Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise(async (resolve) => {
const provider = new WsProvider(this.config.wsEndpoint);
const api = await new ApiPromise(provider).isReady;
const result = [];
let blockCounter = 0;
const creationTimestamps = new Map();
api.rpc.chain.subscribeNewHead(async (header) => {
// for each produced block we store the timestamp
const timestamp = Date.now();
console.log(`New produced block: ${header.blockNumber}, timestamp: ${timestamp}`);
creationTimestamps.set(header.blockNumber.toString(), timestamp);
});
api.rpc.chain.subscribeFinalizedHeads(async (header) => {
const finalizationTimestamp = Date.now();
blockCounter++;
async _waitReadyDNS(index=0) {
const wsEndpoint = this._wsEndpoint(index);
const provider = new WsProvider(wsEndpoint);
const api = await new ApiPromise(provider);
const [chain, nodeName, nodeVersion] = await Promise.all([
api.rpc.system.chain(),
api.rpc.system.name(),
api.rpc.system.version()
]);
console.log(`You are connected to chain ${chain} using ${nodeName} v${nodeVersion}`);
api.disconnect();
return { wsEndpoint };
}