Skip to content

Commit

Permalink
Abstracted Contract with BaseContract without meta-class properties f…
Browse files Browse the repository at this point in the history
…or easier extensions (#1384).
  • Loading branch information
ricmoo committed Mar 26, 2021
1 parent 0e1721b commit 87ceaed
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/contracts/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ export type ContractInterface = string | Array<Fragment | JsonFragment | string>
type InterfaceFunc = (contractInterface: ContractInterface) => Interface;


export class Contract {
export class BaseContract {
readonly address: string;
readonly interface: Interface;

Expand All @@ -598,9 +598,6 @@ export class Contract {

readonly filters: { [ name: string ]: (...args: Array<any>) => 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<string>;
Expand Down Expand Up @@ -709,7 +706,7 @@ export class Contract {
uniqueNames[name].push(signature);
}

if (this[signature] == null) {
if ((<Contract>this)[signature] == null) {
defineReadOnly<any, any>(this, signature, buildDefault(this, fragment, true));
}

Expand Down Expand Up @@ -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 ((<Contract>this)[name] == null) {
defineReadOnly(<Contract>this, name, (<Contract>this)[signature]);
}
} catch (e) { }

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 87ceaed

Please sign in to comment.