Skip to content

Commit 4163dc7

Browse files
committed
common: added new isActivatedEIP() method
1 parent ad9def9 commit 4163dc7

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

packages/common/src/eips/2315.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"comment": "Simple subroutines for the EVM",
55
"url": "https://eips.ethereum.org/EIPS/eip-2315",
66
"status": "Draft",
7-
"minimumHardfork": "berlin",
7+
"minimumHardfork": "istanbul",
88
"gasConfig": {},
99
"gasPrices": {
1010
"beginsub": {

packages/common/src/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,30 @@ export default class Common extends EventEmitter {
370370
return this.paramByHardfork(topic, name, hardfork)
371371
}
372372

373+
/**
374+
* Checks if an EIP is activated by either being included in the EIPs
375+
* manually passed in with the `eips` constructor option or in a
376+
* hardfork currently being active
377+
*
378+
* Note: this method only works for EIPs being supported
379+
* by the `eips` constructor option
380+
* @param eip
381+
*/
382+
isActivatedEIP(eip: number): boolean {
383+
if (this.eips().includes(eip)) {
384+
return true
385+
}
386+
for (const hfChanges of HARDFORK_CHANGES) {
387+
const hf = hfChanges[1]
388+
if (this.gteHardfork(hf['name']) && 'eips' in hf) {
389+
if (hf['eips'].includes(eip)) {
390+
return true
391+
}
392+
}
393+
}
394+
return false
395+
}
396+
373397
/**
374398
* Checks if set or provided hardfork is active on block number
375399
* @param hardfork Hardfork name or null (for HF set)

packages/common/tests/eips.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,16 @@ tape('[Common]: Initialization / Chain params', function (t: tape.Test) {
3232

3333
st.end()
3434
})
35+
36+
t.test('isActivatedEIP()', function (st) {
37+
let c = new Common({ chain: 'rinkeby', hardfork: 'istanbul' })
38+
st.equal(c.isActivatedEIP(2315), false, 'istanbul, eips: [] -> false (EIP-2315)')
39+
c = new Common({ chain: 'rinkeby', hardfork: 'istanbul', eips: [2315] })
40+
st.equal(c.isActivatedEIP(2315), true, 'istanbul, eips: [2315] -> true (EIP-2315)')
41+
c = new Common({ chain: 'rinkeby', hardfork: 'berlin' })
42+
st.equal(c.isActivatedEIP(2315), true, 'berlin, eips: [] -> true (EIP-2315)')
43+
st.equal(c.isActivatedEIP(2537), false, 'berlin, eips: [] -> false (EIP-2537)')
44+
45+
st.end()
46+
})
3547
})

0 commit comments

Comments
 (0)