From 87ceaed4be21283619da74678cf371c228c918b7 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Fri, 26 Mar 2021 17:32:36 -0400 Subject: [PATCH] Abstracted Contract with BaseContract without meta-class properties for easier extensions (#1384). --- packages/contracts/src.ts/index.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/contracts/src.ts/index.ts b/packages/contracts/src.ts/index.ts index 6a5c3d949b..3b10d1e05e 100644 --- a/packages/contracts/src.ts/index.ts +++ b/packages/contracts/src.ts/index.ts @@ -583,7 +583,7 @@ export type ContractInterface = string | Array type InterfaceFunc = (contractInterface: ContractInterface) => Interface; -export class Contract { +export class BaseContract { readonly address: string; readonly interface: Interface; @@ -598,9 +598,6 @@ export class Contract { readonly filters: { [ name: string ]: (...args: Array) => EventFilter }; - // The meta-class properties - readonly [ key: string ]: ContractFunction | any; - // This will always be an address. This will only differ from // address if an ENS name was used in the constructor readonly resolvedAddress: Promise; @@ -709,7 +706,7 @@ export class Contract { uniqueNames[name].push(signature); } - if (this[signature] == null) { + if ((this)[signature] == null) { defineReadOnly(this, signature, buildDefault(this, fragment, true)); } @@ -743,8 +740,8 @@ export class Contract { // If overwriting a member property that is null, swallow the error try { - if (this[name] == null) { - defineReadOnly(this, name, this[signature]); + if ((this)[name] == null) { + defineReadOnly(this, name, (this)[signature]); } } catch (e) { } @@ -1093,6 +1090,11 @@ export class Contract { } +export class Contract extends BaseContract { + // The meta-class properties + readonly [ key: string ]: ContractFunction | any; +} + export class ContractFactory { readonly interface: Interface;