aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers/exchange_wrapper.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-05-30 20:23:44 +0800
committerFabio Berger <me@fabioberger.com>2017-05-30 20:23:44 +0800
commitad14c307cec8e0e7621b47e9e1ecb2652985190f (patch)
tree4800127dea7cd267ab57622d875fa92a49f1a98e /src/contract_wrappers/exchange_wrapper.ts
parent8561258ded12bc7d284933e61f6d052941258f40 (diff)
downloaddexon-sol-tools-ad14c307cec8e0e7621b47e9e1ecb2652985190f.tar
dexon-sol-tools-ad14c307cec8e0e7621b47e9e1ecb2652985190f.tar.gz
dexon-sol-tools-ad14c307cec8e0e7621b47e9e1ecb2652985190f.tar.bz2
dexon-sol-tools-ad14c307cec8e0e7621b47e9e1ecb2652985190f.tar.lz
dexon-sol-tools-ad14c307cec8e0e7621b47e9e1ecb2652985190f.tar.xz
dexon-sol-tools-ad14c307cec8e0e7621b47e9e1ecb2652985190f.tar.zst
dexon-sol-tools-ad14c307cec8e0e7621b47e9e1ecb2652985190f.zip
Refactor exchangeWrapper and tokenRegistryWrapper to use contract getter that instantiates contract instance if not already instantiated
Diffstat (limited to 'src/contract_wrappers/exchange_wrapper.ts')
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index 90b9a39d2..3f6eb0dab 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -7,11 +7,11 @@ import * as ExchangeArtifacts from '../artifacts/Exchange.json';
import {ecSignatureSchema} from '../schemas/ec_signature_schema';
export class ExchangeWrapper extends ContractWrapper {
- private exchangeContractIfExists: ExchangeContract;
+ private exchangeContractIfExists?: ExchangeContract;
constructor(web3Wrapper: Web3Wrapper) {
super(web3Wrapper);
}
- public invalidateContractInstance() {
+ public invalidateContractInstance(): void {
delete this.exchangeContractIfExists;
}
public async isValidSignatureAsync(dataHex: string, ecSignature: ECSignature,
@@ -23,9 +23,9 @@ export class ExchangeWrapper extends ContractWrapper {
const senderAddressIfExists = await this.web3Wrapper.getSenderAddressIfExistsAsync();
assert.assert(!_.isUndefined(senderAddressIfExists), ZeroExError.USER_HAS_NO_ASSOCIATED_ADDRESSES);
- await this.instantiateExchangeContractIfDoesntExistAsync();
+ const exchangeContract = await this.getExchangeContractAsync();
- const isValidSignature = await this.exchangeContractIfExists.isValidSignature.call(
+ const isValidSignature = await exchangeContract.isValidSignature.call(
signerAddressHex,
dataHex,
ecSignature.v,
@@ -37,11 +37,12 @@ export class ExchangeWrapper extends ContractWrapper {
);
return isValidSignature;
}
- private async instantiateExchangeContractIfDoesntExistAsync() {
+ private async getExchangeContractAsync(): Promise<ExchangeContract> {
if (!_.isUndefined(this.exchangeContractIfExists)) {
- return;
+ return this.exchangeContractIfExists;
}
const contractInstance = await this.instantiateContractIfExistsAsync((ExchangeArtifacts as any));
this.exchangeContractIfExists = contractInstance as ExchangeContract;
+ return this.exchangeContractIfExists;
}
}