-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
76 lines (67 loc) · 2.38 KB
/
index.js
File metadata and controls
76 lines (67 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const crypto = require("crypto");
const { Provider, utils } = require("koilib");
const process = require("process");
const contractId = process.argv[2];
if (!contractId) {
console.error("Please provide a contract ID as a command-line argument.");
process.exit(1);
}
const defaultNodeApi = "https://api.koinosblocks.com";
//const defaultNodeApi = "https://api.koinos.io"; // koinos group official api
//const defaultNodeApi = "https://harbinger-api.koinos.io" // harbinger testnet
const nodeApi = process.env.NODE_API || defaultNodeApi;
(async () => {
const provider = new Provider([nodeApi]);
let contractUploads = 0;
let seqNum = 0;
while (true) {
const result = await provider.call("account_history.get_account_history", {
address: contractId,
ascending: true,
limit: 500,
seq_num: seqNum,
});
for (let i = 0; i < result.values.length; i += 1) {
const historyEntry = result.values[i];
if (!historyEntry.trx) continue;
const { trx: trxRecord } = historyEntry;
if (!trxRecord.transaction || !trxRecord.transaction.operations) continue;
for (let j = 0; j < trxRecord.transaction.operations.length; j += 1) {
const op = trxRecord.transaction.operations[j];
if (!op.upload_contract) continue;
const {
authorizes_call_contract,
authorizes_transaction_application,
authorizes_upload_contract,
} = op.upload_contract;
let immutable = true;
if (
!authorizes_call_contract ||
!authorizes_transaction_application ||
!authorizes_upload_contract
) {
immutable = false;
}
const bytecode = utils.decodeBase64url(op.upload_contract.bytecode);
const hash = crypto.createHash("sha256").update(bytecode).digest("hex");
const size = bytecode.length;
console.log({
seq_num: historyEntry.seq_num || 0,
trxId: trxRecord.transaction.id,
opType: "upload_contract",
hash,
size,
immutable,
});
contractUploads += 1;
}
}
const lastSeqNum = Number(result.values[result.values.length - 1].seq_num);
seqNum += 500;
if (lastSeqNum < seqNum - 1) {
console.log(`Search ended in seq_num ${lastSeqNum}`);
break;
}
}
console.log(`Number of contract uploads: ${contractUploads}`);
})();