diff options
author | Fabio Berger <me@fabioberger.com> | 2017-06-01 21:52:11 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-06-01 21:52:11 +0800 |
commit | 73ad8378b0b4c2a87fd81cfc7a0193dbf940ff92 (patch) | |
tree | be077e8e1869bdc070401654133c1ac6762bdc98 /src/contract_wrappers/exchange_wrapper.ts | |
parent | 6a57c42e253a52a449cae8a5c6565276cb01a86c (diff) | |
parent | d8e35c364ea94b606810b340fb02d8706e257c3c (diff) | |
download | dexon-sol-tools-73ad8378b0b4c2a87fd81cfc7a0193dbf940ff92.tar dexon-sol-tools-73ad8378b0b4c2a87fd81cfc7a0193dbf940ff92.tar.gz dexon-sol-tools-73ad8378b0b4c2a87fd81cfc7a0193dbf940ff92.tar.bz2 dexon-sol-tools-73ad8378b0b4c2a87fd81cfc7a0193dbf940ff92.tar.lz dexon-sol-tools-73ad8378b0b4c2a87fd81cfc7a0193dbf940ff92.tar.xz dexon-sol-tools-73ad8378b0b4c2a87fd81cfc7a0193dbf940ff92.tar.zst dexon-sol-tools-73ad8378b0b4c2a87fd81cfc7a0193dbf940ff92.zip |
Merge branch 'fillOrderAsync' of github.com:0xProject/0x.js into fillOrderAsync
# Conflicts:
# src/contract_wrappers/exchange_wrapper.ts
Diffstat (limited to 'src/contract_wrappers/exchange_wrapper.ts')
-rw-r--r-- | src/contract_wrappers/exchange_wrapper.ts | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 1311730a0..bf3f10e28 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -4,6 +4,7 @@ import { ECSignature, ExchangeContract, ExchangeContractErrCodes, + FillOrderValidationErrs, OrderValues, OrderAddresses, SignedOrder, @@ -66,6 +67,8 @@ export class ExchangeWrapper extends ContractWrapper { const senderAddress = await this.web3Wrapper.getSenderAddressOrThrowAsync(); const exchangeInstance = await this.getExchangeInstanceOrThrowAsync(); + this.validateFillOrder(signedOrder, fillAmount, senderAddress, shouldCheckTransfer); + const orderAddresses: OrderAddresses = [ signedOrder.maker, signedOrder.taker, @@ -108,6 +111,18 @@ export class ExchangeWrapper extends ContractWrapper { ); this.throwErrorLogsAsErrors(response.logs); } + private validateFillOrder(signedOrder: SignedOrder, fillAmount: BigNumber.BigNumber, senderAddress: string, + shouldCheckTransfer: boolean = true) { + if (fillAmount.eq(0)) { + throw new Error(FillOrderValidationErrs.FILL_AMOUNT_IS_ZERO); + } + if (signedOrder.taker !== constants.NULL_ADDRESS && signedOrder.taker !== senderAddress) { + throw new Error(FillOrderValidationErrs.NOT_A_TAKER); + } + if (signedOrder.expirationUnixTimestampSec.lessThan(Date.now() / 1000)) { + throw new Error(FillOrderValidationErrs.EXPIRED); + } + } private async getExchangeInstanceOrThrowAsync(): Promise<ExchangeContract> { const contractInstance = await this.instantiateContractIfExistsAsync((ExchangeArtifacts as any)); return contractInstance as ExchangeContract; |