@ethereumjs/common
Advanced tools
Comparing version 3.0.0-beta.1 to 3.0.0-beta.2
@@ -76,4 +76,11 @@ { | ||
{ | ||
"//_comment": "The forkHash will remain same as mergeForkIdTransition is post merge", | ||
"name": "merge", | ||
"td": 50000000000000000, | ||
"block": null, | ||
"forkHash": "0x7119b6b3" | ||
}, | ||
{ | ||
"name": "mergeForkIdTransition", | ||
"block": null, | ||
"forkHash": null | ||
@@ -80,0 +87,0 @@ }, |
@@ -77,4 +77,11 @@ { | ||
{ | ||
"//_comment": "The forkHash will remain same as mergeForkIdTransition is post merge", | ||
"name": "merge", | ||
"td": 17000000000000000, | ||
"block": null, | ||
"forkHash": "0xfe3366e7" | ||
}, | ||
{ | ||
"name": "mergeForkIdTransition", | ||
"block": null, | ||
"forkHash": null | ||
@@ -102,5 +109,21 @@ }, | ||
"comment": "besu" | ||
}, | ||
{ | ||
"ip": "165.22.196.173", | ||
"port": 30303, | ||
"id": "ce970ad2e9daa9e14593de84a8b49da3d54ccfdf83cbc4fe519cb8b36b5918ed4eab087dedd4a62479b8d50756b492d5f762367c8d20329a7854ec01547568a6", | ||
"location": "", | ||
"comment": "EF" | ||
}, | ||
{ | ||
"ip": "65.108.95.67", | ||
"port": 30303, | ||
"id": "075503b13ed736244896efcde2a992ec0b451357d46cb7a8132c0384721742597fc8f0d91bbb40bb52e7d6e66728d36a1fda09176294e4a30cfac55dcce26bc6", | ||
"location": "", | ||
"comment": "lodestar" | ||
} | ||
], | ||
"dnsNetworks": [] | ||
"dnsNetworks": [ | ||
"enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@all.sepolia.ethdisco.net" | ||
] | ||
} |
@@ -32,3 +32,3 @@ "use strict"; | ||
this._hardfork = this.DEFAULT_HARDFORK; | ||
if (opts.hardfork) { | ||
if ((0, util_1.isTruthy)(opts.hardfork)) { | ||
this.setHardfork(opts.hardfork); | ||
@@ -146,3 +146,3 @@ } | ||
} | ||
if (initializedChains[chain]) { | ||
if ((0, util_1.isTruthy)(initializedChains[chain])) { | ||
return initializedChains[chain]; | ||
@@ -230,3 +230,3 @@ } | ||
} | ||
if (td && hf.td) { | ||
if (td && (0, util_1.isTruthy)(hf.td)) { | ||
if (td >= BigInt(hf.td)) { | ||
@@ -243,3 +243,3 @@ minTdHF = hf.name; | ||
let msgAdd = `block number: ${blockNumber} (-> ${hardfork}), `; | ||
if (minTdHF) { | ||
if ((0, util_1.isTruthy)(minTdHF)) { | ||
if (!this.hardforkGteHardfork(hardfork, minTdHF)) { | ||
@@ -251,3 +251,3 @@ const msg = 'HF determined by block number is lower than the minimum total difficulty HF'; | ||
} | ||
if (maxTdHF) { | ||
if ((0, util_1.isTruthy)(maxTdHF)) { | ||
if (!this.hardforkGteHardfork(maxTdHF, hardfork)) { | ||
@@ -305,3 +305,3 @@ const msg = 'Maximum HF determined by total difficulty is lower than the block number HF'; | ||
} | ||
if (eips_1.EIPs[eip].requiredEIPs) { | ||
if ((0, util_1.isTruthy)(eips_1.EIPs[eip].requiredEIPs)) { | ||
; | ||
@@ -356,6 +356,6 @@ eips_1.EIPs[eip].requiredEIPs.forEach((elem) => { | ||
} | ||
// Paramater-inlining HF file (e.g. istanbul.json) | ||
// Parameter-inlining HF file (e.g. istanbul.json) | ||
} | ||
else { | ||
if (!hfChanges[1][topic]) { | ||
if ((0, util_1.isFalsy)(hfChanges[1][topic])) { | ||
throw new Error(`Topic ${topic} not defined`); | ||
@@ -370,5 +370,3 @@ } | ||
} | ||
if (!value) | ||
return BigInt(0); | ||
return BigInt(value); | ||
return BigInt(value ?? 0); | ||
} | ||
@@ -442,3 +440,3 @@ /** | ||
const hfBlock = this.hardforkBlock(hardfork); | ||
if (hfBlock && blockNumber >= hfBlock) { | ||
if ((0, util_1.isTruthy)(hfBlock) && blockNumber >= hfBlock) { | ||
return true; | ||
@@ -521,3 +519,3 @@ } | ||
const block = this.hardforkBlock(hardfork); | ||
return block ? block === blockNumber : false; | ||
return (0, util_1.isTruthy)(block) ? block === blockNumber : false; | ||
} | ||
@@ -695,6 +693,3 @@ /** | ||
} | ||
if (value) { | ||
return value; | ||
} | ||
return this._chainParams['consensus']['type']; | ||
return value ?? this._chainParams['consensus']['type']; | ||
} | ||
@@ -720,6 +715,5 @@ /** | ||
} | ||
if (value) { | ||
return value; | ||
} | ||
return this._chainParams['consensus']['algorithm']; | ||
return (0, util_1.isTruthy)(value) | ||
? value | ||
: this._chainParams['consensus']['algorithm']; | ||
} | ||
@@ -751,7 +745,5 @@ /** | ||
} | ||
if (value) { | ||
return value; | ||
} | ||
const consensusAlgorithm = this.consensusAlgorithm(); | ||
return this._chainParams['consensus'][consensusAlgorithm]; | ||
return (0, util_1.isTruthy)(value) | ||
? value | ||
: this._chainParams['consensus'][this.consensusAlgorithm()]; | ||
} | ||
@@ -758,0 +750,0 @@ /** |
@@ -1,4 +0,4 @@ | ||
export { Common as default } from './common'; | ||
export * from './common'; | ||
export * from './enums'; | ||
export * from './types'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -17,7 +17,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = void 0; | ||
var common_1 = require("./common"); | ||
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return common_1.Common; } }); | ||
__exportStar(require("./common"), exports); | ||
__exportStar(require("./enums"), exports); | ||
__exportStar(require("./types"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@ethereumjs/common", | ||
"version": "3.0.0-beta.1", | ||
"version": "3.0.0-beta.2", | ||
"description": "Resources common to all Ethereum implementations", | ||
@@ -37,3 +37,3 @@ "license": "MIT", | ||
"crc-32": "^1.2.0", | ||
"@ethereumjs/util": "8.0.0-beta.1" | ||
"@ethereumjs/util": "8.0.0-beta.2" | ||
}, | ||
@@ -40,0 +40,0 @@ "devDependencies": { |
@@ -22,21 +22,20 @@ # @ethereumjs/common | ||
import (CommonJS, TypeScript with `esModuleInterop` enabled): | ||
import (ESM, TypeScript): | ||
`import Common from '@ethereumjs/common`\ | ||
`import Common, { Chain, Hardfork } from '@ethereumjs/common` | ||
`import { Chain, Common, Hardfork } from '@ethereumjs/common` | ||
require (ES Modules, Node.js): | ||
require (CommonJS, Node.js): | ||
`const Common = require('@ethereumjs/common').default`\ | ||
`const { default: Common, Chain, Hardfork } = require('@ethereumjs/common')` | ||
`const { Common, Chain, Hardfork } = require('@ethereumjs/common')` | ||
## Parameters | ||
All parameters can be accessed through the `Common` class, instantiated with an object containing either the `chain` (e.g. 'mainnet') or the `chain` together with a specific `hardfork` provided: | ||
All parameters can be accessed through the `Common` class, instantiated with an object containing either the `chain` (e.g. 'Chain.Mainnet') or the `chain` together with a specific `hardfork` provided: | ||
```typescript | ||
// With strings: | ||
const common = new Common({ chain: 'mainnet', hardfork: 'london' }) | ||
// With enums: | ||
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) | ||
// (also possible with directly passing in strings:) | ||
const common = new Common({ chain: 'mainnet', hardfork: 'london' }) | ||
``` | ||
@@ -46,3 +45,3 @@ | ||
Current `DEFAULT_HARDFORK`: `london` | ||
Current `DEFAULT_HARDFORK`: `Hardfork.London` | ||
@@ -53,7 +52,7 @@ Here are some simple usage examples: | ||
// Instantiate with the chain (and the default hardfork) | ||
let c = new Common({ chain: 'ropsten' }) | ||
let c = new Common({ chain: Chain.Ropsten }) | ||
c.param('gasPrices', 'ecAddGas') // 500 | ||
// Chain and hardfork provided | ||
c = new Common({ chain: 'ropsten', hardfork: 'byzantium' }) | ||
c = new Common({ chain: Chain.Ropsten, hardfork: Hardfork.Byzantium }) | ||
c.param('pow', 'minerReward') // 3000000000000000000 | ||
@@ -65,19 +64,9 @@ | ||
// Instantiate with an EIP activated | ||
c = new Common({ chain: 'mainnet', eips: [2537] }) | ||
c = new Common({ chain: Chain.Mainnet, eips: [2537] }) | ||
``` | ||
For an improved developer experience, there are `Chain` and `Hardfork` enums available: | ||
# API | ||
```typescript | ||
import Common, { Chain, Hardfork } from '@ethereumjs/common' | ||
## Docs | ||
// Chain provided by Chain enum | ||
const c = new Common({ chain: Chain.Mainnet }) | ||
// Chain provided by Chain enum, hardfork provided by Hardfork enum | ||
const c = new Common({ chain: Chain.Ropsten, hardfork: Hardfork.Byzantium }) | ||
``` | ||
# API | ||
See the API documentation for a full list of functions for accessing specific chain and | ||
@@ -88,4 +77,10 @@ depending hardfork parameters. There are also additional helper functions like | ||
- [API Docs](./docs/README.md) | ||
Generated TypeDoc API [Documentation](./docs/README.md) | ||
## BigInt Support | ||
Starting with v4 the usage of [BN.js](https://github.com/indutny/bn.js/) for big numbers has been removed from the library and replaced with the usage of the native JS [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) data type (introduced in `ES2020`). | ||
Please note that number-related API signatures have changed along with this version update and the minimal build target has been updated to `ES2020`. | ||
# EVENTS | ||
@@ -107,10 +102,2 @@ | ||
```typescript | ||
const c = new Common({ chain: 'ropsten' }) | ||
``` | ||
Or optionally with the `Chain` enum: | ||
```typescript | ||
import Common, { Chain } from '@ethereumjs/common' | ||
const c = new Common({ chain: Chain.Ropsten }) | ||
@@ -208,3 +195,3 @@ ``` | ||
Custom genesis states should be passed to the `@ethereumjs/blockchain` directly. | ||
Starting with v3 custom genesis states should be passed to the [Blockchain](../blockchain/) library directly. | ||
@@ -216,14 +203,5 @@ ## Hardforks | ||
```typescript | ||
const c = new Common({ chain: 'ropsten', hardfork: 'byzantium' }) | ||
``` | ||
import { Chain, Common, Hardfork } from '@ethereumjs/common' | ||
Or optionally with the `Hardfork` enum: | ||
```typescript | ||
import Common, { Chain, Hardfork } from '@ethereumjs/common' | ||
const c = new Common({ | ||
chain: Chain.Ropsten, | ||
hardfork: Hardfork.Byzantium, | ||
}) | ||
const c = new Common({ chain: Chain.Ropsten, hardfork: Hardfork.Byzantium }) | ||
``` | ||
@@ -248,7 +226,7 @@ | ||
- `london` (`Hardfork.London`) (`DEFAULT_HARDFORK`) (since `v2.4.0`) | ||
- `merge` (`Hardfork.Merge`) (since `v2.5.0`, `experimental`) | ||
- `merge` (`Hardfork.Merge`) (since `v2.5.0`) | ||
### Future Hardforks | ||
The next upcoming HF `shanghai` is currently not yet supported by this library. | ||
The next upcoming HF `Hardfork.Shanghai` is currently not yet supported by this library. | ||
@@ -255,0 +233,0 @@ ### Parameter Access |
@@ -76,4 +76,11 @@ { | ||
{ | ||
"//_comment": "The forkHash will remain same as mergeForkIdTransition is post merge", | ||
"name": "merge", | ||
"td": 50000000000000000, | ||
"block": null, | ||
"forkHash": "0x7119b6b3" | ||
}, | ||
{ | ||
"name": "mergeForkIdTransition", | ||
"block": null, | ||
"forkHash": null | ||
@@ -80,0 +87,0 @@ }, |
@@ -77,4 +77,11 @@ { | ||
{ | ||
"//_comment": "The forkHash will remain same as mergeForkIdTransition is post merge", | ||
"name": "merge", | ||
"td": 17000000000000000, | ||
"block": null, | ||
"forkHash": "0xfe3366e7" | ||
}, | ||
{ | ||
"name": "mergeForkIdTransition", | ||
"block": null, | ||
"forkHash": null | ||
@@ -102,5 +109,21 @@ }, | ||
"comment": "besu" | ||
}, | ||
{ | ||
"ip": "165.22.196.173", | ||
"port": 30303, | ||
"id": "ce970ad2e9daa9e14593de84a8b49da3d54ccfdf83cbc4fe519cb8b36b5918ed4eab087dedd4a62479b8d50756b492d5f762367c8d20329a7854ec01547568a6", | ||
"location": "", | ||
"comment": "EF" | ||
}, | ||
{ | ||
"ip": "65.108.95.67", | ||
"port": 30303, | ||
"id": "075503b13ed736244896efcde2a992ec0b451357d46cb7a8132c0384721742597fc8f0d91bbb40bb52e7d6e66728d36a1fda09176294e4a30cfac55dcce26bc6", | ||
"location": "", | ||
"comment": "lodestar" | ||
} | ||
], | ||
"dnsNetworks": [] | ||
"dnsNetworks": [ | ||
"enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@all.sepolia.ethdisco.net" | ||
] | ||
} |
import { EventEmitter } from 'events' | ||
import { buf as crc32Buffer } from 'crc-32' | ||
import { BigIntLike, toType, TypeOutput, intToBuffer } from '@ethereumjs/util' | ||
import { BigIntLike, toType, TypeOutput, intToBuffer, isTruthy, isFalsy } from '@ethereumjs/util' | ||
import { hardforks as HARDFORK_CHANGES } from './hardforks' | ||
@@ -178,3 +178,3 @@ import { EIPs } from './eips' | ||
if (initializedChains[chain]) { | ||
if (isTruthy(initializedChains[chain])) { | ||
return initializedChains[chain] as ChainConfig | ||
@@ -192,3 +192,3 @@ } | ||
this._hardfork = this.DEFAULT_HARDFORK | ||
if (opts.hardfork) { | ||
if (isTruthy(opts.hardfork)) { | ||
this.setHardfork(opts.hardfork) | ||
@@ -282,3 +282,3 @@ } | ||
} | ||
if (td && hf.td) { | ||
if (td && isTruthy(hf.td)) { | ||
if (td >= BigInt(hf.td)) { | ||
@@ -294,3 +294,3 @@ minTdHF = hf.name | ||
let msgAdd = `block number: ${blockNumber} (-> ${hardfork}), ` | ||
if (minTdHF) { | ||
if (isTruthy(minTdHF)) { | ||
if (!this.hardforkGteHardfork(hardfork, minTdHF)) { | ||
@@ -302,3 +302,3 @@ const msg = 'HF determined by block number is lower than the minimum total difficulty HF' | ||
} | ||
if (maxTdHF) { | ||
if (isTruthy(maxTdHF)) { | ||
if (!this.hardforkGteHardfork(maxTdHF, hardfork)) { | ||
@@ -360,3 +360,3 @@ const msg = 'Maximum HF determined by total difficulty is lower than the block number HF' | ||
} | ||
if (EIPs[eip].requiredEIPs) { | ||
if (isTruthy(EIPs[eip].requiredEIPs)) { | ||
;(EIPs[eip].requiredEIPs as number[]).forEach((elem) => { | ||
@@ -411,5 +411,5 @@ if (!(eips.includes(elem) || this.isActivatedEIP(elem))) { | ||
} | ||
// Paramater-inlining HF file (e.g. istanbul.json) | ||
// Parameter-inlining HF file (e.g. istanbul.json) | ||
} else { | ||
if (!hfChanges[1][topic]) { | ||
if (isFalsy(hfChanges[1][topic])) { | ||
throw new Error(`Topic ${topic} not defined`) | ||
@@ -423,4 +423,3 @@ } | ||
} | ||
if (!value) return BigInt(0) | ||
return BigInt(value) | ||
return BigInt(value ?? 0) | ||
} | ||
@@ -481,3 +480,3 @@ | ||
if (this.gteHardfork(hf['name']) && 'eips' in hf) { | ||
if (hf['eips'].includes(eip)) { | ||
if ((hf['eips'] as number[]).includes(eip)) { | ||
return true | ||
@@ -500,3 +499,3 @@ } | ||
const hfBlock = this.hardforkBlock(hardfork) | ||
if (hfBlock && blockNumber >= hfBlock) { | ||
if (isTruthy(hfBlock) && blockNumber >= hfBlock) { | ||
return true | ||
@@ -585,3 +584,3 @@ } | ||
const block = this.hardforkBlock(hardfork) | ||
return block ? block === blockNumber : false | ||
return isTruthy(block) ? block === blockNumber : false | ||
} | ||
@@ -776,6 +775,3 @@ | ||
} | ||
if (value) { | ||
return value | ||
} | ||
return this._chainParams['consensus']!['type'] | ||
return value ?? this._chainParams['consensus']['type'] | ||
} | ||
@@ -802,6 +798,5 @@ | ||
} | ||
if (value) { | ||
return value | ||
} | ||
return this._chainParams['consensus']!['algorithm'] as ConsensusAlgorithm | ||
return isTruthy(value) | ||
? value | ||
: (this._chainParams['consensus']['algorithm'] as ConsensusAlgorithm) | ||
} | ||
@@ -834,7 +829,5 @@ | ||
} | ||
if (value) { | ||
return value | ||
} | ||
const consensusAlgorithm = this.consensusAlgorithm() | ||
return this._chainParams['consensus']![consensusAlgorithm as ConsensusAlgorithm]! | ||
return isTruthy(value) | ||
? value | ||
: this._chainParams['consensus'][this.consensusAlgorithm() as ConsensusAlgorithm]! | ||
} | ||
@@ -841,0 +834,0 @@ |
@@ -1,3 +0,3 @@ | ||
export { Common as default } from './common' | ||
export * from './common' | ||
export * from './enums' | ||
export * from './types' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
247766
6771
0
296
+ Added@ethereumjs/util@8.0.0-beta.2(transitive)
+ Addedrlp@4.0.0-beta.2(transitive)
- Removed@ethereumjs/util@8.0.0-beta.1(transitive)
- Removedrlp@4.0.0-beta.1(transitive)