Skip to content

Commit e9f6396

Browse files
committed
update to ethereumjs-util 7.0.2
1 parent 4b9a096 commit e9f6396

File tree

18 files changed

+149
-148
lines changed

18 files changed

+149
-148
lines changed

packages/account/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
"homepage": "https://github.com/ethereumjs/ethereumjs-account#readme",
3838
"dependencies": {
39-
"ethereumjs-util": "^6.0.0",
39+
"ethereumjs-util": "^7.0.2",
4040
"rlp": "^2.2.1",
4141
"safe-buffer": "^5.1.1"
4242
},
@@ -45,7 +45,7 @@
4545
"@ethereumjs/config-prettier": "^1.1.0",
4646
"@ethereumjs/config-tsc": "^1.1.0",
4747
"@ethereumjs/config-tslint": "^1.1.0",
48-
"@types/bn.js": "^4.11.3",
48+
"@types/bn.js": "^4.11.6",
4949
"@types/node": "^11.9.4",
5050
"@types/tape": "^4.2.33",
5151
"merkle-patricia-tree": "^3.0.0",
@@ -56,7 +56,7 @@
5656
"tslint": "^5.12.0",
5757
"typedoc": "next",
5858
"typedoc-plugin-markdown": "^2.2.17",
59-
"typescript": "^3.2.2",
59+
"typescript": "^3.9.2",
6060
"typestrict": "^1.0.2"
6161
}
6262
}

packages/block/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
},
4040
"homepage": "https://github.com/ethereumjs/ethereumjs-block#readme",
4141
"dependencies": {
42-
"@types/bn.js": "^4.11.5",
42+
"@types/bn.js": "^4.11.6",
4343
"ethereumjs-common": "^1.5.0",
4444
"ethereumjs-tx": "^2.1.1",
45-
"ethereumjs-util": "^6.1.0",
45+
"ethereumjs-util": "^7.0.2",
4646
"merkle-patricia-tree": "^2.1.2"
4747
},
4848
"devDependencies": {
@@ -67,7 +67,7 @@
6767
"tslint": "^5.15.0",
6868
"typedoc": "next",
6969
"typedoc-plugin-markdown": "^2.2.17",
70-
"typescript": "^3.4.3",
70+
"typescript": "^3.9.2",
7171
"typestrict": "^1.0.2"
7272
}
7373
}

packages/block/src/block.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import Common from 'ethereumjs-common'
2-
import * as ethUtil from 'ethereumjs-util'
3-
import { BN, rlp } from 'ethereumjs-util'
2+
import { rlp, keccak256, KECCAK256_RLP, baToJSON } from 'ethereumjs-util'
43
import { Transaction, TransactionOptions } from 'ethereumjs-tx'
5-
64
import { BlockHeader } from './header'
75
import { Blockchain, BlockData, ChainOptions } from './types'
86

97
const Trie = require('merkle-patricia-tree')
8+
const { BN } = require('ethereumjs-util')
109

