aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers/exchange_wrapper.ts
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-10-16 16:40:20 +0800
committerGitHub <noreply@github.com>2017-10-16 16:40:20 +0800
commita798f32cc89b61788856073265d20ad3812576ae (patch)
tree43a7ee4b5dab08091178b09985e180ab8de7f53f /src/contract_wrappers/exchange_wrapper.ts
parentc8b54f3bac33f28c315c7018b3185f59e9a474dc (diff)
parentdf5fe4a84f3c5ee8946fa615428c5b9de8f8b06f (diff)
downloaddexon-0x-contracts-a798f32cc89b61788856073265d20ad3812576ae.tar
dexon-0x-contracts-a798f32cc89b61788856073265d20ad3812576ae.tar.gz
dexon-0x-contracts-a798f32cc89b61788856073265d20ad3812576ae.tar.bz2
dexon-0x-contracts-a798f32cc89b61788856073265d20ad3812576ae.tar.lz
dexon-0x-contracts-a798f32cc89b61788856073265d20ad3812576ae.tar.xz
dexon-0x-contracts-a798f32cc89b61788856073265d20ad3812576ae.tar.zst
dexon-0x-contracts-a798f32cc89b61788856073265d20ad3812576ae.zip
Merge branch 'development' into setFillOrKillToUseRequestInterface
Diffstat (limited to 'src/contract_wrappers/exchange_wrapper.ts')
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index e7b4a437f..bc0ac0634 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -1,4 +1,5 @@
import * as _ from 'lodash';
+import * as Web3 from 'web3';
import * as BigNumber from 'bignumber.js';
import {schemas} from '0x-json-schemas';
import {Web3Wrapper} from '../web3_wrapper';
@@ -27,6 +28,8 @@ import {
OrderTransactionOpts,
RawLog,
EventCallback,
+ ExchangeContractEventArgs,
+ DecodedLogArgs,
} from '../types';
import {assert} from '../utils/assert';
import {utils} from '../utils/utils';
@@ -653,13 +656,14 @@ export class ExchangeWrapper extends ContractWrapper {
* @param callback Callback that gets called when a log is added/removed
* @return Subscription token used later to unsubscribe
*/
- public async subscribeAsync(eventName: ExchangeEvents, indexFilterValues: IndexedFilterValues,
- callback: EventCallback): Promise<string> {
+ public async subscribeAsync<ArgsType extends ExchangeContractEventArgs>(
+ eventName: ExchangeEvents, indexFilterValues: IndexedFilterValues,
+ callback: EventCallback<ArgsType>): Promise<string> {
assert.doesBelongToStringEnum('eventName', eventName, ExchangeEvents);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
assert.isFunction('callback', callback);
const exchangeContractAddress = await this.getContractAddressAsync();
- const subscriptionToken = this._subscribe(
+ const subscriptionToken = this._subscribe<ArgsType>(
exchangeContractAddress, eventName, indexFilterValues, artifacts.ExchangeArtifact.abi, callback,
);
this._activeSubscriptions.push(subscriptionToken);
@@ -681,13 +685,14 @@ export class ExchangeWrapper extends ContractWrapper {
* the value is the value you are interested in. E.g `{_from: aUserAddressHex}`
* @return Array of logs that match the parameters
*/
- public async getLogsAsync(eventName: ExchangeEvents, subscriptionOpts: SubscriptionOpts,
- indexFilterValues: IndexedFilterValues): Promise<LogWithDecodedArgs[]> {
+ public async getLogsAsync<ArgsType extends ExchangeContractEventArgs>(
+ eventName: ExchangeEvents, subscriptionOpts: SubscriptionOpts, indexFilterValues: IndexedFilterValues,
+ ): Promise<Array<LogWithDecodedArgs<ArgsType>>> {
assert.doesBelongToStringEnum('eventName', eventName, ExchangeEvents);
assert.doesConformToSchema('subscriptionOpts', subscriptionOpts, schemas.subscriptionOptsSchema);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
const exchangeContractAddress = await this.getContractAddressAsync();
- const logs = await this._getLogsAsync(
+ const logs = await this._getLogsAsync<ArgsType>(
exchangeContractAddress, eventName, subscriptionOpts, indexFilterValues, artifacts.ExchangeArtifact.abi,
);
return logs;
@@ -798,12 +803,14 @@ export class ExchangeWrapper extends ContractWrapper {
}
/**
* Checks if logs contain LogError, which is emmited by Exchange contract on transaction failure.
- * @param logsWithDecodedArgs Transaction logs as returned by `zeroEx.awaitTransactionMinedAsync`
+ * @param logs Transaction logs as returned by `zeroEx.awaitTransactionMinedAsync`
*/
- public throwLogErrorsAsErrors(logsWithDecodedArgs: LogWithDecodedArgs[]): void {
- const errLog = _.find(logsWithDecodedArgs, {event: ExchangeEvents.LogError});
+ public throwLogErrorsAsErrors(logs: Array<LogWithDecodedArgs<DecodedLogArgs>|Web3.LogEntry>): void {
+ const errLog = _.find(logs, {
+ event: ExchangeEvents.LogError,
+ }) as LogWithDecodedArgs<LogErrorContractEventArgs>|undefined;
if (!_.isUndefined(errLog)) {
- const logArgs: LogErrorContractEventArgs = errLog.args as any;
+ const logArgs = errLog.args;
const errCode = logArgs.errorId.toNumber();
const errMessage = this._exchangeContractErrCodesToMsg[errCode];
throw new Error(errMessage);