feat(contract-manager): implement a script to get the entropy current registration (#1512)
* write a script to get the current registration * simplify * correct description * catch only rpc errors * refactor and simplify
This commit is contained in:
parent
c2da454637
commit
b47ee059d7
|
@ -0,0 +1,64 @@
|
||||||
|
import yargs from "yargs";
|
||||||
|
import { hideBin } from "yargs/helpers";
|
||||||
|
import { DefaultStore } from "../src";
|
||||||
|
|
||||||
|
function deserializeCommitmentMetadata(data: Buffer) {
|
||||||
|
const seed = Uint8Array.from(data.subarray(0, 32));
|
||||||
|
const chainLength = data.readBigInt64LE(32);
|
||||||
|
|
||||||
|
return {
|
||||||
|
seed,
|
||||||
|
chainLength,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const parser = yargs(hideBin(process.argv))
|
||||||
|
.usage("Usage: $0")
|
||||||
|
.options({
|
||||||
|
testnet: {
|
||||||
|
type: "boolean",
|
||||||
|
default: false,
|
||||||
|
desc: "Fetch the provider registration data for the testnet contracts.",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const argv = await parser.argv;
|
||||||
|
|
||||||
|
for (const contract of Object.values(DefaultStore.entropy_contracts)) {
|
||||||
|
if (contract.getChain().isMainnet() === argv.testnet) continue;
|
||||||
|
let provider;
|
||||||
|
let providerInfo;
|
||||||
|
try {
|
||||||
|
provider = await contract.getDefaultProvider();
|
||||||
|
providerInfo = await contract.getProviderInfo(provider);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Error fetching info for ${contract.getId()}`, e);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const commitmentMetadata = providerInfo.commitmentMetadata.replace(
|
||||||
|
"0x",
|
||||||
|
""
|
||||||
|
);
|
||||||
|
|
||||||
|
// const binaryData = hexToBytes(commitmentMetadata);
|
||||||
|
const metadata = deserializeCommitmentMetadata(
|
||||||
|
Buffer.from(commitmentMetadata, "hex")
|
||||||
|
);
|
||||||
|
console.log("=".repeat(100));
|
||||||
|
console.log(`Fetched info for ${contract.getId()}`);
|
||||||
|
|
||||||
|
console.log(`chain : ${contract.getChain().getId()}`);
|
||||||
|
console.log(`contract : ${contract.address}`);
|
||||||
|
console.log(`provider : ${provider}`);
|
||||||
|
console.log(`commitment data : ${commitmentMetadata}`);
|
||||||
|
console.log(`chainLength : ${metadata.chainLength}`);
|
||||||
|
console.log(`seed : [${metadata.seed}]`);
|
||||||
|
console.log(
|
||||||
|
`original seq no : ${providerInfo.originalCommitmentSequenceNumber}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
Loading…
Reference in New Issue