aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-07-02 01:20:06 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-07-02 10:44:17 +0800
commit0e54418dbbccab84fad30e7d8b38f189652f76e7 (patch)
treea47ef80cc2b3f38c097f55aa7c34b7dab9ecf8ab /src/contract_wrappers
parent6e0edb8d8e8ced3b9e602a5722df859dd34ce563 (diff)
downloaddexon-sol-tools-0e54418dbbccab84fad30e7d8b38f189652f76e7.tar
dexon-sol-tools-0e54418dbbccab84fad30e7d8b38f189652f76e7.tar.gz
dexon-sol-tools-0e54418dbbccab84fad30e7d8b38f189652f76e7.tar.bz2
dexon-sol-tools-0e54418dbbccab84fad30e7d8b38f189652f76e7.tar.lz
dexon-sol-tools-0e54418dbbccab84fad30e7d8b38f189652f76e7.tar.xz
dexon-sol-tools-0e54418dbbccab84fad30e7d8b38f189652f76e7.tar.zst
dexon-sol-tools-0e54418dbbccab84fad30e7d8b38f189652f76e7.zip
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.ts20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index 5d514e5ec..5d4c21154 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -25,6 +25,8 @@ import {
LogErrorContractEventArgs,
LogFillContractEventArgs,
LogCancelContractEventArgs,
+ EventCallback,
+ ContractEventArg,
} from '../types';
import {assert} from '../utils/assert';
import {utils} from '../utils/utils';
@@ -583,14 +585,30 @@ export class ExchangeWrapper extends ContractWrapper {
this._exchangeLogEventEmitters = [];
}
private _wrapEventEmitter(event: ContractEventObj): ContractEventEmitter {
+ const watch = (eventCallback: EventCallback) => {
+ const bignumberWrappingEventCallback = this._wrapEventCallback(eventCallback);
+ event.watch(bignumberWrappingEventCallback);
+ };
const zeroExEvent = {
- watch: event.watch.bind(event),
+ watch,
stopWatchingAsync: async () => {
await promisify(event.stopWatching, event)();
},
};
return zeroExEvent;
}
+ private _wrapEventCallback(eventCallback: EventCallback): EventCallback {
+ const bignumberWrappingEventCallback = (err: Error, event: ContractEvent) => {
+ if (_.isNull(err)) {
+ const wrapIfBigNumber = (value: ContractEventArg): ContractEventArg => {
+ return value instanceof String ? value : new BigNumber(value);
+ };
+ event.args = _.mapValues(event.args, wrapIfBigNumber);
+ }
+ eventCallback(err, event);
+ };
+ return bignumberWrappingEventCallback;
+ }
private async _isValidSignatureUsingContractCallAsync(dataHex: string, ecSignature: ECSignature,
signerAddressHex: string): Promise<boolean> {
assert.isHexString('dataHex', dataHex);