Skip to content

Commit 77dc55a

Browse files
committed
introduce common.copy() for deep copy
1 parent 280e013 commit 77dc55a

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

packages/client/lib/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ export class Config {
194194
// TODO: map chainParams (and lib/util.parseParams) to new Common format
195195
const common =
196196
options.common ?? new Common({ chain: Config.CHAIN_DEFAULT, hardfork: 'chainstart' })
197-
this.chainCommon = Object.assign(Object.create(Object.getPrototypeOf(common)), common)
198-
this.execCommon = Object.assign(Object.create(Object.getPrototypeOf(common)), common)
197+
this.chainCommon = common.copy()
198+
this.execCommon = common.copy()
199199

200200
this.discDns = this.getDnsDiscovery(options.discDns)
201201
this.discV4 = this.getV4Discovery(options.discV4)

packages/common/src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,4 +742,11 @@ export default class Common extends EventEmitter {
742742
consensusConfig(): any {
743743
return (<any>this._chainParams)['consensus'][this.consensusAlgorithm()]
744744
}
745+
746+
/**
747+
* Returns a deep copy of this common instance.
748+
*/
749+
copy(): Common {
750+
return Object.assign(Object.create(Object.getPrototypeOf(this)), this)
751+
}
745752
}

packages/tx/src/baseTransaction.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ export abstract class BaseTransaction<TransactionObject> {
4646

4747
this._validateExceedsMaxInteger(validateCannotExceedMaxInteger)
4848

49-
this.common =
50-
(txOptions.common &&
51-
Object.assign(Object.create(Object.getPrototypeOf(txOptions.common)), txOptions.common)) ??
52-
new Common({ chain: 'mainnet' })
49+
this.common = txOptions.common?.copy() ?? new Common({ chain: 'mainnet' })
5350
}
5451

5552
/**

0 commit comments

Comments
 (0)