1110
/**
1211
* An object that represents the block
@@ -148,7 +147,7 @@ export class Block {
148147
if (this.transactions.length) {
149148
return txT === this.txTrie.root.toString('hex')
150149
} else {
151-
return txT === ethUtil.KECCAK256_RLP.toString('hex')
150+
return txT === KECCAK256_RLP.toString('hex')
152151
}
153152
}
154153

@@ -209,7 +208,7 @@ export class Block {
209208
validateUnclesHash(): boolean {
210209
const raw = rlp.encode(this.uncleHeaders.map(uh => uh.raw))
211210

212-
return ethUtil.keccak256(raw).toString('hex') === this.header.uncleHash.toString('hex')
211+
return keccak256(raw).toString('hex') === this.header.uncleHash.toString('hex')
213212
}
214213

215214
/**
@@ -248,7 +247,7 @@ export class Block {
248247
uncleHeaders: this.uncleHeaders.forEach(uh => uh.toJSON(true)),
249248
}
250249
} else {
251-
return ethUtil.baToJSON(this.raw)
250+
return baToJSON(this.raw)
252251
}
253252
}
254253

packages/block/src/from-rpc.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FakeTransaction, TransactionOptions } from 'ethereumjs-tx'
2-
import * as ethUtil from 'ethereumjs-util'
2+
import { toBuffer, setLengthLeft } from 'ethereumjs-util'
33
import { Block } from './index'
44
import { ChainOptions } from './types'
55

@@ -34,7 +34,7 @@ export default function blockFromRpc(
3434
for (const _txParams of blockParams.transactions) {
3535
const txParams = normalizeTxParams(_txParams)
3636
// override from address
37-
const fromAddress = ethUtil.toBuffer(txParams.from)
37+
const fromAddress = toBuffer(txParams.from)
3838
delete txParams.from
3939

4040
const tx = new FakeTransaction(txParams, chainOptions as TransactionOptions)
@@ -43,7 +43,7 @@ export default function blockFromRpc(
4343
return fromAddress
4444
}
4545
// override hash
46-
const txHash = ethUtil.toBuffer(txParams.hash)
46+
const txHash = toBuffer(txParams.hash)
4747
tx.hash = function() {
4848
return txHash
4949
}
@@ -60,7 +60,7 @@ function normalizeTxParams(_txParams: any) {
6060
txParams.gasLimit = txParams.gasLimit === undefined ? txParams.gas : txParams.gasLimit
6161
txParams.data = txParams.data === undefined ? txParams.input : txParams.data
6262
// strict byte length checking
63-
txParams.to = txParams.to ? ethUtil.setLengthLeft(ethUtil.toBuffer(txParams.to), 20) : null
63+
txParams.to = txParams.to ? setLengthLeft(toBuffer(txParams.to), 20) : null
6464

6565
// v as raw signature value {0,1}
6666
// v is the recovery bit and can be either {0,1} or {27,28}.

packages/block/src/header-from-rpc.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BlockHeader } from './header'
2-
import * as ethUtil from 'ethereumjs-util'
2+
import { KECCAK256_NULL, toBuffer } from 'ethereumjs-util'
33
import { ChainOptions } from './types'
44

55
/**
@@ -16,7 +16,7 @@ export default function blockHeaderFromRpc(blockParams: any, chainOptions?: Chai
1616
coinbase: blockParams.miner,
1717
stateRoot: blockParams.stateRoot,
1818
transactionsTrie: blockParams.transactionsRoot,
19-
receiptTrie: blockParams.receiptRoot || blockParams.receiptsRoot || ethUtil.KECCAK256_NULL,
19+
receiptTrie: blockParams.receiptRoot || blockParams.receiptsRoot || KECCAK256_NULL,
2020
bloom: blockParams.logsBloom,
2121
difficulty: blockParams.difficulty,
2222
number: blockParams.number,
@@ -32,7 +32,7 @@ export default function blockHeaderFromRpc(blockParams: any, chainOptions?: Chai
3232

3333
// override hash in case something was missing
3434
blockHeader.hash = function() {
35-
return ethUtil.toBuffer(blockParams.hash)
35+
return toBuffer(blockParams.hash)
3636
}
3737

3838
return blockHeader

packages/block/src/header.ts

+31-21
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import Common from 'ethereumjs-common'
2-
import * as utils from 'ethereumjs-util'
3-
import { BN } from 'ethereumjs-util'
2+
import {
3+
zeros,
4+
KECCAK256_RLP_ARRAY,
5+
KECCAK256_RLP,
6+
toBuffer,
7+
defineProperties,
8+
bufferToInt,
9+
rlphash,
10+
} from 'ethereumjs-util'
411
import { Blockchain, BlockHeaderData, BufferLike, ChainOptions, PrefixedHexString } from './types'
512
import { Buffer } from 'buffer'
613
import { Block } from './block'
714

15+
const { BN } = require('ethereumjs-util')
16+
import IBN = require('bn.js')
17+
818
/**
919
* An object that represents the block header
1020
*/
@@ -55,35 +65,35 @@ export class BlockHeader {
5565
{
5666
name: 'parentHash',
5767
length: 32,
58-
default: utils.zeros(32),
68+
default: zeros(32),
5969
},
6070
{
6171
name: 'uncleHash',
62-
default: utils.KECCAK256_RLP_ARRAY,
72+
default: KECCAK256_RLP_ARRAY,
6373
},
6474
{
6575
name: 'coinbase',
6676
length: 20,
67-
default: utils.zeros(20),
77+
default: zeros(20),
6878
},
6979
{
7080
name: 'stateRoot',
7181
length: 32,
72-
default: utils.zeros(32),
82+
default: zeros(32),
7383
},
7484
{
7585
name: 'transactionsTrie',
7686
length: 32,
77-
default: utils.KECCAK256_RLP,
87+
default: KECCAK256_RLP,
7888
},
7989
{
8090
name: 'receiptTrie',
8191
length: 32,
82-
default: utils.KECCAK256_RLP,
92+
default: KECCAK256_RLP,
8393
},
8494
{
8595
name: 'bloom',
86-
default: utils.zeros(256),
96+
default: zeros(256),
8797
},
8898
{
8999
name: 'difficulty',
@@ -92,7 +102,7 @@ export class BlockHeader {
92102
{
93103
name: 'number',
94104
// TODO: params.homeSteadForkNumber.v left for legacy reasons, replace on future release
95-
default: utils.toBuffer(1150000),
105+
default: toBuffer(1150000),
96106
},
97107
{
98108
name: 'gasLimit',
@@ -115,23 +125,23 @@ export class BlockHeader {
115125
},
116126
{
117127
name: 'mixHash',
118-
default: utils.zeros(32),
128+
default: zeros(32),
119129
// length: 32
120130
},
121131
{
122132
name: 'nonce',
123-
default: utils.zeros(8), // sha3(42)
133+
default: zeros(8), // sha3(42)
124134
},
125135
]
126-
utils.defineProperties(this, fields, data)
136+
defineProperties(this, fields, data)
127137
}
128138

129139
/**
130140
* Returns the canonical difficulty for this block.
131141
*
132142
* @param parentBlock - the parent `Block` of this header
133143
*/
134-
canonicalDifficulty(parentBlock: Block): BN {
144+
canonicalDifficulty(parentBlock: Block): IBN {
135145
const hardfork = this._getHardfork()
136146
const blockTs = new BN(this.timestamp)
137147
const parentTs = new BN(parentBlock.header.timestamp)
@@ -143,11 +153,11 @@ export class BlockHeader {
143153
let num = new BN(this.number)
144154

145155
// We use a ! here as TS can follow this hardforks-dependent logic, but it always gets assigned
146-
let dif!: BN
156+
let dif!: IBN
147157

148158
if (this._common.hardforkGteHardfork(hardfork, 'byzantium')) {
149159
// 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
160+
const uncleAddend = parentBlock.header.uncleHash.equals(KECCAK256_RLP_ARRAY) ? 1 : 2
151161
let a = blockTs
152162
.sub(parentTs)
153163
.idivn(9)
@@ -252,7 +262,7 @@ export class BlockHeader {
252262
* @param blockchain - the blockchain that this block is validating against
253263
* @param height - If this is an uncle header, this is the height of the block that is including it
254264
*/
255-
async validate(blockchain: Blockchain, height?: BN): Promise<void> {
265+
async validate(blockchain: Blockchain, height?: IBN): Promise<void> {
256266
if (this.isGenesis()) {
257267
return
258268
}
@@ -283,11 +293,11 @@ export class BlockHeader {
283293
throw new Error('invalid gas limit')
284294
}
285295

286-
if (utils.bufferToInt(this.number) - utils.bufferToInt(parentBlock.header.number) !== 1) {
296+
if (bufferToInt(this.number) - bufferToInt(parentBlock.header.number) !== 1) {
287297
throw new Error('invalid height')
288298
}
289299

290-
if (utils.bufferToInt(this.timestamp) <= utils.bufferToInt(parentBlock.header.timestamp)) {
300+
if (bufferToInt(this.timestamp) <= bufferToInt(parentBlock.header.timestamp)) {
291301
throw new Error('invalid timestamp')
292302
}
293303

@@ -301,7 +311,7 @@ export class BlockHeader {
301311
* Returns the hash of the block header.
302312
*/
303313
hash(): Buffer {
304-
return utils.rlphash(this.raw)
314+
return rlphash(this.raw)
305315
}
306316

307317
/**
@@ -347,7 +357,7 @@ export class BlockHeader {
347357

348358
return commonHardFork !== null
349359
? commonHardFork
350-
: this._common.activeHardfork(utils.bufferToInt(this.number))
360+
: this._common.activeHardfork(bufferToInt(this.number))
351361
}
352362

353363
private async _getBlockByHash(blockchain: Blockchain, hash: Buffer): Promise<Block | undefined> {

packages/block/test/difficulty.spec.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import * as utils from 'ethereumjs-util'
2-
import { BN } from 'ethereumjs-util'
1+
import { toBuffer } from 'ethereumjs-util'
32
import { Block } from '../src/block'
43
import tape = require('tape')
54

5+
const { BN } = require('ethereumjs-util')
6+
67
function isHexPrefixed(str: string) {
78
return str.toLowerCase().startsWith('0x')
89
}
910

1011
function normalize(data: any) {
1112
Object.keys(data).forEach(function(i) {
1213
if (i !== 'homestead' && typeof data[i] === 'string') {
13-
data[i] = isHexPrefixed(data[i]) ? new BN(utils.toBuffer(data[i])) : new BN(data[i])
14+
data[i] = isHexPrefixed(data[i]) ? new BN(toBuffer(data[i])) : new BN(data[i])
1415
}
1516
})
1617
}

packages/block/test/header.spec.ts

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
import tape = require('tape')
22
import Common from 'ethereumjs-common'
3-
import * as utils from 'ethereumjs-util'
4-
import { rlp } from 'ethereumjs-util'
3+
import { rlp, toBuffer, zeros, KECCAK256_RLP_S, KECCAK256_RLP_ARRAY_S } from 'ethereumjs-util'
54
import { BlockHeader } from '../src/header'
65
import { Block } from '../src/block'
76

87
tape('[Block]: Header functions', function(t) {
98
t.test('should create with default constructor', function(st) {
109
function compareDefaultHeader(st: tape.Test, header: BlockHeader) {
11-
st.deepEqual(header.parentHash, utils.zeros(32))
12-
st.equal(header.uncleHash.toString('hex'), utils.KECCAK256_RLP_ARRAY_S)
13-
st.deepEqual(header.coinbase, utils.zeros(20))
14-
st.deepEqual(header.stateRoot, utils.zeros(32))
15-
st.equal(header.transactionsTrie.toString('hex'), utils.KECCAK256_RLP_S)
16-
st.equal(header.receiptTrie.toString('hex'), utils.KECCAK256_RLP_S)
17-
st.deepEqual(header.bloom, utils.zeros(256))
10+
st.deepEqual(header.parentHash, zeros(32))
11+
st.equal(header.uncleHash.toString('hex'), KECCAK256_RLP_ARRAY_S)
12+
st.deepEqual(header.coinbase, zeros(20))
13+
st.deepEqual(header.stateRoot, zeros(32))
14+
st.equal(header.transactionsTrie.toString('hex'), KECCAK256_RLP_S)
15+
st.equal(header.receiptTrie.toString('hex'), KECCAK256_RLP_S)
16+
st.deepEqual(header.bloom, zeros(256))
1817
st.deepEqual(header.difficulty, Buffer.from([]))
19-
st.deepEqual(header.number, utils.toBuffer(1150000))
18+
st.deepEqual(header.number, toBuffer(1150000))
2019
st.deepEqual(header.gasLimit, Buffer.from('ffffffffffffff', 'hex'))
2120
st.deepEqual(header.gasUsed, Buffer.from([]))
2221
st.deepEqual(header.timestamp, Buffer.from([]))
2322
st.deepEqual(header.extraData, Buffer.from([]))
24-
st.deepEqual(header.mixHash, utils.zeros(32))
25-
st.deepEqual(header.nonce, utils.zeros(8))
23+
st.deepEqual(header.mixHash, zeros(32))
24+
st.deepEqual(header.nonce, zeros(8))
2625
}
2726

2827
let header = new BlockHeader()

packages/blockchain/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"ethashjs": "~0.0.7",
4242
"ethereumjs-block": "~3.0.0",
4343
"ethereumjs-common": "^1.5.0",
44-
"ethereumjs-util": "~6.1.0",
44+
"ethereumjs-util": "~7.0.2",
4545
"flow-stoplight": "^1.0.0",
4646
"level-mem": "^3.0.1",
4747
"lru-cache": "^5.1.1",
@@ -54,7 +54,7 @@
5454
"@ethereumjs/config-tsc": "^1.1.1",
5555
"@ethereumjs/config-tslint": "^1.1.1",
5656
"@types/async": "^2.4.1",
57-
"@types/bn.js": "^4.11.4",
57+
"@types/bn.js": "^4.11.6",
5858
"@types/lru-cache": "^5.1.0",
5959
"@types/node": "^11.11.4",
6060
"@types/semaphore": "^1.1.0",
@@ -67,7 +67,7 @@
6767
"tslint": "^5.13.1",
6868
"typedoc": "next",
6969
"typedoc-plugin-markdown": "^2.2.17",
70-
"typescript": "^3.3.3333",
70+
"typescript": "^3.9.2",
7171
"typestrict": "^1.0.2"
7272
}
7373
}

0 commit comments

Comments
 (0)