aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers/exchange_wrapper.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/contract_wrappers/exchange_wrapper.ts')
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index f0f153c2b..3f6eb0dab 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -7,9 +7,13 @@ import * as ExchangeArtifacts from '../artifacts/Exchange.json';
import {ecSignatureSchema} from '../schemas/ec_signature_schema';
export class ExchangeWrapper extends ContractWrapper {
+ private exchangeContractIfExists?: ExchangeContract;
constructor(web3Wrapper: Web3Wrapper) {
super(web3Wrapper);
}
+ public invalidateContractInstance(): void {
+ delete this.exchangeContractIfExists;
+ }
public async isValidSignatureAsync(dataHex: string, ecSignature: ECSignature,
signerAddressHex: string): Promise<boolean> {
assert.isHexString('dataHex', dataHex);
@@ -19,10 +23,9 @@ export class ExchangeWrapper extends ContractWrapper {
const senderAddressIfExists = await this.web3Wrapper.getSenderAddressIfExistsAsync();
assert.assert(!_.isUndefined(senderAddressIfExists), ZeroExError.USER_HAS_NO_ASSOCIATED_ADDRESSES);
- const contractInstance = await this.instantiateContractIfExistsAsync((ExchangeArtifacts as any));
- const exchangeInstance = contractInstance as ExchangeContract;
+ const exchangeContract = await this.getExchangeContractAsync();
- const isValidSignature = await exchangeInstance.isValidSignature.call(
+ const isValidSignature = await exchangeContract.isValidSignature.call(
signerAddressHex,
dataHex,
ecSignature.v,
@@ -34,4 +37,12 @@ export class ExchangeWrapper extends ContractWrapper {
);
return isValidSignature;
}
+ private async getExchangeContractAsync(): Promise<ExchangeContract> {
+ if (!_.isUndefined(this.exchangeContractIfExists)) {
+ return this.exchangeContractIfExists;
+ }
+ const contractInstance = await this.instantiateContractIfExistsAsync((ExchangeArtifacts as any));
+ this.exchangeContractIfExists = contractInstance as ExchangeContract;
+ return this.exchangeContractIfExists;
+ }
}