forked from mrsmkl/eth-patricia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetstorage.js
executable file
·56 lines (43 loc) · 1.31 KB
/
getstorage.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
#!/usr/bin/node
const fs = require("fs")
const Web3 = require("../web3.js/packages/web3")
const web3 = new Web3()
const RLP = require('rlp')
const util = require('ethereumjs-util')
// should read and write from custom.dta
var host = process.argv[2] || "localhost"
web3.setProvider(new web3.providers.HttpProvider('http://' + host + ':8545'))
function getList() {
var str = fs.readFileSync("custom.in", "hex")
var lst = []
for (var i = 0; i < str.length; i += 64) lst.push(str.substr(i, 64))
return lst
}
function conv(a) {
while (a.length < 64) a = "0"+a
return a
}
function getInteger(str) {
var res = 0
for (var i = 0; i < 64; i++) res = parseInt("0x"+str[i]) + res*16
console.error(res)
return res
}
function hash(dta) {
return util.sha3(Buffer.from(dta.substr(2),"hex"))
}
function make32(str) {
while (str.length < 64) str = "0"+str;
return "0x"+str
}
async function main() {
var lst = getList()
console.error(lst)
var blk = await web3.eth.getBlock(getInteger(lst[0]))
console.error("Account", "0x"+lst[1].substr(24), blk.hash)
var cell = await web3.eth.getStorageCell(blk.hash, "0x"+lst[1].substr(24), make32(lst[2]))
cell = RLP.decode(cell).toString("hex")
console.error(cell)
fs.writeFileSync("custom.out", conv(cell), "hex")
}
main()