aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src/utils/exchange_wrapper.ts
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-03-10 07:47:21 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-04-21 04:56:16 +0800
commit6db0b2e39821f27f6f31a8247159864dacd1d2bd (patch)
treebe4b6b6cc5cb098446a3a82016931173642faf5b /packages/contracts/src/utils/exchange_wrapper.ts
parent2bd1ddd1296b4b3706bf91934e00c02508ca7c6f (diff)
downloaddexon-sol-tools-6db0b2e39821f27f6f31a8247159864dacd1d2bd.tar.gz
dexon-sol-tools-6db0b2e39821f27f6f31a8247159864dacd1d2bd.tar.zst
dexon-sol-tools-6db0b2e39821f27f6f31a8247159864dacd1d2bd.zip
Address feedback and lint
Diffstat (limited to 'packages/contracts/src/utils/exchange_wrapper.ts')
-rw-r--r--packages/contracts/src/utils/exchange_wrapper.ts94
1 files changed, 15 insertions, 79 deletions
diff --git a/packages/contracts/src/utils/exchange_wrapper.ts b/packages/contracts/src/utils/exchange_wrapper.ts
index b53519871..5996867cb 100644
--- a/packages/contracts/src/utils/exchange_wrapper.ts
+++ b/packages/contracts/src/utils/exchange_wrapper.ts
@@ -31,13 +31,7 @@ export class ExchangeWrapper {
params.signature,
{ from },
);
- const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
- tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
- tx.logs = _.map(tx.logs, log => {
- const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log);
- wrapLogBigNumbers(logWithDecodedArgs);
- return logWithDecodedArgs;
- });
+ const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
return tx;
}
public async cancelOrderAsync(
@@ -51,13 +45,7 @@ export class ExchangeWrapper {
params.takerTokenCancelAmount,
{ from },
);
- const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
- tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
- tx.logs = _.map(tx.logs, log => {
- const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log);
- wrapLogBigNumbers(logWithDecodedArgs);
- return logWithDecodedArgs;
- });
+ const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
return tx;
}
public async fillOrKillOrderAsync(
@@ -72,13 +60,7 @@ export class ExchangeWrapper {
params.signature,
{ from },
);
- const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
- tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
- tx.logs = _.map(tx.logs, log => {
- const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log);
- wrapLogBigNumbers(logWithDecodedArgs);
- return logWithDecodedArgs;
- });
+ const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
return tx;
}
public async fillOrderNoThrowAsync(
@@ -93,13 +75,7 @@ export class ExchangeWrapper {
params.signature,
{ from },
);
- const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
- tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
- tx.logs = _.map(tx.logs, log => {
- const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log);
- wrapLogBigNumbers(logWithDecodedArgs);
- return logWithDecodedArgs;
- });
+ const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
return tx;
}
public async batchFillOrdersAsync(
@@ -114,13 +90,7 @@ export class ExchangeWrapper {
params.signatures,
{ from },
);
- const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
- tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
- tx.logs = _.map(tx.logs, log => {
- const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log);
- wrapLogBigNumbers(logWithDecodedArgs);
- return logWithDecodedArgs;
- });
+ const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
return tx;
}
public async batchFillOrKillOrdersAsync(
@@ -135,13 +105,7 @@ export class ExchangeWrapper {
params.signatures,
{ from },
);
- const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
- tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
- tx.logs = _.map(tx.logs, log => {
- const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log);
- wrapLogBigNumbers(logWithDecodedArgs);
- return logWithDecodedArgs;
- });
+ const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
return tx;
}
public async batchFillOrdersNoThrowAsync(
@@ -156,13 +120,7 @@ export class ExchangeWrapper {
params.signatures,
{ from },
);
- const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
- tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
- tx.logs = _.map(tx.logs, log => {
- const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log);
- wrapLogBigNumbers(logWithDecodedArgs);
- return logWithDecodedArgs;
- });
+ const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
return tx;
}
public async marketFillOrdersAsync(
@@ -177,13 +135,7 @@ export class ExchangeWrapper {
params.signatures,
{ from },
);
- const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
- tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
- tx.logs = _.map(tx.logs, log => {
- const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log);
- wrapLogBigNumbers(logWithDecodedArgs);
- return logWithDecodedArgs;
- });
+ const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
return tx;
}
public async marketFillOrdersNoThrowAsync(
@@ -198,13 +150,7 @@ export class ExchangeWrapper {
params.signatures,
{ from },
);
- const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
- tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
- tx.logs = _.map(tx.logs, log => {
- const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log);
- wrapLogBigNumbers(logWithDecodedArgs);
- return logWithDecodedArgs;
- });
+ const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
return tx;
}
public async batchCancelOrdersAsync(
@@ -218,13 +164,7 @@ export class ExchangeWrapper {
params.takerTokenCancelAmounts,
{ from },
);
- const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
- tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
- tx.logs = _.map(tx.logs, log => {
- const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log);
- wrapLogBigNumbers(logWithDecodedArgs);
- return logWithDecodedArgs;
- });
+ const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
return tx;
}
public async getOrderHashAsync(signedOrder: SignedOrder): Promise<string> {
@@ -262,14 +202,10 @@ export class ExchangeWrapper {
const filledAmount = new BigNumber(await this._exchange.filled.callAsync(orderHashHex));
return filledAmount;
}
-}
-
-function wrapLogBigNumbers(log: any): any {
- const argNames = _.keys(log.args);
- for (const argName of argNames) {
- const isWeb3BigNumber = _.startsWith(log.args[argName].constructor.toString(), 'function BigNumber(');
- if (isWeb3BigNumber) {
- log.args[argName] = new BigNumber(log.args[argName]);
- }
+ private async _getTxWithDecodedExchangeLogsAsync(txHash: string) {
+ const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
+ tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
+ tx.logs = _.map(tx.logs, log => this._logDecoder.decodeLogOrThrow(log));
+ return tx;
}
}