1
1
import Common from 'ethereumjs-common'
2
- import * as utils from 'ethereumjs-util'
3
- import { BN } from 'ethereumjs-util'
2
+ import {
3
+ BN ,
4
+ zeros ,
5
+ KECCAK256_RLP_ARRAY ,
6
+ KECCAK256_RLP ,
7
+ toBuffer ,
8
+ defineProperties ,
9
+ bufferToInt ,
10
+ rlphash ,
11
+ } from 'ethereumjs-util'
4
12
import { Blockchain , BlockHeaderData , BufferLike , ChainOptions , PrefixedHexString } from './types'
5
13
import { Buffer } from 'buffer'
6
14
import { Block } from './block'
@@ -55,35 +63,35 @@ export class BlockHeader {
55
63
{
56
64
name : 'parentHash' ,
57
65
length : 32 ,
58
- default : utils . zeros ( 32 ) ,
66
+ default : zeros ( 32 ) ,
59
67
} ,
60
68
{
61
69
name : 'uncleHash' ,
62
- default : utils . KECCAK256_RLP_ARRAY ,
70
+ default : KECCAK256_RLP_ARRAY ,
63
71
} ,
64
72
{
65
73
name : 'coinbase' ,
66
74
length : 20 ,
67
- default : utils . zeros ( 20 ) ,
75
+ default : zeros ( 20 ) ,
68
76
} ,
69
77
{
70
78
name : 'stateRoot' ,
71
79
length : 32 ,
72
- default : utils . zeros ( 32 ) ,
80
+ default : zeros ( 32 ) ,
73
81
} ,
74
82
{
75
83
name : 'transactionsTrie' ,
76
84
length : 32 ,
77
- default : utils . KECCAK256_RLP ,
85
+ default : KECCAK256_RLP ,
78
86
} ,
79
87
{
80
88
name : 'receiptTrie' ,
81
89
length : 32 ,
82
- default : utils . KECCAK256_RLP ,
90
+ default : KECCAK256_RLP ,
83
91
} ,
84
92
{
85
93
name : 'bloom' ,
86
- default : utils . zeros ( 256 ) ,
94
+ default : zeros ( 256 ) ,
87
95
} ,
88
96
{
89
97
name : 'difficulty' ,
@@ -92,7 +100,7 @@ export class BlockHeader {
92
100
{
93
101
name : 'number' ,
94
102
// TODO: params.homeSteadForkNumber.v left for legacy reasons, replace on future release
95
- default : utils . toBuffer ( 1150000 ) ,
103
+ default : toBuffer ( 1150000 ) ,
96
104
} ,
97
105
{
98
106
name : 'gasLimit' ,
@@ -115,15 +123,15 @@ export class BlockHeader {
115
123
} ,
116
124
{
117
125
name : 'mixHash' ,
118
- default : utils . zeros ( 32 ) ,
126
+ default : zeros ( 32 ) ,
119
127
// length: 32
120
128
} ,
121
129
{
122
130
name : 'nonce' ,
123
- default : utils . zeros ( 8 ) , // sha3(42)
131
+ default : zeros ( 8 ) , // sha3(42)
124
132
} ,
125
133
]
126
- utils . defineProperties ( this , fields , data )
134
+ defineProperties ( this , fields , data )
127
135
}
128
136
129
137
/**
@@ -147,7 +155,7 @@ export class BlockHeader {
147
155
148
156
if ( this . _common . hardforkGteHardfork ( hardfork , 'byzantium' ) ) {
149
157
// max((2 if len(parent.uncles) else 1) - ((timestamp - parent.timestamp) // 9), -99) (EIP100)
150
- const uncleAddend = parentBlock . header . uncleHash . equals ( utils . KECCAK256_RLP_ARRAY ) ? 1 : 2
158
+ const uncleAddend = parentBlock . header . uncleHash . equals ( KECCAK256_RLP_ARRAY ) ? 1 : 2
151
159
let a = blockTs
152
160
. sub ( parentTs )
153
161
. idivn ( 9 )
@@ -283,11 +291,11 @@ export class BlockHeader {
283
291
throw new Error ( 'invalid gas limit' )
284
292
}
285
293
286
- if ( utils . bufferToInt ( this . number ) - utils . bufferToInt ( parentBlock . header . number ) !== 1 ) {
294
+ if ( bufferToInt ( this . number ) - bufferToInt ( parentBlock . header . number ) !== 1 ) {
287
295
throw new Error ( 'invalid height' )
288
296
}
289
297
290
- if ( utils . bufferToInt ( this . timestamp ) <= utils . bufferToInt ( parentBlock . header . timestamp ) ) {
298
+ if ( bufferToInt ( this . timestamp ) <= bufferToInt ( parentBlock . header . timestamp ) ) {
291
299
throw new Error ( 'invalid timestamp' )
292
300
}
293
301
@@ -301,7 +309,7 @@ export class BlockHeader {
301
309
* Returns the hash of the block header.
302
310
*/
303
311
hash ( ) : Buffer {
304
- return utils . rlphash ( this . raw )
312
+ return rlphash ( this . raw )
305
313
}
306
314
307
315
/**
@@ -347,7 +355,7 @@ export class BlockHeader {
347
355
348
356
return commonHardFork !== null
349
357
? commonHardFork
350
- : this . _common . activeHardfork ( utils . bufferToInt ( this . number ) )
358
+ : this . _common . activeHardfork ( bufferToInt ( this . number ) )
351
359
}
352
360
353
361
private async _getBlockByHash ( blockchain : Blockchain , hash : Buffer ) : Promise < Block | undefined > {
0 commit comments