Skip to content

Commit b47ee05

Browse files
author
Dev Kalra
authored
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
1 parent c2da454 commit b47ee05

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import yargs from "yargs";
2+
import { hideBin } from "yargs/helpers";
3+
import { DefaultStore } from "../src";
4+
5+
function deserializeCommitmentMetadata(data: Buffer) {
6+
const seed = Uint8Array.from(data.subarray(0, 32));
7+
const chainLength = data.readBigInt64LE(32);
8+
9+
return {
10+
seed,
11+
chainLength,
12+
};
13+
}
14+
15+
const parser = yargs(hideBin(process.argv))
16+
.usage("Usage: $0")
17+
.options({
18+
testnet: {
19+
type: "boolean",
20+
default: false,
21+
desc: "Fetch the provider registration data for the testnet contracts.",
22+
},
23+
});
24+
25+
async function main() {
26+
const argv = await parser.argv;
27+
28+
for (const contract of Object.values(DefaultStore.entropy_contracts)) {
29+
if (contract.getChain().isMainnet() === argv.testnet) continue;
30+
let provider;
31+
let providerInfo;
32+
try {
33+
provider = await contract.getDefaultProvider();
34+
providerInfo = await contract.getProviderInfo(provider);
35+
} catch (e) {
36+
console.error(`Error fetching info for ${contract.getId()}`, e);
37+
continue;
38+
}
39+
40+
const commitmentMetadata = providerInfo.commitmentMetadata.replace(
41+
"0x",
42+
""
43+
);
44+
45+
// const binaryData = hexToBytes(commitmentMetadata);
46+
const metadata = deserializeCommitmentMetadata(
47+
Buffer.from(commitmentMetadata, "hex")
48+
);
49+
console.log("=".repeat(100));
50+
console.log(`Fetched info for ${contract.getId()}`);
51+
52+
console.log(`chain : ${contract.getChain().getId()}`);
53+
console.log(`contract : ${contract.address}`);
54+
console.log(`provider : ${provider}`);
55+
console.log(`commitment data : ${commitmentMetadata}`);
56+
console.log(`chainLength : ${metadata.chainLength}`);
57+
console.log(`seed : [${metadata.seed}]`);
58+
console.log(
59+
`original seq no : ${providerInfo.originalCommitmentSequenceNumber}`
60+
);
61+
}
62+
}
63+
64+
main();

0 commit comments

Comments
 (0)