feat: initialize Kurdistan SDK - independent fork of Polkadot SDK
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
const utils = require("./utils");
|
||||
|
||||
async function run(nodeName, networkInfo, args) {
|
||||
const {wsUri, userDefinedTypes} = networkInfo.nodesByName[nodeName];
|
||||
const api = await zombie.connect(wsUri, userDefinedTypes);
|
||||
|
||||
// parse arguments
|
||||
const exitAfterSeconds = Number(args[0]);
|
||||
const bridgedChain = require("./chains/" + args[1]);
|
||||
|
||||
// start listening to new blocks
|
||||
let totalGrandpaHeaders = 0;
|
||||
let totalTeyrchainHeaders = 0;
|
||||
api.rpc.chain.subscribeNewHeads(async function (header) {
|
||||
const apiAtParent = await api.at(header.parentHash);
|
||||
const apiAtCurrent = await api.at(header.hash);
|
||||
const currentEvents = await apiAtCurrent.query.system.events();
|
||||
|
||||
totalGrandpaHeaders += await utils.countGrandpaHeaderImports(bridgedChain, currentEvents);
|
||||
totalTeyrchainHeaders += await utils.countTeyrchainHeaderImports(bridgedChain, currentEvents);
|
||||
});
|
||||
|
||||
// wait given time
|
||||
await new Promise(resolve => setTimeout(resolve, exitAfterSeconds * 1000));
|
||||
// if we haven't seen many (>1) new GRANDPA or teyrchain headers => fail
|
||||
if (totalGrandpaHeaders <= 1) {
|
||||
throw new Error("No bridged relay chain headers imported");
|
||||
}
|
||||
if (totalTeyrchainHeaders <= 1) {
|
||||
throw new Error("No bridged teyrchain headers imported");
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { run }
|
||||
Reference in New Issue
Block a user