@feelyourprotocol/block 8141.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +466 -0
  3. package/dist/cjs/block/block.d.ts +147 -0
  4. package/dist/cjs/block/block.d.ts.map +1 -0
  5. package/dist/cjs/block/block.js +415 -0
  6. package/dist/cjs/block/block.js.map +1 -0
  7. package/dist/cjs/block/constructors.d.ts +77 -0
  8. package/dist/cjs/block/constructors.d.ts.map +1 -0
  9. package/dist/cjs/block/constructors.js +298 -0
  10. package/dist/cjs/block/constructors.js.map +1 -0
  11. package/dist/cjs/block/index.d.ts +3 -0
  12. package/dist/cjs/block/index.d.ts.map +1 -0
  13. package/dist/cjs/block/index.js +19 -0
  14. package/dist/cjs/block/index.js.map +1 -0
  15. package/dist/cjs/consensus/clique.d.ts +52 -0
  16. package/dist/cjs/consensus/clique.d.ts.map +1 -0
  17. package/dist/cjs/consensus/clique.js +144 -0
  18. package/dist/cjs/consensus/clique.js.map +1 -0
  19. package/dist/cjs/consensus/ethash.d.ts +9 -0
  20. package/dist/cjs/consensus/ethash.d.ts.map +1 -0
  21. package/dist/cjs/consensus/ethash.js +13 -0
  22. package/dist/cjs/consensus/ethash.js.map +1 -0
  23. package/dist/cjs/consensus/index.d.ts +3 -0
  24. package/dist/cjs/consensus/index.d.ts.map +1 -0
  25. package/dist/cjs/consensus/index.js +29 -0
  26. package/dist/cjs/consensus/index.js.map +1 -0
  27. package/dist/cjs/from-beacon-payload.d.ts +36 -0
  28. package/dist/cjs/from-beacon-payload.d.ts.map +1 -0
  29. package/dist/cjs/from-beacon-payload.js +48 -0
  30. package/dist/cjs/from-beacon-payload.js.map +1 -0
  31. package/dist/cjs/header/constructors.d.ts +39 -0
  32. package/dist/cjs/header/constructors.d.ts.map +1 -0
  33. package/dist/cjs/header/constructors.js +127 -0
  34. package/dist/cjs/header/constructors.js.map +1 -0
  35. package/dist/cjs/header/header.d.ts +134 -0
  36. package/dist/cjs/header/header.d.ts.map +1 -0
  37. package/dist/cjs/header/header.js +699 -0
  38. package/dist/cjs/header/header.js.map +1 -0
  39. package/dist/cjs/header/index.d.ts +3 -0
  40. package/dist/cjs/header/index.d.ts.map +1 -0
  41. package/dist/cjs/header/index.js +19 -0
  42. package/dist/cjs/header/index.js.map +1 -0
  43. package/dist/cjs/helpers.d.ts +59 -0
  44. package/dist/cjs/helpers.d.ts.map +1 -0
  45. package/dist/cjs/helpers.js +172 -0
  46. package/dist/cjs/helpers.js.map +1 -0
  47. package/dist/cjs/index.d.ts +8 -0
  48. package/dist/cjs/index.d.ts.map +1 -0
  49. package/dist/cjs/index.js +31 -0
  50. package/dist/cjs/index.js.map +1 -0
  51. package/dist/cjs/package.json +3 -0
  52. package/dist/cjs/params.d.ts +3 -0
  53. package/dist/cjs/params.d.ts.map +1 -0
  54. package/dist/cjs/params.js +97 -0
  55. package/dist/cjs/params.js.map +1 -0
  56. package/dist/cjs/types.d.ts +228 -0
  57. package/dist/cjs/types.d.ts.map +1 -0
  58. package/dist/cjs/types.js +3 -0
  59. package/dist/cjs/types.js.map +1 -0
  60. package/dist/esm/block/block.d.ts +147 -0
  61. package/dist/esm/block/block.d.ts.map +1 -0
  62. package/dist/esm/block/block.js +411 -0
  63. package/dist/esm/block/block.js.map +1 -0
  64. package/dist/esm/block/constructors.d.ts +77 -0
  65. package/dist/esm/block/constructors.d.ts.map +1 -0
  66. package/dist/esm/block/constructors.js +286 -0
  67. package/dist/esm/block/constructors.js.map +1 -0
  68. package/dist/esm/block/index.d.ts +3 -0
  69. package/dist/esm/block/index.d.ts.map +1 -0
  70. package/dist/esm/block/index.js +3 -0
  71. package/dist/esm/block/index.js.map +1 -0
  72. package/dist/esm/consensus/clique.d.ts +52 -0
  73. package/dist/esm/consensus/clique.d.ts.map +1 -0
  74. package/dist/esm/consensus/clique.js +132 -0
  75. package/dist/esm/consensus/clique.js.map +1 -0
  76. package/dist/esm/consensus/ethash.d.ts +9 -0
  77. package/dist/esm/consensus/ethash.d.ts.map +1 -0
  78. package/dist/esm/consensus/ethash.js +10 -0
  79. package/dist/esm/consensus/ethash.js.map +1 -0
  80. package/dist/esm/consensus/index.d.ts +3 -0
  81. package/dist/esm/consensus/index.d.ts.map +1 -0
  82. package/dist/esm/consensus/index.js +3 -0
  83. package/dist/esm/consensus/index.js.map +1 -0
  84. package/dist/esm/from-beacon-payload.d.ts +36 -0
  85. package/dist/esm/from-beacon-payload.d.ts.map +1 -0
  86. package/dist/esm/from-beacon-payload.js +45 -0
  87. package/dist/esm/from-beacon-payload.js.map +1 -0
  88. package/dist/esm/header/constructors.d.ts +39 -0
  89. package/dist/esm/header/constructors.d.ts.map +1 -0
  90. package/dist/esm/header/constructors.js +120 -0
  91. package/dist/esm/header/constructors.js.map +1 -0
  92. package/dist/esm/header/header.d.ts +134 -0
  93. package/dist/esm/header/header.d.ts.map +1 -0
  94. package/dist/esm/header/header.js +695 -0
  95. package/dist/esm/header/header.js.map +1 -0
  96. package/dist/esm/header/index.d.ts +3 -0
  97. package/dist/esm/header/index.d.ts.map +1 -0
  98. package/dist/esm/header/index.js +3 -0
  99. package/dist/esm/header/index.js.map +1 -0
  100. package/dist/esm/helpers.d.ts +59 -0
  101. package/dist/esm/helpers.d.ts.map +1 -0
  102. package/dist/esm/helpers.js +161 -0
  103. package/dist/esm/helpers.js.map +1 -0
  104. package/dist/esm/index.d.ts +8 -0
  105. package/dist/esm/index.d.ts.map +1 -0
  106. package/dist/esm/index.js +8 -0
  107. package/dist/esm/index.js.map +1 -0
  108. package/dist/esm/package.json +3 -0
  109. package/dist/esm/params.d.ts +3 -0
  110. package/dist/esm/params.d.ts.map +1 -0
  111. package/dist/esm/params.js +94 -0
  112. package/dist/esm/params.js.map +1 -0
  113. package/dist/esm/types.d.ts +228 -0
  114. package/dist/esm/types.d.ts.map +1 -0
  115. package/dist/esm/types.js +2 -0
  116. package/dist/esm/types.js.map +1 -0
  117. package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -0
  118. package/dist/tsconfig.prod.esm.tsbuildinfo +1 -0
  119. package/package.json +75 -0
  120. package/src/block/block.ts +526 -0
  121. package/src/block/constructors.ts +407 -0
  122. package/src/block/index.ts +2 -0
  123. package/src/consensus/clique.ts +171 -0
  124. package/src/consensus/ethash.ts +11 -0
  125. package/src/consensus/index.ts +12 -0
  126. package/src/from-beacon-payload.ts +82 -0
  127. package/src/header/constructors.ts +169 -0
  128. package/src/header/header.ts +890 -0
  129. package/src/header/index.ts +2 -0
  130. package/src/helpers.ts +223 -0
  131. package/src/index.ts +13 -0
  132. package/src/params.ts +95 -0
  133. package/src/types.ts +254 -0
