forked from mrsmkl/eth-patricia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrreceiver.js
executable file
·44 lines (33 loc) · 1.04 KB
/
trreceiver.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
#!/usr/bin/node
const fs = require("fs")
const Web3 = require("../web3.js/packages/web3")
const web3 = new Web3()
// 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
}
async function main() {
var lst = getList()
var blk = await web3.eth.getBlock(getInteger(lst[0]))
var tr_hash = blk.transactions[getInteger(lst[1])]
var tr = await web3.eth.getTransaction(tr_hash)
console.error(tr.to)
if (!tr.to) fs.writeFileSync("custom.out", conv("00"), "hex")
else fs.writeFileSync("custom.out", conv(tr.to.substr(2)), "hex")
}
main()