Skip to content

Commit

Permalink
add wax delband example
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Jan 30, 2024
1 parent abc6793 commit 299e5e7
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 0 deletions.
82 changes: 82 additions & 0 deletions examples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"@substreams/core": "latest",
"@substreams/manifest": "latest",
"@substreams/node": "latest",
"@wharfkit/antelope": "^1.0.6",
"log-update": "latest"
}
}
75 changes: 75 additions & 0 deletions examples/wax-delband.mjs
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();

0 comments on commit 299e5e7

Please sign in to comment.