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.ts14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index 7a80c5800..66e53a7d4 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -26,9 +26,13 @@ export class ExchangeWrapper extends ContractWrapper {
[ExchangeContractErrs.ERROR_FILL_TRUNCATION]: 'The rounding error was too large when filling this order',
[ExchangeContractErrs.ERROR_FILL_BALANCE_ALLOWANCE]: 'Maker or taker has insufficient balance or allowance',
};
+ 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);
@@ -36,7 +40,7 @@ export class ExchangeWrapper extends ContractWrapper {
assert.isETHAddressHex('signerAddressHex', signerAddressHex);
const senderAddress = await this.web3Wrapper.getSenderAddressOrThrowAsync();
- const exchangeInstance = await this.getExchangeInstanceOrThrowAsync();
+ const exchangeInstance = await this.getExchangeContractAsync();
const isValidSignature = await exchangeInstance.isValidSignature.call(
signerAddressHex,
@@ -102,4 +106,12 @@ export class ExchangeWrapper extends ContractWrapper {
throw new Error(humanReadableErrMessage);
}
}
+ 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;
+ }
}