1
+ import VM from './index'
1
2
const async = require ( 'async' )
2
3
3
4
/**
@@ -6,31 +7,32 @@ const async = require('async')
6
7
* @param {Blockchain } blockchain A [blockchain](https://github.com/ethereum/ethereumjs-blockchain) that to process
7
8
* @param {Function } cb the callback function
8
9
*/
9
- module . exports = function ( blockchain , cb ) {
10
- var self = this
11
- var headBlock , parentState
10
+ export default function runBlockchain ( this : VM , blockchain : any , cb : any ) {
11
+ const self = this
12
+ let headBlock : any
13
+ let parentState : Buffer
12
14
13
15
// parse arguments
14
16
if ( typeof blockchain === 'function' ) {
15
17
cb = blockchain
16
- blockchain = undefined
18
+ blockchain = this . blockchain
17
19
}
18
20
19
- blockchain = blockchain || self . blockchain
21
+ blockchain = blockchain || this . blockchain
20
22
21
23
// setup blockchain iterator
22
24
blockchain . iterator ( 'vm' , processBlock , cb )
23
- function processBlock ( block , reorg , cb ) {
25
+ function processBlock ( block : any , reorg : boolean , cb : any ) {
24
26
async . series ( [
25
27
getStartingState ,
26
28
runBlock
27
29
] , cb )
28
30
29
31
// determine starting state for block run
30
- function getStartingState ( cb ) {
32
+ function getStartingState ( cb : any ) {
31
33
// if we are just starting or if a chain re-org has happened
32
34
if ( ! headBlock || reorg ) {
33
- blockchain . getBlock ( block . header . parentHash , function ( err , parentBlock ) {
35
+ blockchain . getBlock ( block . header . parentHash , function ( err : any , parentBlock : any ) {
34
36
parentState = parentBlock . header . stateRoot
35
37
// generate genesis state if we are at the genesis block
36
38
// we don't have the genesis state
@@ -47,7 +49,7 @@ module.exports = function (blockchain, cb) {
47
49
}
48
50
49
51
// run block, update head if valid
50
- function runBlock ( cb ) {
52
+ function runBlock ( cb : any ) {
51
53
self . runBlock ( {
52
54
block : block ,
53
55
root : parentState
0 commit comments