Created
August 19, 2022 15:32
-
-
Save mgild/692ea0f0405bbfce5376c5d4c0488a11 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import fetch, { Response } from "node-fetch"; | |
| import { Connection, LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js"; | |
| async function loadZeroCopyResult( | |
| con: Connection, | |
| addr: PublicKey | |
| ): Promise<any> { | |
| const data = (await con.getAccountInfo(addr))!.data; | |
| let offset = 0; | |
| const dicsriminator = data[0]; | |
| offset += 1; | |
| const parent = new PublicKey(data.subarray(offset, offset + 32)); | |
| offset += 32; | |
| const numSuccess = data.readInt32LE(offset); | |
| offset += 4; | |
| const numError = data.readInt32LE(offset); | |
| offset += 4; | |
| const result = data.readDoubleLE(offset); | |
| offset += 8; | |
| const roundOpenSlot = data.readBigUInt64LE(offset); | |
| offset += 8; | |
| const roundOpenTimestamp = data.readBigInt64LE(offset); | |
| offset += 8; | |
| const minResponse = data.readDoubleLE(offset); | |
| offset += 8; | |
| const maxResponse = data.readDoubleLE(offset); | |
| return { | |
| dicsriminator, | |
| parent, | |
| numSuccess, | |
| numError, | |
| result, | |
| roundOpenSlot, | |
| roundOpenTimestamp, | |
| minResponse, | |
| maxResponse, | |
| }; | |
| } | |
| (async function main() { | |
| const connection = new Connection("https://api.mainnet-beta.solana.com"); | |
| const poa = new PublicKey("3HtmwdXJPAdMZ73fTGeCFgbDQZGLZWpmsm3JAB5quGJN"); | |
| const data = await loadZeroCopyResult(connection, poa); | |
| console.log(data); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment