Skip to content

Commit

Permalink
refactor: rlp -> @ethereumjs/rlp
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasbrugneaux committed Feb 23, 2024
1 parent 388a034 commit 5bb4005
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/sdk/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
],
"dependencies": {
"@celo/base": "^6.0.0",
"@ethereumjs/rlp": "^5.0.2",
"@ethereumjs/util": "8.0.5",
"@noble/ciphers": "0.4.1",
"@noble/curves": "1.3.0",
Expand All @@ -32,7 +33,6 @@
"bignumber.js": "^9.0.0",
"fp-ts": "2.1.1",
"io-ts": "2.0.1",
"rlp": "^2.2.4",
"web3-eth-abi": "1.10.0",
"web3-utils": "1.10.0"
},
Expand Down
22 changes: 14 additions & 8 deletions packages/sdk/utils/src/istanbul.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { bufferToHex, toChecksumAddress } from '@ethereumjs/util'
import BigNumber from 'bignumber.js'
import * as rlp from 'rlp'
// import * as rlp from 'rlp'
import * as rlp from '@ethereumjs/rlp'
import { Address } from './address'

// This file contains utilities that help with istanbul-specific block information.
Expand Down Expand Up @@ -42,14 +43,19 @@ function sealFromBuffers(data: Buffer[]): Seal {
// Parse RLP encoded block extra data into an IstanbulExtra object.
export function parseBlockExtraData(data: string): IstanbulExtra {
const buffer = Buffer.from(data.replace(/^0x/, ''), 'hex')
const decode: any = rlp.decode('0x' + buffer.slice(ISTANBUL_EXTRA_VANITY_BYTES).toString('hex'))
const decode = rlp.decode('0x' + buffer.subarray(ISTANBUL_EXTRA_VANITY_BYTES).toString('hex'))

return {
addedValidators: decode[0].map((addr: Buffer) => toChecksumAddress(bufferToHex(addr))),
addedValidatorsPublicKeys: decode[1].map((key: Buffer) => '0x' + key.toString('hex')),
removedValidators: bigNumberFromBuffer(decode[2]),
seal: '0x' + decode[3].toString('hex'),
aggregatedSeal: sealFromBuffers(decode[4]),
parentAggregatedSeal: sealFromBuffers(decode[5]),
addedValidators: (decode.at(0) as Uint8Array[]).map((addr) =>
toChecksumAddress(bufferToHex(Buffer.from(addr)))
),
addedValidatorsPublicKeys: (decode.at(1) as Uint8Array[]).map(
(key) => '0x' + Buffer.from(key).toString('hex')
),
removedValidators: bigNumberFromBuffer(Buffer.from(decode.at(2) as Uint8Array)),
seal: '0x' + Buffer.from(decode.at(3) as Uint8Array).toString('hex'),
aggregatedSeal: sealFromBuffers((decode.at(4) as Uint8Array[]).map(Buffer.from)),
parentAggregatedSeal: sealFromBuffers((decode.at(5) as Uint8Array[]).map(Buffer.from)),
}
}

Expand Down

0 comments on commit 5bb4005

Please sign in to comment.