aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers/exchange_wrapper.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-05-30 20:55:43 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-05-30 20:55:43 +0800
commit3e65ac018c145d9fb49ece6cb113ae577f84323b (patch)
tree49f3b63f898b78c2b210b56b01e96f62887161b0 /src/contract_wrappers/exchange_wrapper.ts
parentdfcf49464b1a93b6e5df39289e9d14b2e60e62d2 (diff)
parent6b321ca1c70b9dcf188b2a112015386cba0ad5f2 (diff)
downloaddexon-sol-tools-3e65ac018c145d9fb49ece6cb113ae577f84323b.tar
dexon-sol-tools-3e65ac018c145d9fb49ece6cb113ae577f84323b.tar.gz
dexon-sol-tools-3e65ac018c145d9fb49ece6cb113ae577f84323b.tar.bz2
dexon-sol-tools-3e65ac018c145d9fb49ece6cb113ae577f84323b.tar.lz
dexon-sol-tools-3e65ac018c145d9fb49ece6cb113ae577f84323b.tar.xz
dexon-sol-tools-3e65ac018c145d9fb49ece6cb113ae577f84323b.tar.zst
dexon-sol-tools-3e65ac018c145d9fb49ece6cb113ae577f84323b.zip
Merge branch 'master' into fillOrderAsync
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;
+ }
}