aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-07-04 07:13:16 +0800
committerGitHub <noreply@github.com>2017-07-04 07:13:16 +0800
commit997964f3e24eda9287a6d4a9c56d8e90b72f0789 (patch)
tree0cb99d4d64b08dd6bb1d64e53c0e0af751d6b8c9 /src/contract_wrappers
parentd4cef89587ef8ea0f7fbab1146c4524e8f588eac (diff)
parentc9edeae6d8dad1fba6c4f5eca63ff5db3e6555e2 (diff)
downloaddexon-sol-tools-997964f3e24eda9287a6d4a9c56d8e90b72f0789.tar
dexon-sol-tools-997964f3e24eda9287a6d4a9c56d8e90b72f0789.tar.gz
dexon-sol-tools-997964f3e24eda9287a6d4a9c56d8e90b72f0789.tar.bz2
dexon-sol-tools-997964f3e24eda9287a6d4a9c56d8e90b72f0789.tar.lz
dexon-sol-tools-997964f3e24eda9287a6d4a9c56d8e90b72f0789.tar.xz
dexon-sol-tools-997964f3e24eda9287a6d4a9c56d8e90b72f0789.tar.zst
dexon-sol-tools-997964f3e24eda9287a6d4a9c56d8e90b72f0789.zip
Merge pull request #87 from 0xProject/wrap-log-bignumber
Wrap all event args in a newer version of BigNumber and test it
Diffstat (limited to 'src/contract_wrappers')
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index f596cb429..57a116aea 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -1,6 +1,7 @@
import * as _ from 'lodash';
import * as BigNumber from 'bignumber.js';
import promisify = require('es6-promisify');
+import * as Web3 from 'web3';
import {Web3Wrapper} from '../web3_wrapper';
import {
ECSignature,
@@ -26,6 +27,8 @@ import {
LogErrorContractEventArgs,
LogFillContractEventArgs,
LogCancelContractEventArgs,
+ EventCallback,
+ ContractEventArg,
ExchangeContractByAddress,
ContractArtifact,
} from '../types';
@@ -653,14 +656,36 @@ export class ExchangeWrapper extends ContractWrapper {
return isAuthorized;
}
private _wrapEventEmitter(event: ContractEventObj): ContractEventEmitter {
+ const watch = (eventCallback: EventCallback) => {
+ const bignumberWrappingEventCallback = this._getBigNumberWrappingEventCallback(eventCallback);
+ event.watch(bignumberWrappingEventCallback);
+ };
const zeroExEvent = {
- watch: event.watch.bind(event),
+ watch,
stopWatchingAsync: async () => {
await promisify(event.stopWatching, event)();
},
};
return zeroExEvent;
}
+ private _getBigNumberWrappingEventCallback(eventCallback: EventCallback): EventCallback {
+ const bignumberWrappingEventCallback = (err: Error, event: ContractEvent) => {
+ if (_.isNull(err)) {
+ const wrapIfBigNumber = (value: ContractEventArg): ContractEventArg => {
+ // HACK: The old version of BigNumber used by Web3@0.19.0 does not support the `isBigNumber`
+ // and checking for a BigNumber instance using `instanceof` does not work either. We therefore
+ // compare the constructor functions of the possible BigNumber instance and the BigNumber used by
+ // Web3.
+ const web3BigNumber = (Web3.prototype as any).BigNumber;
+ const isWeb3BigNumber = web3BigNumber.toString() === value.constructor.toString();
+ return isWeb3BigNumber ? new BigNumber(value) : value;
+ };
+ event.args = _.mapValues(event.args, wrapIfBigNumber);
+ }
+ eventCallback(err, event);
+ };
+ return bignumberWrappingEventCallback;
+ }
private async _isValidSignatureUsingContractCallAsync(dataHex: string, ecSignature: ECSignature,
signerAddressHex: string,
exchangeContractAddress: string): Promise<boolean> {