Make fillOrderAsync accept signedOrder instead of a shit-ton of params

This commit is contained in:
Leonid Logvinov 2017-05-30 12:17:43 +02:00
parent cf63e1d1a6
commit 380c1e1ca5
No known key found for this signature in database
GPG Key ID: 0DD294BFDE8C95D4

View File

@ -6,11 +6,13 @@ import {
ExchangeContractErrs, ExchangeContractErrs,
OrderValues, OrderValues,
OrderAddresses, OrderAddresses,
SignedOrder,
} from '../types'; } from '../types';
import {assert} from '../utils/assert'; import {assert} from '../utils/assert';
import {ContractWrapper} from './contract_wrapper'; import {ContractWrapper} from './contract_wrapper';
import * as ExchangeArtifacts from '../artifacts/Exchange.json'; import * as ExchangeArtifacts from '../artifacts/Exchange.json';
import {ecSignatureSchema} from '../schemas/ec_signature_schema'; import {ecSignatureSchema} from '../schemas/ec_signature_schema';
import {signedOrderSchema} from '../schemas/signed_order_schema';
import {ContractResponse} from '../types'; import {ContractResponse} from '../types';
import {constants} from '../utils/constants'; import {constants} from '../utils/constants';
@ -47,54 +49,38 @@ export class ExchangeWrapper extends ContractWrapper {
); );
return isValidSignature; return isValidSignature;
} }
public async fillOrderAsync(maker: string, taker: string, makerTokenAddress: string, public async fillOrderAsync(signedOrder: SignedOrder, shouldCheckTransfer: boolean = true) {
takerTokenAddress: string, makerTokenAmount: BigNumber.BigNumber, assert.doesConformToSchema('signedOrder', JSON.parse(JSON.stringify(signedOrder)), signedOrderSchema);
takerTokenAmount: BigNumber.BigNumber, makerFee: BigNumber.BigNumber, assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer);
takerFee: BigNumber.BigNumber, expirationUnixTimestampSec: BigNumber.BigNumber,
feeRecipient: string, fillAmount: BigNumber.BigNumber,
ecSignature: ECSignature, salt: BigNumber.BigNumber) {
assert.isBigNumber('salt', salt);
assert.isBigNumber('makerFee', makerFee);
assert.isBigNumber('takerFee', takerFee);
assert.isBigNumber('fillAmount', fillAmount);
assert.isBigNumber('makerTokenAmount', makerTokenAmount);
assert.isBigNumber('takerTokenAmount', takerTokenAmount);
assert.isBigNumber('expirationUnixTimestampSec', expirationUnixTimestampSec);
assert.isETHAddressHex('maker', maker);
assert.isETHAddressHex('taker', taker);
assert.isETHAddressHex('feeRecipient', feeRecipient);
assert.isETHAddressHex('makerTokenAddress', makerTokenAddress);
assert.isETHAddressHex('takerTokenAddress', takerTokenAddress);
assert.doesConformToSchema('ecSignature', ecSignature, ecSignatureSchema);
const senderAddress = await this.web3Wrapper.getSenderAddressOrThrowAsync(); const senderAddress = await this.web3Wrapper.getSenderAddressOrThrowAsync();
const exchangeInstance = await this.getExchangeInstanceOrThrowAsync(); const exchangeInstance = await this.getExchangeInstanceOrThrowAsync();
taker = taker === '' ? constants.NULL_ADDRESS : taker; const taker = _.isUndefined(signedOrder.taker) ? constants.NULL_ADDRESS : signedOrder.taker;
const shouldCheckTransfer = true;
const orderAddresses: OrderAddresses = [ const orderAddresses: OrderAddresses = [
maker, signedOrder.maker,
taker, taker,
makerTokenAddress, signedOrder.makerTokenAddress,
takerTokenAddress, signedOrder.takerTokenAddress,
feeRecipient, signedOrder.feeRecipient,
]; ];
const orderValues: OrderValues = [ const orderValues: OrderValues = [
makerTokenAmount, signedOrder.makerTokenAmount,
takerTokenAmount, signedOrder.takerTokenAmount,
makerFee, signedOrder.makerFee,
takerFee, signedOrder.takerFee,
expirationUnixTimestampSec, signedOrder.expirationUnixTimestampSec,
salt, signedOrder.salt,
]; ];
const response: ContractResponse = await exchangeInstance.fill( const response: ContractResponse = await exchangeInstance.fill(
orderAddresses, orderAddresses,
orderValues, orderValues,
fillAmount, signedOrder.fillAmount,
shouldCheckTransfer, shouldCheckTransfer,
ecSignature.v, signedOrder.ecSignature.v,
ecSignature.r, signedOrder.ecSignature.r,
ecSignature.s, signedOrder.ecSignature.s,
{ {
from: senderAddress, from: senderAddress,
}, },