aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-02-10 05:43:32 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-04-21 04:56:16 +0800
commit4c76ad072a043253085fc0f08f47afb30bb6f834 (patch)
tree6947520aba3b7b735bca57439be2d7b814dc91e1 /packages/contracts/src
parentedf837ed622d782e43b0d25dd46a27469b9b0381 (diff)
downloaddexon-sol-tools-4c76ad072a043253085fc0f08f47afb30bb6f834.tar
dexon-sol-tools-4c76ad072a043253085fc0f08f47afb30bb6f834.tar.gz
dexon-sol-tools-4c76ad072a043253085fc0f08f47afb30bb6f834.tar.bz2
dexon-sol-tools-4c76ad072a043253085fc0f08f47afb30bb6f834.tar.lz
dexon-sol-tools-4c76ad072a043253085fc0f08f47afb30bb6f834.tar.xz
dexon-sol-tools-4c76ad072a043253085fc0f08f47afb30bb6f834.tar.zst
dexon-sol-tools-4c76ad072a043253085fc0f08f47afb30bb6f834.zip
Move log decoding logic to exchange wrapper
Diffstat (limited to 'packages/contracts/src')
-rw-r--r--packages/contracts/src/utils/exchange_wrapper.ts50
1 files changed, 39 insertions, 11 deletions
diff --git a/packages/contracts/src/utils/exchange_wrapper.ts b/packages/contracts/src/utils/exchange_wrapper.ts
index daab002b3..4887a1f07 100644
--- a/packages/contracts/src/utils/exchange_wrapper.ts
+++ b/packages/contracts/src/utils/exchange_wrapper.ts
@@ -5,11 +5,14 @@ import * as Web3 from 'web3';
import { ExchangeContract } from '../contract_wrappers/generated/exchange';
+import { constants } from './constants';
import { formatters } from './formatters';
+import { LogDecoder } from './log_decoder';
import { signedOrderUtils } from './signed_order_utils';
export class ExchangeWrapper {
private _exchange: ExchangeContract;
+ private _logDecoder: LogDecoder = new LogDecoder(constants.TESTRPC_NETWORK_ID);
private _zeroEx: ZeroEx;
constructor(exchangeContract: ExchangeContract, zeroEx: ZeroEx) {
this._exchange = exchangeContract;
@@ -32,7 +35,11 @@ export class ExchangeWrapper {
);
const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
- _.each(tx.logs, log => wrapLogBigNumbers(log));
+ tx.logs = _.map(tx.logs, log => {
+ const decodedLog = this._logDecoder.tryToDecodeLogOrNoop(log);
+ wrapLogBigNumbers(decodedLog);
+ return decodedLog;
+ });
return tx;
}
public async cancelOrderAsync(
@@ -49,7 +56,11 @@ export class ExchangeWrapper {
);
const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
- _.each(tx.logs, log => wrapLogBigNumbers(log));
+ tx.logs = _.map(tx.logs, log => {
+ const decodedLog = this._logDecoder.tryToDecodeLogOrNoop(log);
+ wrapLogBigNumbers(decodedLog);
+ return decodedLog;
+ });
return tx;
}
public async fillOrKillOrderAsync(
@@ -69,16 +80,17 @@ export class ExchangeWrapper {
);
const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
- _.each(tx.logs, log => wrapLogBigNumbers(log));
+ tx.logs = _.map(tx.logs, log => {
+ const decodedLog = this._logDecoder.tryToDecodeLogOrNoop(log);
+ wrapLogBigNumbers(decodedLog);
+ return decodedLog;
+ });
return tx;
}
public async batchFillOrdersAsync(
orders: SignedOrder[],
from: string,
- opts: {
- takerTokenFillAmounts?: BigNumber[];
- shouldThrowOnInsufficientBalanceOrAllowance?: boolean;
- } = {},
+ opts: { takerTokenFillAmounts?: BigNumber[] } = {},
): Promise<TransactionReceiptWithDecodedLogs> {
const params = formatters.createBatchFill(orders, opts.takerTokenFillAmounts);
const txHash = await this._exchange.batchFillOrders.sendTransactionAsync(
@@ -92,7 +104,11 @@ export class ExchangeWrapper {
);
const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
- _.each(tx.logs, log => wrapLogBigNumbers(log));
+ tx.logs = _.map(tx.logs, log => {
+ const decodedLog = this._logDecoder.tryToDecodeLogOrNoop(log);
+ wrapLogBigNumbers(decodedLog);
+ return decodedLog;
+ });
return tx;
}
public async batchFillOrKillOrdersAsync(
@@ -112,7 +128,11 @@ export class ExchangeWrapper {
);
const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
- _.each(tx.logs, log => wrapLogBigNumbers(log));
+ tx.logs = _.map(tx.logs, log => {
+ const decodedLog = this._logDecoder.tryToDecodeLogOrNoop(log);
+ wrapLogBigNumbers(decodedLog);
+ return decodedLog;
+ });
return tx;
}
public async marketFillOrdersAsync(
@@ -132,7 +152,11 @@ export class ExchangeWrapper {
);
const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
- _.each(tx.logs, log => wrapLogBigNumbers(log));
+ tx.logs = _.map(tx.logs, log => {
+ const decodedLog = this._logDecoder.tryToDecodeLogOrNoop(log);
+ wrapLogBigNumbers(decodedLog);
+ return decodedLog;
+ });
return tx;
}
public async batchCancelOrdersAsync(
@@ -149,7 +173,11 @@ export class ExchangeWrapper {
);
const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
- _.each(tx.logs, log => wrapLogBigNumbers(log));
+ tx.logs = _.map(tx.logs, log => {
+ const decodedLog = this._logDecoder.tryToDecodeLogOrNoop(log);
+ wrapLogBigNumbers(decodedLog);
+ return decodedLog;
+ });
return tx;
}
public async getOrderHashAsync(signedOrder: SignedOrder): Promise<string> {