Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* might come in the future. This means that even if there is less
* results than expected per page, future blocks might add more
* results, hence the `cursor` not returning as empty.
*
* **Note** Doing a descending search will yield an empty
* string cursor at some point because you will reach the Genesis
* Block of the chain (Block #1).
*/
if (page.cursor === "" || page.transactions.length < resultPerPage) {
// No more pages, stop page fetch
break
}
console.log(`RAM Running Total (${resultCount} transactions included) is ${runningTotal}`)
console.log(`Fetching next page (#${pageCount + 1}) in 5s ...`)
await waitFor(5000)
}
console.log(`Running total is ${runningTotal}`)
console.log(`Completed after reading ${pageCount} page(s)`)
} catch (error) {
console.log("An error occurred", error)
}
client.release()
}
if (message.type === InboundMessageType.HEAD_INFO) {
console.log("WebSocket stream data.", JSON.stringify(message.data))
// Mark latest location where we want to start back at
wsStream.mark({ atBlockNum: message.data.head_block_num })
}
})
wsStream.onPostRestart = () => {
console.log()
console.log(
"<============= WebSocket stream has restarted to its previous `mark()` location =============>"
)
}
await waitFor(35000)
await graphqlStream.close()
await wsStream.close()
client.release()
}
})
)
const ramData = { accounts: "eosio.token", action_names: "transfer", receivers: "eosio.ram" }
const ramStream: Stream = await client.streamActionTraces(
ramData,
dynamicMessageDispatcher({
listening: onListeningFactory("ram_transfer"),
action_trace: onTransferToEosioRamAction
})
)
console.log(
"Notice how `Buy RAM` and `RAM cost` happens in random order, due to using 2 independent streams."
)
await waitFor(60000)
await buyRamStream.close()
await ramStream.close()
console.log("")
const mergedData = {
accounts: "eosio|eosio.token",
action_names: "buyrambytes|transfer",
receivers: "eosio|eosio.token|eosio.ram"
}
const mergedStream: Stream = await client.streamActionTraces(
mergedData,
dynamicMessageDispatcher({
listening: onListeningFactory("merged"),
action_trace: onMergedAction
})
const stream = await client.streamTableRows(
{ code: "eosio", scope: "eosio", table: "global" },
(message: InboundMessage) => {
if (message.type === InboundMessageType.TABLE_DELTA) {
const { dbop, block_num } = message.data as TableDeltaData
const { total_ram_stake, total_unpaid_blocks } = dbop.new!.json!
console.log(
`Global state change @ #${block_num} [Total RAM Stake ${total_ram_stake}, Total Unpaid Block Count ${total_unpaid_blocks}]`
)
}
}
)
await waitFor(5000)
await stream.close()
client.release()
}
return
}
if (message.type === InboundMessageType.TRANSACTION_LIFECYCLE) {
console.log(prettifyJson(message.data))
return
}
if (message.type === InboundMessageType.ERROR) {
console.log(prettifyJson(message.data))
return
}
}
)
await waitFor(5000)
await stream.close()
client.release()
}
const onMessage = (message: InboundMessage) => {
if (message.type === InboundMessageType.LISTENING) {
console.log("Stream is now listening.")
}
}
const stream = await client.streamActionTraces(
{
accounts: "eosio.token",
action_names: "issue"
},
onMessage
)
console.log("Socket is now connected.")
await waitFor(35000)
await stream.close()
client.release()
}
}
if (message.type === InboundMessageType.TABLE_DELTA) {
console.log(prettifyJson(message.data))
return
}
if (message.type === InboundMessageType.ERROR) {
console.log(prettifyJson(message.data))
return
}
},
{ fetch: true }
)
await waitFor(15000)
await stream.close()
client.release()
}
async function main() {
const client = createDfuseClient({
apiKey: DFUSE_API_KEY,
network: DFUSE_API_NETWORK,
streamClientOptions: {
socketOptions: {
reconnectDelayInMs: 250
}
}
})
const engine = new Engine(client)
await engine.start()
await waitFor(50000)
await engine.stop()
client.release()
}
network: DFUSE_API_NETWORK
})
const stream = await client.streamActionTraces(
{ accounts: "eosio.token", action_names: "transfer" },
onMessage,
{
/**
* Request to only obtain irreversible notifications by specifying this
* common flag and setting its value to true.
*/
irreversible_only: true
}
)
await waitFor(5000)
await stream.close()
client.release()
}
async function main() {
const client = createDfuseClient({
apiKey: DFUSE_API_KEY,
network: DFUSE_API_NETWORK
})
const engine = new Engine(client)
await engine.start()
await waitFor(50000)
await engine.stop()
client.release()
}