-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendProof.js
76 lines (65 loc) · 2.12 KB
/
sendProof.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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 preRlp = [
address,
from
];
res.forEach((proof) => {
preRlp.push(proof.isBloom ? 1 : 0);
if (!proof.isBloom) {
var pf = proof.accountProof;
var len = pf.length
preRlp.push(len);
for (var i = 0; i < len; i++) {
preRlp.push(pf[i]);
}
}
});
console.log("> preRlp : ", preRlp);
var rlped = rlp.encode(preRlp);
console.log("> rlped : ", rlped);
web3.eth.getAccounts().then(accounts => {
var address = accounts[0];
var password = "1234"
web3.eth.personal.unlockAccount(address, password, 0).then(() => {
web3.eth.sendTransaction({
from: address,
to: "0x0123456789012345678901234567890123456789",
value: 1,
gas: 21000000,
data: "0x" + toHexString(rlped),
}, function (err, hash) {
console.log("> txHash : ", hash);
});
});
});
});
function toHexString(byteArray) {
return Array.from(byteArray, function (byte) {
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
}).join('')
}