ethereumjs / ethereumjs-monorepo

@@ -4,11 +4,11 @@
Loading
4 4
import { TransactionFactory } from '@ethereumjs/tx'
5 5
import {
6 6
  arrToBufArr,
7 -
  bigIntToBuffer,
7 +
  bigIntToUnpaddedBuffer,
8 8
  bufArrToArr,
9 9
  bufferToBigInt,
10 10
  bufferToInt,
11 -
  intToBuffer,
11 +
  intToUnpaddedBuffer,
12 12
} from '@ethereumjs/util'
13 13
import { encodeReceipt } from '@ethereumjs/vm/dist/runBlock'
14 14
@@ -86,7 +86,7 @@
Loading
86 86
    {
87 87
      name: 'NewBlockHashes',
88 88
      code: 0x01,
89 -
      encode: (hashes: any[]) => hashes.map((hn) => [hn[0], bigIntToBuffer(hn[1])]),
89 +
      encode: (hashes: any[]) => hashes.map((hn) => [hn[0], bigIntToUnpaddedBuffer(hn[1])]),
90 90
      decode: (hashes: any[]) => hashes.map((hn) => [hn[0], bufferToBigInt(hn[1])]),
91 91
    },
92 92
    {
@@ -116,12 +116,12 @@
Loading
116 116
      code: 0x03,
117 117
      response: 0x04,
118 118
      encode: ({ reqId, block, max, skip = 0, reverse = false }: GetBlockHeadersOpts) => [
119 -
        bigIntToBuffer(reqId ?? ++this.nextReqId),
119 +
        bigIntToUnpaddedBuffer(reqId ?? ++this.nextReqId),
120 120
        [
121 -
          typeof block === 'bigint' ? bigIntToBuffer(block) : block,
122 -
          max === 0 ? Buffer.from([]) : intToBuffer(max),
123 -
          skip === 0 ? Buffer.from([]) : intToBuffer(skip),
124 -
          !reverse ? Buffer.from([]) : Buffer.from([1]),
121 +
          typeof block === 'bigint' ? bigIntToUnpaddedBuffer(block) : block,
122 +
          intToUnpaddedBuffer(max),
123 +
          intToUnpaddedBuffer(skip),
124 +
          intToUnpaddedBuffer(!reverse ? 0 : 1),
125 125
        ],
126 126
      ],
127 127
      decode: ([reqId, [block, max, skip, reverse]]: any) => ({
@@ -136,7 +136,7 @@
Loading
136 136
      name: 'BlockHeaders',
137 137
      code: 0x04,
138 138
      encode: ({ reqId, headers }: { reqId: bigint; headers: BlockHeader[] }) => [
139 -
        bigIntToBuffer(reqId),
139 +
        bigIntToUnpaddedBuffer(reqId),
140 140
        headers.map((h) => h.raw()),
141 141
      ],
142 142
      decode: ([reqId, headers]: [Buffer, BlockHeaderBuffer[]]) => [
@@ -161,7 +161,7 @@
Loading
161 161
      code: 0x05,
162 162
      response: 0x06,
163 163
      encode: ({ reqId, hashes }: GetBlockBodiesOpts) => [
164 -
        bigIntToBuffer(reqId ?? ++this.nextReqId),
164 +
        bigIntToUnpaddedBuffer(reqId ?? ++this.nextReqId),
165 165
        hashes,
166 166
      ],
167 167
      decode: ([reqId, hashes]: [Buffer, Buffer[]]) => ({
@@ -173,7 +173,7 @@
Loading
173 173
      name: 'BlockBodies',
174 174
      code: 0x06,
175 175
      encode: ({ reqId, bodies }: { reqId: bigint; bodies: BlockBodyBuffer[] }) => [
176 -
        bigIntToBuffer(reqId),
176 +
        bigIntToUnpaddedBuffer(reqId),
177 177
        bodies,
178 178
      ],
179 179
      decode: ([reqId, bodies]: [Buffer, BlockBodyBuffer[]]) => [bufferToBigInt(reqId), bodies],
@@ -181,7 +181,7 @@
Loading
181 181
    {
182 182
      name: 'NewBlock',
183 183
      code: 0x07,
184 -
      encode: ([block, td]: [Block, bigint]) => [block.raw(), bigIntToBuffer(td)],
184 +
      encode: ([block, td]: [Block, bigint]) => [block.raw(), bigIntToUnpaddedBuffer(td)],
185 185
      decode: ([block, td]: [BlockBuffer, Buffer]) => [
186 186
        Block.fromValuesArray(block, {
187 187
          common: this.config.chainCommon,
@@ -193,13 +193,15 @@
Loading
193 193
    {
194 194
      name: 'NewPooledTransactionHashes',
195 195
      code: 0x08,
196 +
      encode: (hashes: Buffer[]) => hashes,
197 +
      decode: (hashes: Buffer[]) => hashes,
196 198
    },
197 199
    {
198 200
      name: 'GetPooledTransactions',
199 201
      code: 0x09,
200 202
      response: 0x0a,
201 203
      encode: ({ reqId, hashes }: GetPooledTransactionsOpts) => [
202 -
        bigIntToBuffer(reqId ?? ++this.nextReqId),
204 +
        bigIntToUnpaddedBuffer(reqId ?? ++this.nextReqId),
203 205
        hashes,
204 206
      ],
205 207
      decode: ([reqId, hashes]: [Buffer, Buffer[]]) => ({
@@ -219,7 +221,7 @@
Loading
219 221
            serializedTxs.push(tx.serialize())
220 222
          }
221 223
        }
222 -
        return [bigIntToBuffer(reqId), serializedTxs]
224 +
        return [bigIntToUnpaddedBuffer(reqId), serializedTxs]
223 225
      },
224 226
      decode: ([reqId, txs]: [Buffer, any[]]) => [
225 227
        bufferToBigInt(reqId),
@@ -234,7 +236,7 @@
Loading
234 236
      code: 0x0f,
235 237
      response: 0x10,
236 238
      encode: ({ reqId, hashes }: { reqId: bigint; hashes: Buffer[] }) => [
237 -
        bigIntToBuffer(reqId ?? ++this.nextReqId),
239 +
        bigIntToUnpaddedBuffer(reqId ?? ++this.nextReqId),
238 240
        hashes,
239 241
      ],
240 242
      decode: ([reqId, hashes]: [Buffer, Buffer[]]) => ({
@@ -251,7 +253,7 @@
Loading
251 253
          const encodedReceipt = encodeReceipt(receipt, receipt.txType)
252 254
          serializedReceipts.push(encodedReceipt)
253 255
        }
254 -
        return [bigIntToBuffer(reqId), serializedReceipts]
256 +
        return [bigIntToUnpaddedBuffer(reqId), serializedReceipts]
255 257
      },
256 258
      decode: ([reqId, receipts]: [Buffer, Buffer[]]) => [
257 259
        bufferToBigInt(reqId),
@@ -325,12 +327,11 @@
Loading
325 327
   */
326 328
  encodeStatus(): any {
327 329
    return {
328 -
      networkId: bigIntToBuffer(this.chain.networkId),
329 -
      td:
330 -
        this.chain.blocks.td === BigInt(0) ? Buffer.from([]) : bigIntToBuffer(this.chain.blocks.td),
330 +
      networkId: bigIntToUnpaddedBuffer(this.chain.networkId),
331 +
      td: bigIntToUnpaddedBuffer(this.chain.blocks.td),
331 332
      bestHash: this.chain.blocks.latest!.hash(),
332 333
      genesisHash: this.chain.genesis.hash(),
333 -
      latestBlock: bigIntToBuffer(this.chain.blocks.latest!.header.number),
334 +
      latestBlock: bigIntToUnpaddedBuffer(this.chain.blocks.latest!.header.number),
334 335
    }
335 336
  }
336 337

@@ -1,7 +1,7 @@
Loading
1 1
import {
2 2
  accountBodyFromSlim,
3 3
  accountBodyToSlim,
4 -
  bigIntToBuffer,
4 +
  bigIntToUnpaddedBuffer,
5 5
  bufferToBigInt,
6 6
  setLengthLeft,
7 7
} from '@ethereumjs/util'
@@ -97,11 +97,11 @@
Loading
97 97
      // [reqID: P, rootHash: B_32, startingHash: B_32, limitHash: B_32, responseBytes: P]
98 98
      encode: ({ reqId, root, origin, limit, bytes }: GetAccountRangeOpts) => {
99 99
        return [
100 -
          bigIntToBuffer(reqId ?? ++this.nextReqId),
100 +
          bigIntToUnpaddedBuffer(reqId ?? ++this.nextReqId),
101 101
          setLengthLeft(root, 32),
102 102
          setLengthLeft(origin, 32),
103 103
          setLengthLeft(limit, 32),
104 -
          bigIntToBuffer(bytes),
104 +
          bigIntToUnpaddedBuffer(bytes),
105 105
        ]
106 106
      },
107 107
      decode: ([reqId, root, origin, limit, bytes]: any) => {
@@ -128,7 +128,7 @@
Loading
128 128
        proof: Buffer[]
129 129
      }) => {
130 130
        return [
131 -
          bigIntToBuffer(reqId ?? ++this.nextReqId),
131 +
          bigIntToUnpaddedBuffer(reqId ?? ++this.nextReqId),
132 132
          accounts.map((account) => [
133 133
            setLengthLeft(account.hash, 32),
134 134
            accountBodyToSlim(account.body),
@@ -157,12 +157,12 @@
Loading
157 157
      // [reqID: P, rootHash: B_32, accountHashes: [B_32], startingHash: B, limitHash: B, responseBytes: P]
158 158
      encode: ({ reqId, root, accounts, origin, limit, bytes }: GetStorageRangesOpts) => {
159 159
        return [
160 -
          bigIntToBuffer(reqId ?? ++this.nextReqId),
160 +
          bigIntToUnpaddedBuffer(reqId ?? ++this.nextReqId),
161 161
          setLengthLeft(root, 32),
162 162
          accounts.map((acc) => setLengthLeft(acc, 32)),
163 163
          origin,
164 164
          limit,
165 -
          bigIntToBuffer(bytes),
165 +
          bigIntToUnpaddedBuffer(bytes),
166 166
        ]
167 167
      },
168 168
      decode: ([reqId, root, accounts, origin, limit, bytes]: any) => {
@@ -190,7 +190,7 @@
Loading
190 190
        proof: Buffer[]
191 191
      }) => {
192 192
        return [
193 -
          bigIntToBuffer(reqId ?? ++this.nextReqId),
193 +
          bigIntToUnpaddedBuffer(reqId ?? ++this.nextReqId),
194 194
          slots.map((accSlots) =>
195 195
            accSlots.map((slotData) => [setLengthLeft(slotData.hash, 32), slotData.body])
196 196
          ),
@@ -214,9 +214,9 @@
Loading
214 214
      // [reqID: P, hashes: [hash1: B_32, hash2: B_32, ...], bytes: P]
215 215
      encode: ({ reqId, hashes, bytes }: GetByteCodesOpts) => {
216 216
        return [
217 -
          bigIntToBuffer(reqId ?? ++this.nextReqId),
217 +
          bigIntToUnpaddedBuffer(reqId ?? ++this.nextReqId),
218 218
          hashes.map((hash) => setLengthLeft(hash, 32)),
219 -
          bigIntToBuffer(bytes),
219 +
          bigIntToUnpaddedBuffer(bytes),
220 220
        ]
221 221
      },
222 222
      decode: ([reqId, hashes, bytes]: any) => {
@@ -232,7 +232,7 @@
Loading
232 232
      code: 0x05,
233 233
      // [reqID: P, codes: [code1: B, code2: B, ...]]
234 234
      encode: ({ reqId, codes }: { reqId: bigint; codes: Buffer[] }) => {
235 -
        return [bigIntToBuffer(reqId ?? ++this.nextReqId), codes]
235 +
        return [bigIntToUnpaddedBuffer(reqId ?? ++this.nextReqId), codes]
236 236
      },
237 237
      decode: ([reqId, codes]: any) => {
238 238
        return {
@@ -248,10 +248,10 @@
Loading
248 248
      // [reqID: P, rootHash: B_32, paths: [[accPath: B, slotPath1: B, slotPath2: B, ...]...], bytes: P]
249 249
      encode: ({ reqId, root, paths, bytes }: GetTrieNodesOpts) => {
250 250
        return [
251 -
          bigIntToBuffer(reqId ?? ++this.nextReqId),
251 +
          bigIntToUnpaddedBuffer(reqId ?? ++this.nextReqId),
252 252
          setLengthLeft(root, 32),
253 253
          paths,
254 -
          bigIntToBuffer(bytes),
254 +
          bigIntToUnpaddedBuffer(bytes),
255 255
        ]
256 256
      },
257 257
      decode: ([reqId, root, paths, bytes]: any) => {
@@ -268,7 +268,7 @@
Loading
268 268
      code: 0x07,
269 269
      // [reqID: P, nodes: [node1: B, node2: B, ...]]
270 270
      encode: ({ reqId, nodes }: { reqId: bigint; nodes: Buffer[] }) => {
271 -
        return [bigIntToBuffer(reqId ?? ++this.nextReqId), nodes]
271 +
        return [bigIntToUnpaddedBuffer(reqId ?? ++this.nextReqId), nodes]
272 272
      },
273 273
      decode: ([reqId, nodes]: any) => {
274 274
        return {

@@ -1,5 +1,5 @@
Loading
1 1
import { BlockHeader } from '@ethereumjs/block'
2 -
import { bigIntToBuffer, bufferToBigInt, bufferToInt, intToBuffer } from '@ethereumjs/util'
2 +
import { bigIntToUnpaddedBuffer, bufferToBigInt, bufferToInt, intToBuffer } from '@ethereumjs/util'
3 3
4 4
import { Protocol } from './protocol'
5 5
@@ -56,8 +56,8 @@
Loading
56 56
      encode: ({ headHash, headNumber, headTd, reorgDepth }: any) => [
57 57
        // TO DO: handle state changes
58 58
        headHash,
59 -
        bigIntToBuffer(headNumber),
60 -
        bigIntToBuffer(headTd),
59 +
        bigIntToUnpaddedBuffer(headNumber),
60 +
        bigIntToUnpaddedBuffer(headTd),
61 61
        intToBuffer(reorgDepth),
62 62
      ],
63 63
      decode: ([headHash, headNumber, headTd, reorgDepth]: any) => ({
@@ -73,8 +73,13 @@
Loading
73 73
      code: 0x02,
74 74
      response: 0x03,
75 75
      encode: ({ reqId, block, max, skip = 0, reverse = false }: GetBlockHeadersOpts) => [
76 -
        bigIntToBuffer(reqId ?? ++this.nextReqId),
77 -
        [typeof block === 'bigint' ? bigIntToBuffer(block) : block, max, skip, !reverse ? 0 : 1],
76 +
        bigIntToUnpaddedBuffer(reqId ?? ++this.nextReqId),
77 +
        [
78 +
          typeof block === 'bigint' ? bigIntToUnpaddedBuffer(block) : block,
79 +
          max,
80 +
          skip,
81 +
          !reverse ? 0 : 1,
82 +
        ],
78 83
      ],
79 84
      decode: ([reqId, [block, max, skip, reverse]]: any) => ({
80 85
        reqId: bufferToBigInt(reqId),
@@ -88,8 +93,8 @@
Loading
88 93
      name: 'BlockHeaders',
89 94
      code: 0x03,
90 95
      encode: ({ reqId, bv, headers }: any) => [
91 -
        bigIntToBuffer(reqId),
92 -
        bigIntToBuffer(bv),
96 +
        bigIntToUnpaddedBuffer(reqId),
97 +
        bigIntToUnpaddedBuffer(bv),
93 98
        headers.map((h: BlockHeader) => h.raw()),
94 99
      ],
95 100
      decode: ([reqId, bv, headers]: any) => ({
@@ -176,18 +181,13 @@
Loading
176 181
      this.chain.genesis.hash()
177 182
    )
178 183
    const nextFork = this.config.chainCommon.nextHardforkBlock(this.config.chainCommon.hardfork())
179 -
    const forkID = [
180 -
      Buffer.from(forkHash.slice(2), 'hex'),
181 -
      typeof nextFork === 'bigint' && nextFork !== BigInt(0)
182 -
        ? bigIntToBuffer(nextFork)
183 -
        : Buffer.from([]),
184 -
    ]
184 +
    const forkID = [Buffer.from(forkHash.slice(2), 'hex'), bigIntToUnpaddedBuffer(nextFork ?? 0n)]
185 185
186 186
    return {
187 -
      networkId: bigIntToBuffer(this.chain.networkId),
188 -
      headTd: bigIntToBuffer(this.chain.headers.td),
187 +
      networkId: bigIntToUnpaddedBuffer(this.chain.networkId),
188 +
      headTd: bigIntToUnpaddedBuffer(this.chain.headers.td),
189 189
      headHash: this.chain.headers.latest?.hash(),
190 -
      headNum: bigIntToBuffer(this.chain.headers.height),
190 +
      headNum: bigIntToUnpaddedBuffer(this.chain.headers.height),
191 191
      genesisHash: this.chain.genesis.hash(),
192 192
      forkID,
193 193
      recentTxLookup: intToBuffer(1),
Files Coverage
packages 87.67%
Project Totals (189 files) 87.67%
1
coverage:
2
  status:
3
    project:
4
      default:
5
        target: auto
6
        threshold: 2%
7
    patch:
8
      default:
9
        target: auto
10
        threshold: 5%
11
comment:
12
  layout: 'reach, flags'
13
flags:
14
  rlp:
15
    carryforward: true
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading