-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
56 lines (45 loc) · 1.6 KB
/
script.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
function init() {
blocks = [];
gasUsed = 0;
tnxHashes = []; // transaction hashes
totalDifficulties = [];
emptyBlockNum = 0;
prevTime = 0;
blockMiningTime = []; // in seconds
tnxReceipts = [];
return true;
}
function getInfo() {
for (var i = blocks.length; i <= eth.blockNumber; i++) {
block = eth.getBlock(i);
block_data = {};
block_data.no = block.number;
block_data.miner = block.miner;
block_data.extraData = block.extraData;
block_data.gasUsed = block.gasUsed;
block_data.tnxCnt = block.transactions.length;
blocks.push(block_data);
gasUsed += block.gasUsed;
if (block.transactions.length) {
tnxsHashes = tnxHashes.concat(block.transactions);
for (var j = 0; j < block.transactions.length; j++) {
tnx = eth.getTransactionReceipt(block.transactions[j]);
tnx_data = {};
tnx_data.blockNumber = tnx.blockNumber;
tnx_data.transactionHash = tnx.transactionHash;
tnx_data.isContract = tnx.contractAddress == null ? false : true;
tnx_data.from = tnx.from;
tnx_data.to = tnx.to;
tnx_data.gasUsed = tnx.gasUsed;
tnxReceipts.push(tnx_data);
}
}
else emptyBlockNum++;
if (i > 1) { // exclude the first block(the genesis block)
blockMiningTime.push(block.timestamp - prevTime);
}
prevTime = block.timestamp;
totalDifficulties.push(block.totalDifficulty);
}
return true;
}