-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetProofs.js
54 lines (47 loc) · 1.36 KB
/
getProofs.js
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
const rlp = require('rlp');
const Web3 = require("web3");
const provider = "http://localhost:8081";
// const provider = "https://ropsten.infura.io";
const web3 = new Web3(provider);
// values
const cpInterval = 5;
// functions
function getProofs(address, storageKey, startBlockNumber, endBlockNumber) {
var proofs = [];
for (var i = startBlockNumber; i <= endBlockNumber; i += cpInterval) {
var proof = web3.eth.getProof(address, storageKey, i).catch((err) => {
// console.log(err)
});
proofs.push(proof);
}
return proofs;
}
// main
var address = process.argv[2]; // "0x7224769b9eE714dAA816053732D6Ed0AA35714CB";
var storageKey = []; // Empty for EOA
var from = Number(process.argv[3]); // 6011146;
var to = Number(process.argv[4]); // 6011172;
// Get Proofs
var proofs = getProofs(address, storageKey, from, to);
Promise.all(proofs).then((res) => {
var accountProofs = [];
res.forEach((proof) => {
// console.log(proof);
accountProofs.push(proof.accountProof);
});
/*
var preRlp = {
"address" : address,
"startBlockNumber" : from,
"accountProofs" : accountProofs
};
*/
var preRlp = [
address,
from,
accountProofs
];
// print
console.log(preRlp);
console.log(rlp.encode(preRlp));
});