forked from ethereumjs/node-blockchain-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessBlockchain.js
More file actions
50 lines (42 loc) · 1.3 KB
/
processBlockchain.js
File metadata and controls
50 lines (42 loc) · 1.3 KB
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
const leveldb = require('level')
const VM = require('ethereumjs-vm')
const Blockchain = require('ethereumjs-blockchain')
const StateTrie = require('merkle-patricia-tree/secure')
var blockchainDb = leveldb('./blockchaindb')
var stateDb = leveldb('./statedb')
var blockchain = new Blockchain(blockchainDb, false)
var stateTrie = new StateTrie(stateDb)
var vm = new VM(stateTrie, blockchain)
var blockNumber
var blockHash
vm.on('step', function (info) {
console.log(info.opcode.opcode, info.address.toString('hex'))
})
vm.on('beforeTx', function (tx) {
console.log('tx.hash:', tx.hash().toString('hex'))
})
vm.on('beforeBlock', function (block) {
blockNumber = block.header.number.toString('hex')
blockHash = block.hash().toString('hex')
})
vm.on('afterBlock', function (results) {
// if (results.error) console.log(results.error)
var out = blockNumber
out += ' hash: ' + blockHash
out += ' error: ' + results.error
out += ' txs: ' + results.receipts.length
console.log(results)
console.log(out)
if (results.error) {
process.exit()
}
})
// console.log('generateGenesis - before')
// vm.generateCanonicalGenesis(function(){
// console.log('generateGenesis - after')
console.log('runBlockchain - before')
vm.runBlockchain(function () {
console.log('runBlockchain - after')
})
// })
// 010b25