Skip to content

Commit

Permalink
introduce common.copy() for deep copy
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio committed Mar 9, 2021
1 parent 280e013 commit 77dc55a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/client/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ export class Config {
// TODO: map chainParams (and lib/util.parseParams) to new Common format
const common =
options.common ?? new Common({ chain: Config.CHAIN_DEFAULT, hardfork: 'chainstart' })
this.chainCommon = Object.assign(Object.create(Object.getPrototypeOf(common)), common)
this.execCommon = Object.assign(Object.create(Object.getPrototypeOf(common)), common)
this.chainCommon = common.copy()
this.execCommon = common.copy()

this.discDns = this.getDnsDiscovery(options.discDns)
this.discV4 = this.getV4Discovery(options.discV4)
Expand Down
7 changes: 7 additions & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -742,4 +742,11 @@ export default class Common extends EventEmitter {
consensusConfig(): any {
return (<any>this._chainParams)['consensus'][this.consensusAlgorithm()]
}

/**
* Returns a deep copy of this common instance.
*/
copy(): Common {
return Object.assign(Object.create(Object.getPrototypeOf(this)), this)
}
}
5 changes: 1 addition & 4 deletions packages/tx/src/baseTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ export abstract class BaseTransaction<TransactionObject> {

this._validateExceedsMaxInteger(validateCannotExceedMaxInteger)

this.common =
(txOptions.common &&
Object.assign(Object.create(Object.getPrototypeOf(txOptions.common)), txOptions.common)) ??
new Common({ chain: 'mainnet' })
this.common = txOptions.common?.copy() ?? new Common({ chain: 'mainnet' })
}

/**
Expand Down

0 comments on commit 77dc55a

Please sign in to comment.