-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abc6793
commit 299e5e7
Showing
3 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { createRegistry, createRequest, applyParams } from "@substreams/core"; | ||
import { readPackage } from "@substreams/manifest"; | ||
import { BlockEmitter, createNodeTransport } from "@substreams/node"; | ||
import { APIClient, Bytes, Serializer } from "@wharfkit/antelope"; | ||
|
||
// auth API token | ||
// https://app.streamingfast.io/ | ||
// https://app.pinax.network/ | ||
if (!process.env.SUBSTREAMS_API_TOKEN) { | ||
throw new Error("SUBSTREAMS_API_TOKEN is require"); | ||
} | ||
const token = process.env.SUBSTREAMS_API_TOKEN; | ||
|
||
// RPC API Client | ||
const rpc = new APIClient({ url: "https://wax.api.eosnation.io" }); | ||
const abi = (await rpc.v1.chain.get_abi("eosio")).abi; | ||
if ( !abi ) throw new Error("ABI not found"); | ||
|
||
// User parameters | ||
const baseUrl = "https://wax.substreams.pinax.network:443"; | ||
const manifest = "https://github.com/pinax-network/substreams/releases/download/common-v0.7.0/common-v0.7.0.spkg"; | ||
const outputModule = "map_db_ops"; | ||
const params = "map_db_ops=contract=eosio&table=delband" | ||
const startBlockNum = -10000; | ||
|
||
// Read Substream | ||
const substreamPackage = await readPackage(manifest); | ||
if (!substreamPackage.modules) { | ||
throw new Error("No modules found in substream package"); | ||
} | ||
applyParams([params], substreamPackage.modules.modules); | ||
|
||
// Connect Transport | ||
const registry = createRegistry(substreamPackage); | ||
const transport = createNodeTransport(baseUrl, token, registry); | ||
const request = createRequest({ | ||
substreamPackage, | ||
outputModule, | ||
startBlockNum, | ||
}); | ||
|
||
// NodeJS Events | ||
const emitter = new BlockEmitter(transport, request, registry); | ||
|
||
// Session Trace ID | ||
emitter.on("session", (session) => { | ||
console.dir(session); | ||
}); | ||
|
||
// Stream Blocks | ||
emitter.on("anyMessage", (message, cursor, clock) => { | ||
for ( const dbOp of message.dbOps ?? [] ) { | ||
console.log(dbOp); | ||
// const data = Bytes.fromString(dbOp.newData.toString("hex")); | ||
// const decoded = Serializer.decode({data, abi, type: "delegated_bandwidth"}); | ||
// console.log(decoded); | ||
} | ||
}); | ||
|
||
// End of Stream | ||
emitter.on("close", (error) => { | ||
if (error) { | ||
console.error(error); | ||
} | ||
console.timeEnd("🆗 close"); | ||
}); | ||
|
||
// Fatal Error | ||
emitter.on("fatalError", (error) => { | ||
console.error(error); | ||
}); | ||
|
||
console.log("✅ start"); | ||
console.time("🆗 close"); | ||
emitter.start(); |