@@ -0,0 +1,415 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Block = void 0;
4
+ const common_1 = require("@feelyourprotocol/common");
5
+ const mpt_1 = require("@feelyourprotocol/mpt");
6
+ const rlp_1 = require("@feelyourprotocol/rlp");
7
+ const tx_1 = require("@feelyourprotocol/tx");
8
+ const util_1 = require("@feelyourprotocol/util");
9
+ const sha2_js_1 = require("@noble/hashes/sha2.js");
10
+ const sha3_js_1 = require("@noble/hashes/sha3.js");
11
+ /* eslint-disable */
12
+ // This is to allow for a proper and linked collection of constructors for the class header.
13
+ // For tree shaking/code size this should be no problem since types go away on transpilation.
14
+ // TODO: See if there is an easier way to achieve the same result.
15
+ // See: https://github.com/microsoft/TypeScript/issues/47558
16
+ // (situation will eventually improve on Typescript and/or Eslint update)
17
+ const index_ts_1 = require("../index.js");
18
+ /**
19
+ * Class representing a block in the Ethereum network. The {@link BlockHeader} has its own
20
+ * class and can be used independently, for a block it is included in the form of the
21
+ * {@link Block.header} property.
22
+ *
23
+ * A block object can be created with one of the following constructor methods
24
+ * (separate from the Block class to allow for tree shaking):
25
+ *
26
+ * - {@link createBlock }
27
+ * - {@link createBlockFromBytesArray }
28
+ * - {@link createBlockFromRLP }
29
+ * - {@link createBlockFromRPC }
30
+ * - {@link createBlockFromJSONRPCProvider }
31
+ * - {@link createBlockFromExecutionPayload }
32
+ * - {@link createBlockFromBeaconPayloadJSON }
33
+ */
34
+ class Block {
35
+ /**
36
+ * This constructor takes the values, validates them, assigns them and freezes the object.
37
+ *
38
+ * @deprecated Use the static factory methods (see {@link Block} for an overview) to assist in creating
39
+ * a Block object from varying data types and options.
40
+ */
41
+ constructor(header, transactions = [], uncleHeaders = [], withdrawals, opts = {}) {
42
+ this.transactions = [];
43
+ this.uncleHeaders = [];
44
+ this.cache = {};
45
+ this.header = header ?? new index_ts_1.BlockHeader({}, opts);
46
+ this.common = this.header.common;
47
+ this.keccakFunction = this.common.customCrypto.keccak256 ?? sha3_js_1.keccak_256;
48
+ this.sha256Function = this.common.customCrypto.sha256 ?? sha2_js_1.sha256;
49
+ this.transactions = transactions;
50
+ this.withdrawals = withdrawals ?? (this.common.isActivatedEIP(4895) ? [] : undefined);
51
+ this.uncleHeaders = uncleHeaders;
52
+ if (uncleHeaders.length > 0) {
53
+ this.validateUncles();
54
+ if (this.common.consensusType() === common_1.ConsensusType.ProofOfAuthority) {
55
+ const msg = this._errorMsg('Block initialization with uncleHeaders on a PoA network is not allowed');
56
+ throw (0, util_1.EthereumJSErrorWithoutCode)(msg);
57
+ }
58
+ if (this.common.consensusType() === common_1.ConsensusType.ProofOfStake) {
59
+ const msg = this._errorMsg('Block initialization with uncleHeaders on a PoS network is not allowed');
60
+ throw (0, util_1.EthereumJSErrorWithoutCode)(msg);
61
+ }
62
+ }
63
+ if (!this.common.isActivatedEIP(4895) && withdrawals !== undefined) {
64
+ throw (0, util_1.EthereumJSErrorWithoutCode)('Cannot have a withdrawals field if EIP 4895 is not active');
65
+ }
66
+ const freeze = opts?.freeze ?? true;
67
+ if (freeze) {
68
+ Object.freeze(this);
69
+ }
70
+ }
71
+ /**
72
+ * Returns an array of the raw byte arrays for this block, in order.
73
+ */
74
+ raw() {
75
+ const bytesArray = [
76
+ this.header.raw(),
77
+ this.transactions.map((tx) => tx.supports(tx_1.Capability.EIP2718TypedTransaction) ? tx.serialize() : tx.raw()),
78
+ this.uncleHeaders.map((uh) => uh.raw()),
79
+ ];
80
+ const withdrawalsRaw = this.withdrawals?.map((wt) => wt.raw());
81
+ if (withdrawalsRaw) {
82
+ bytesArray.push(withdrawalsRaw);
83
+ }
84
+ return bytesArray;
85
+ }
86
+ /**
87
+ * Returns the hash of the block.
88
+ */
89
+ hash() {
90
+ return this.header.hash();
91
+ }
92
+ /**
93
+ * Determines if this block is the genesis block.
94
+ */
95
+ isGenesis() {
96
+ return this.header.isGenesis();
97
+ }
98
+ /**
99
+ * Returns the rlp encoding of the block.
100
+ */
101
+ serialize() {
102
+ return rlp_1.RLP.encode(this.raw());
103
+ }
104
+ /**
105
+ * Generates transaction trie for validation.
106
+ */
107
+ async genTxTrie() {
108
+ return (0, index_ts_1.genTransactionsTrieRoot)(this.transactions, new mpt_1.MerklePatriciaTrie({ common: this.common }));
109
+ }
110
+ /**
111
+ * Validates the transaction trie by generating a trie
112
+ * and do a check on the root hash.
113
+ * @returns True if the transaction trie is valid, false otherwise
114
+ */
115
+ async transactionsTrieIsValid() {
116
+ let result;
117
+ if (this.transactions.length === 0) {
118
+ result = (0, util_1.equalsBytes)(this.header.transactionsTrie, util_1.KECCAK256_RLP);
119
+ return result;
120
+ }
121
+ if (this.cache.txTrieRoot === undefined) {
122
+ this.cache.txTrieRoot = await this.genTxTrie();
123
+ }
124
+ result = (0, util_1.equalsBytes)(this.cache.txTrieRoot, this.header.transactionsTrie);
125
+ return result;
126
+ }
127
+ /**
128
+ * Validates transaction signatures and minimum gas requirements.
129
+ * @returns {string[]} an array of error strings
130
+ */
131
+ getTransactionsValidationErrors() {
132
+ const errors = [];
133
+ let blobGasUsed = util_1.BIGINT_0;
134
+ // eslint-disable-next-line prefer-const
135
+ for (let [i, tx] of this.transactions.entries()) {
136
+ const errs = tx.getValidationErrors();
137
+ if (this.common.isActivatedEIP(1559)) {
138
+ if (tx.supports(tx_1.Capability.EIP1559FeeMarket)) {
139
+ tx = tx;
140
+ if (tx.maxFeePerGas < this.header.baseFeePerGas) {
141
+ errs.push('tx unable to pay base fee (EIP-1559 tx)');
142
+ }
143
+ }
144
+ else {
145
+ tx = tx;
146
+ if (tx.gasPrice < this.header.baseFeePerGas) {
147
+ errs.push('tx unable to pay base fee (non EIP-1559 tx)');
148
+ }
149
+ }
150
+ }
151
+ if (this.common.isActivatedEIP(4844)) {
152
+ const blobGasLimit = this.common.getBlobGasSchedule().maxBlobGasPerBlock;
153
+ const blobGasPerBlob = this.common.param('blobGasPerBlob');
154
+ if (tx instanceof tx_1.Blob4844Tx) {
155
+ blobGasUsed += BigInt(tx.numBlobs()) * blobGasPerBlob;
156
+ if (blobGasUsed > blobGasLimit) {
157
+ errs.push(`tx causes total blob gas of ${blobGasUsed} to exceed maximum blob gas per block of ${blobGasLimit}`);
158
+ }
159
+ }
160
+ }
161
+ if (errs.length > 0) {
162
+ errors.push(`errors at tx ${i}: ${errs.join(', ')}`);
163
+ }
164
+ }
165
+ if (this.common.isActivatedEIP(4844)) {
166
+ if (blobGasUsed !== this.header.blobGasUsed) {
167
+ errors.push(`invalid blobGasUsed expected=${this.header.blobGasUsed} actual=${blobGasUsed}`);
168
+ }
169
+ }
170
+ return errors;
171
+ }
172
+ /**
173
+ * Validates transaction signatures and minimum gas requirements.
174
+ * @returns True if all transactions are valid, false otherwise
175
+ */
176
+ transactionsAreValid() {
177
+ const errors = this.getTransactionsValidationErrors();
178
+ return errors.length === 0;
179
+ }
180
+ /**
181
+ * Validates the block data, throwing if invalid.
182
+ * This can be checked on the Block itself without needing access to any parent block
183
+ * It checks:
184
+ * - All transactions are valid
185
+ * - The transactions trie is valid
186
+ * - The uncle hash is valid
187
+ * - Block size limit (EIP-7934)
188
+ * @param onlyHeader if only passed the header, skip validating txTrie and unclesHash (default: false)
189
+ * @param verifyTxs if set to `false`, will not check for transaction validation errors (default: true)
190
+ * @param validateBlockSize if set to `true`, will check for block size limit (EIP-7934) (default: false)
191
+ */
192
+ async validateData(onlyHeader = false, verifyTxs = true, validateBlockSize = false) {
193
+ // EIP-7934: RLP Execution Block Size Limit validation
194
+ if (validateBlockSize && this.common.isActivatedEIP(7934)) {
195
+ const rlpEncoded = this.serialize();
196
+ const maxRlpBlockSize = this.common.param('maxRlpBlockSize');
197
+ if (rlpEncoded.length > maxRlpBlockSize) {
198
+ const msg = this._errorMsg(`Block size exceeds maximum RLP block size limit: ${rlpEncoded.length} bytes > ${maxRlpBlockSize} bytes`);
199
+ throw (0, util_1.EthereumJSErrorWithoutCode)(msg);
200
+ }
201
+ }
202
+ if (verifyTxs) {
203
+ const txErrors = this.getTransactionsValidationErrors();
204
+ if (txErrors.length > 0) {
205
+ const msg = this._errorMsg(`invalid transactions: ${txErrors.join(' ')}`);
206
+ throw (0, util_1.EthereumJSErrorWithoutCode)(msg);
207
+ }
208
+ }
209
+ if (onlyHeader) {
210
+ return;
211
+ }
212
+ if (verifyTxs) {
213
+ for (const [index, tx] of this.transactions.entries()) {
214
+ if (!tx.isSigned()) {
215
+ const msg = this._errorMsg(`invalid transactions: transaction at index ${index} is unsigned`);
216
+ throw (0, util_1.EthereumJSErrorWithoutCode)(msg);
217
+ }
218
+ }
219
+ }
220
+ if (!(await this.transactionsTrieIsValid())) {
221
+ const msg = this._errorMsg('invalid transaction trie');
222
+ throw (0, util_1.EthereumJSErrorWithoutCode)(msg);
223
+ }
224
+ if (!this.uncleHashIsValid()) {
225
+ const msg = this._errorMsg('invalid uncle hash');
226
+ throw (0, util_1.EthereumJSErrorWithoutCode)(msg);
227
+ }
228
+ if (this.common.isActivatedEIP(4895) && !(await this.withdrawalsTrieIsValid())) {
229
+ const msg = this._errorMsg('invalid withdrawals trie');
230
+ throw (0, util_1.EthereumJSErrorWithoutCode)(msg);
231
+ }
232
+ }
233
+ /**
234
+ * Validates that blob gas fee for each transaction is greater than or equal to the
235
+ * blobGasPrice for the block and that total blob gas in block is less than maximum
236
+ * blob gas per block
237
+ * @param parentHeader header of parent block
238
+ */
239
+ validateBlobTransactions(parentHeader) {
240
+ if (this.common.isActivatedEIP(4844)) {
241
+ const blobGasLimit = this.common.getBlobGasSchedule().maxBlobGasPerBlock;
242
+ const blobGasPerBlob = this.common.param('blobGasPerBlob');
243
+ let blobGasUsed = util_1.BIGINT_0;
244
+ const expectedExcessBlobGas = parentHeader.calcNextExcessBlobGas(this.common);
245
+ if (this.header.excessBlobGas !== expectedExcessBlobGas) {
246
+ throw (0, util_1.EthereumJSErrorWithoutCode)(`block excessBlobGas mismatch: have ${this.header.excessBlobGas}, want ${expectedExcessBlobGas}`);
247
+ }
248
+ let blobGasPrice;
249
+ for (const tx of this.transactions) {
250
+ if (tx instanceof tx_1.Blob4844Tx) {
251
+ blobGasPrice = blobGasPrice ?? this.header.getBlobGasPrice();
252
+ if (tx.maxFeePerBlobGas < blobGasPrice) {
253
+ throw (0, util_1.EthereumJSErrorWithoutCode)(`blob transaction maxFeePerBlobGas ${tx.maxFeePerBlobGas} < than block blob gas price ${blobGasPrice} - ${this.errorStr()}`);
254
+ }
255
+ blobGasUsed += BigInt(tx.blobVersionedHashes.length) * blobGasPerBlob;
256
+ if (blobGasUsed > blobGasLimit) {
257
+ throw (0, util_1.EthereumJSErrorWithoutCode)(`tx causes total blob gas of ${blobGasUsed} to exceed maximum blob gas per block of ${blobGasLimit}`);
258
+ }
259
+ }
260
+ }
261
+ if (this.header.blobGasUsed !== blobGasUsed) {
262
+ throw (0, util_1.EthereumJSErrorWithoutCode)(`block blobGasUsed mismatch: have ${this.header.blobGasUsed}, want ${blobGasUsed}`);
263
+ }
264
+ }
265
+ }
266
+ /**
267
+ * Validates the uncle's hash.
268
+ * @returns true if the uncle's hash is valid, false otherwise.
269
+ */
270
+ uncleHashIsValid() {
271
+ if (this.uncleHeaders.length === 0) {
272
+ return (0, util_1.equalsBytes)(util_1.KECCAK256_RLP_ARRAY, this.header.uncleHash);
273
+ }
274
+ const uncles = this.uncleHeaders.map((uh) => uh.raw());
275
+ const raw = rlp_1.RLP.encode(uncles);
276
+ return (0, util_1.equalsBytes)(this.keccakFunction(raw), this.header.uncleHash);
277
+ }
278
+ /**
279
+ * Validates the withdrawal root
280
+ * @returns true if the withdrawals trie root is valid, false otherwise
281
+ */
282
+ async withdrawalsTrieIsValid() {
283
+ if (!this.common.isActivatedEIP(4895)) {
284
+ throw (0, util_1.EthereumJSErrorWithoutCode)('EIP 4895 is not activated');
285
+ }
286
+ let result;
287
+ if (this.withdrawals.length === 0) {
288
+ result = (0, util_1.equalsBytes)(this.header.withdrawalsRoot, util_1.KECCAK256_RLP);
289
+ return result;
290
+ }
291
+ if (this.cache.withdrawalsTrieRoot === undefined) {
292
+ this.cache.withdrawalsTrieRoot = await (0, index_ts_1.genWithdrawalsTrieRoot)(this.withdrawals, new mpt_1.MerklePatriciaTrie({ common: this.common }));
293
+ }
294
+ result = (0, util_1.equalsBytes)(this.cache.withdrawalsTrieRoot, this.header.withdrawalsRoot);
295
+ return result;
296
+ }
297
+ /**
298
+ * Consistency checks for uncles included in the block, if any.
299
+ *
300
+ * Throws if invalid.
301
+ *
302
+ * The rules for uncles checked are the following:
303
+ * Header has at most 2 uncles.
304
+ * Header does not count an uncle twice.
305
+ */
306
+ validateUncles() {
307
+ if (this.isGenesis()) {
308
+ return;
309
+ }
310
+ // Header has at most 2 uncles
311
+ if (this.uncleHeaders.length > 2) {
312
+ const msg = this._errorMsg('too many uncle headers');
313
+ throw (0, util_1.EthereumJSErrorWithoutCode)(msg);
314
+ }
315
+ // Header does not count an uncle twice.
316
+ const uncleHashes = this.uncleHeaders.map((header) => (0, util_1.bytesToHex)(header.hash()));
317
+ if (!(new Set(uncleHashes).size === uncleHashes.length)) {
318
+ const msg = this._errorMsg('duplicate uncles');
319
+ throw (0, util_1.EthereumJSErrorWithoutCode)(msg);
320
+ }
321
+ }
322
+ /**
323
+ * Validates if the block gasLimit remains in the boundaries set by the protocol.
324
+ * Throws if invalid
325
+ *
326
+ * @param parentBlock - the parent of this `Block`
327
+ */
328
+ validateGasLimit(parentBlock) {
329
+ return this.header.validateGasLimit(parentBlock.header);
330
+ }
331
+ /**
332
+ * Returns the block in JSON format.
333
+ */
334
+ toJSON() {
335
+ const withdrawalsAttr = this.withdrawals
336
+ ? {
337
+ withdrawals: this.withdrawals.map((wt) => wt.toJSON()),
338
+ }
339
+ : {};
340
+ return {
341
+ header: this.header.toJSON(),
342
+ transactions: this.transactions.map((tx) => tx.toJSON()),
343
+ uncleHeaders: this.uncleHeaders.map((uh) => uh.toJSON()),
344
+ ...withdrawalsAttr,
345
+ };
346
+ }
347
+ /**
348
+ * Maps the block properties to the execution payload structure from the beacon chain,
349
+ * see https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#ExecutionPayload
350
+ *
351
+ * @returns dict with the execution payload parameters with camel case naming
352
+ */
353
+ toExecutionPayload() {
354
+ const blockJSON = this.toJSON();
355
+ const header = blockJSON.header;
356
+ const transactions = this.transactions.map((tx) => (0, util_1.bytesToHex)(tx.serialize())) ?? [];
357
+ const withdrawalsArr = blockJSON.withdrawals ? { withdrawals: blockJSON.withdrawals } : {};
358
+ const executionPayload = {
359
+ blockNumber: header.number,
360
+ parentHash: header.parentHash,
361
+ feeRecipient: header.coinbase,
362
+ stateRoot: header.stateRoot,
363
+ receiptsRoot: header.receiptTrie,
364
+ logsBloom: header.logsBloom,
365
+ gasLimit: header.gasLimit,
366
+ gasUsed: header.gasUsed,
367
+ timestamp: header.timestamp,
368
+ extraData: header.extraData,
369
+ baseFeePerGas: header.baseFeePerGas,
370
+ blobGasUsed: header.blobGasUsed,
371
+ excessBlobGas: header.excessBlobGas,
372
+ blockHash: (0, util_1.bytesToHex)(this.hash()),
373
+ prevRandao: header.mixHash,
374
+ transactions,
375
+ ...withdrawalsArr,
376
+ parentBeaconBlockRoot: header.parentBeaconBlockRoot,
377
+ requestsHash: header.requestsHash,
378
+ };
379
+ return executionPayload;
380
+ }
381
+ /**
382
+ * Return a compact error string representation of the object
383
+ */
384
+ errorStr() {
385
+ let hash = '';
386
+ try {
387
+ hash = (0, util_1.bytesToHex)(this.hash());
388
+ }
389
+ catch {
390
+ hash = 'error';
391
+ }
392
+ let hf = '';
393
+ try {
394
+ hf = this.common.hardfork();
395
+ }
396
+ catch {
397
+ hf = 'error';
398
+ }
399
+ let errorStr = `block number=${this.header.number} hash=${hash} `;
400
+ errorStr += `hf=${hf} baseFeePerGas=${this.header.baseFeePerGas ?? 'none'} `;
401
+ errorStr += `txs=${this.transactions.length} uncles=${this.uncleHeaders.length}`;
402
+ return errorStr;
403
+ }
404
+ /**
405
+ * Internal helper function to create an annotated error message
406
+ *
407
+ * @param msg Base error message
408
+ * @hidden
409
+ */
410
+ _errorMsg(msg) {
411
+ return `${msg} (${this.errorStr()})`;
412
+ }
413
+ }
414
+ exports.Block = Block;
415
+ //# sourceMappingURL=block.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block.js","sourceRoot":"","sources":["../../../src/block/block.ts"],"names":[],"mappings":";;;AAAA,+CAAkD;AAClD,yCAAoD;AACpD,yCAAqC;AACrC,uCAAuD;AACvD,2CAOyB;AACzB,mDAA8C;AAC9C,mDAAkD;AAKlD,oBAAoB;AACpB,4FAA4F;AAC5F,6FAA6F;AAC7F,kEAAkE;AAClE,4DAA4D;AAC5D,yEAAyE;AACzE,0CAWoB;AAIpB;;;;;;;;;;;;;;;GAeG;AACH,MAAa,KAAK;IAchB;;;;;OAKG;IACH,YACE,MAAoB,EACpB,eAAmC,EAAE,EACrC,eAA8B,EAAE,EAChC,WAA0B,EAC1B,OAAqB,EAAE;QAvBT,iBAAY,GAAuB,EAAE,CAAA;QACrC,iBAAY,GAAkB,EAAE,CAAA;QAMtC,UAAK,GAGX,EAAE,CAAA;QAeJ,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,sBAAW,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;QACjD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CA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BAAgB,CAAA;IACzB,CAAC;IAED;;OAEG;IACI,QAAQ;QACb,IAAI,IAAI,GAAG,EAAE,CAAA;QACb,IAAI,CAAC;YACH,IAAI,GAAG,IAAA,iBAAU,EAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;QAChC,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,GAAG,OAAO,CAAA;QAChB,CAAC;QACD,IAAI,EAAE,GAAG,EAAE,CAAA;QACX,IAAI,CAAC;YACH,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAA;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,EAAE,GAAG,OAAO,CAAA;QACd,CAAC;QACD,IAAI,QAAQ,GAAG,gBAAgB,IAAI,CAAC,MAAM,CAAC,MAAM,SAAS,IAAI,GAAG,CAAA;QACjE,QAAQ,IAAI,MAAM,EAAE,kBAAkB,IAAI,CAAC,MAAM,CAAC,aAAa,IAAI,MAAM,GAAG,CAAA;QAC5E,QAAQ,IAAI,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,WAAW,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAA;QAChF,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED;;;;;OAKG;IACO,SAAS,CAAC,GAAW;QAC7B,OAAO,GAAG,GAAG,KAAK,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAA;IACtC,CAAC;CACF;AAtdD,sBAsdC"}
@@ -0,0 +1,77 @@
1
+ import { Block } from '../index.ts';
2
+ import type { EthersProvider } from '@feelyourprotocol/util';
3
+ import type { BeaconPayloadJSON } from '../from-beacon-payload.ts';
4
+ import type { BlockBytes, BlockData, BlockOptions, ExecutionPayload, HeaderData, JSONRPCBlock } from '../types.ts';
5
+ /**
6
+ * Static constructor to create a block from a block data dictionary
7
+ *
8
+ * @param blockData
9
+ * @param opts
10
+ * @returns a new {@link Block} object
11
+ */
12
+ export declare function createBlock(blockData?: BlockData, opts?: BlockOptions): Block;
13
+ /**
14
+ * Simple static constructor if only an empty block is needed
15
+ * (tree shaking advantages since it does not draw all the tx constructors in)
16
+ *
17
+ * @param headerData
18
+ * @param opts
19
+ * @returns a new {@link Block} object
20
+ */
21
+ export declare function createEmptyBlock(headerData: HeaderData, opts?: BlockOptions): Block;
22
+ /**
23
+ * Static constructor to create a block from an array of Bytes values
24
+ *
25
+ * @param values
26
+ * @param opts
27
+ * @returns a new {@link Block} object
28
+ */
29
+ export declare function createBlockFromBytesArray(values: BlockBytes, opts?: BlockOptions): Block;
30
+ /**
31
+ * Static constructor to create a block from a RLP-serialized block
32
+ *
33
+ * @param serialized
34
+ * @param opts
35
+ * @returns a new {@link Block} object
36
+ */
37
+ export declare function createBlockFromRLP(serialized: Uint8Array, opts?: BlockOptions): Block;
38
+ /**
39
+ * Creates a new block object from Ethereum JSON RPC.
40
+ *
41
+ * @param blockParams - Ethereum JSON RPC of block (eth_getBlockByNumber)
42
+ * @param uncles - Optional list of Ethereum JSON RPC of uncles (eth_getUncleByBlockHashAndIndex)
43
+ * @param opts - An object describing the blockchain
44
+ * @returns a new {@link Block} object
45
+ */
46
+ export declare function createBlockFromRPC(blockParams: JSONRPCBlock, uncles?: any[], options?: BlockOptions): Block;
47
+ /**
48
+ * Method to retrieve a block from a JSON-RPC provider and format as a {@link Block}
49
+ * @param provider either a url for a remote provider or an Ethers JSONRPCProvider object
50
+ * @param blockTag block hash or block number to be run
51
+ * @param opts {@link BlockOptions}
52
+ * @returns a new {@link Block} object specified by `blockTag`
53
+ */
54
+ export declare const createBlockFromJSONRPCProvider: (provider: string | EthersProvider, blockTag: string | bigint, opts: BlockOptions) => Promise<Block>;
55
+ /**
56
+ * Method to retrieve a block from an execution payload
57
+ * @param payload Execution payload constructed from beacon payload data
58
+ * @param opts {@link BlockOptions}
59
+ * @returns The constructed {@link Block} object
60
+ */
61
+ export declare function createBlockFromExecutionPayload(payload: ExecutionPayload, opts?: BlockOptions): Promise<Block>;
62
+ /**
63
+ * Method to retrieve a block from a beacon payload JSON
64
+ * @param payload JSON of a beacon block fetched from beacon APIs
65
+ * @param opts {@link BlockOptions}
66
+ * @returns The constructed {@link Block} object
67
+ */
68
+ export declare function createBlockFromBeaconPayloadJSON(payload: BeaconPayloadJSON, opts?: BlockOptions): Promise<Block>;
69
+ /**
70
+ * Creates a block for Clique networks with the seal applied during instantiation.
71
+ * @param blockData Block fields used to build the block
72
+ * @param cliqueSigner Private key bytes used to sign the header
73
+ * @param opts {@link BlockOptions}
74
+ * @returns A sealed Clique {@link Block} object
75
+ */
76
+ export declare function createSealedCliqueBlock(blockData: BlockData | undefined, cliqueSigner: Uint8Array, opts?: BlockOptions): Block;
77
+ //# sourceMappingURL=constructors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constructors.d.ts","sourceRoot":"","sources":["../../../src/block/constructors.ts"],"names":[],"mappings":"AAwBA,OAAO,EACL,KAAK,EAKN,MAAM,aAAa,CAAA;AAEpB,OAAO,KAAK,EAAE,cAAc,EAAmB,MAAM,kBAAkB,CAAA;AACvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAClE,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,YAAY,EAEb,MAAM,aAAa,CAAA;AAEpB;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,SAAS,GAAE,SAAc,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,KAAK,CA0CjF;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,KAAK,CAGnF;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,KAAK,CAiExF;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,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