aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers/contract_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/contract_wrapper.ts
parentc8b54f3bac33f28c315c7018b3185f59e9a474dc (diff)
parentdf5fe4a84f3c5ee8946fa615428c5b9de8f8b06f (diff)
downloaddexon-sol-tools-a798f32cc89b61788856073265d20ad3812576ae.tar
dexon-sol-tools-a798f32cc89b61788856073265d20ad3812576ae.tar.gz
dexon-sol-tools-a798f32cc89b61788856073265d20ad3812576ae.tar.bz2
dexon-sol-tools-a798f32cc89b61788856073265d20ad3812576ae.tar.lz
dexon-sol-tools-a798f32cc89b61788856073265d20ad3812576ae.tar.xz
dexon-sol-tools-a798f32cc89b61788856073265d20ad3812576ae.tar.zst
dexon-sol-tools-a798f32cc89b61788856073265d20ad3812576ae.zip
Merge branch 'development' into setFillOrKillToUseRequestInterface
Diffstat (limited to 'src/contract_wrappers/contract_wrapper.ts')
-rw-r--r--src/contract_wrappers/contract_wrapper.ts29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts
index f6ccfdee4..19dccc6f2 100644
--- a/src/contract_wrappers/contract_wrapper.ts
+++ b/src/contract_wrappers/contract_wrapper.ts
@@ -14,6 +14,7 @@ import {
IndexedFilterValues,
EventCallback,
BlockParamLiteral,
+ ContractEventArgs,
} from '../types';
import {constants} from '../utils/constants';
import {intervalUtils} from '../utils/interval_utils';
@@ -25,7 +26,7 @@ export class ContractWrapper {
private _blockAndLogStreamer: BlockAndLogStreamer|undefined;
private _blockAndLogStreamInterval: NodeJS.Timer;
private _filters: {[filterToken: string]: Web3.FilterObject};
- private _filterCallbacks: {[filterToken: string]: EventCallback};
+ private _filterCallbacks: {[filterToken: string]: EventCallback<ContractEventArgs>};
private _onLogAddedSubscriptionToken: string|undefined;
private _onLogRemovedSubscriptionToken: string|undefined;
constructor(web3Wrapper: Web3Wrapper, abiDecoder?: AbiDecoder) {
@@ -37,9 +38,9 @@ export class ContractWrapper {
this._onLogAddedSubscriptionToken = undefined;
this._onLogRemovedSubscriptionToken = undefined;
}
- protected _subscribe(address: string, eventName: ContractEvents,
- indexFilterValues: IndexedFilterValues, abi: Web3.ContractAbi,
- callback: EventCallback): string {
+ protected _subscribe<ArgsType extends ContractEventArgs>(
+ address: string, eventName: ContractEvents, indexFilterValues: IndexedFilterValues, abi: Web3.ContractAbi,
+ callback: EventCallback<ArgsType>): string {
const filter = filterUtils.getFilter(address, eventName, indexFilterValues, abi);
if (_.isUndefined(this._blockAndLogStreamer)) {
this._startBlockAndLogStream();
@@ -59,32 +60,32 @@ export class ContractWrapper {
this._stopBlockAndLogStream();
}
}
- protected async _getLogsAsync(address: string, eventName: ContractEvents, subscriptionOpts: SubscriptionOpts,
- indexFilterValues: IndexedFilterValues,
- abi: Web3.ContractAbi): Promise<LogWithDecodedArgs[]> {
+ protected async _getLogsAsync<ArgsType extends ContractEventArgs>(
+ address: string, eventName: ContractEvents, subscriptionOpts: SubscriptionOpts,
+ indexFilterValues: IndexedFilterValues, abi: Web3.ContractAbi): Promise<Array<LogWithDecodedArgs<ArgsType>>> {
const filter = filterUtils.getFilter(address, eventName, indexFilterValues, abi, subscriptionOpts);
const logs = await this._web3Wrapper.getLogsAsync(filter);
const logsWithDecodedArguments = _.map(logs, this._tryToDecodeLogOrNoop.bind(this));
return logsWithDecodedArguments;
}
- protected _tryToDecodeLogOrNoop(log: Web3.LogEntry): LogWithDecodedArgs|RawLog {
+ protected _tryToDecodeLogOrNoop<ArgsType extends ContractEventArgs>(
+ log: Web3.LogEntry): LogWithDecodedArgs<ArgsType>|RawLog {
if (_.isUndefined(this._abiDecoder)) {
throw new Error(InternalZeroExError.NoAbiDecoder);
}
const logWithDecodedArgs = this._abiDecoder.tryToDecodeLogOrNoop(log);
return logWithDecodedArgs;
}
- protected async _instantiateContractIfExistsAsync<A extends Web3.ContractInstance>(artifact: Artifact,
- addressIfExists?: string,
- ): Promise<A> {
+ protected async _instantiateContractIfExistsAsync<ContractType extends Web3.ContractInstance>(
+ artifact: Artifact, addressIfExists?: string): Promise<ContractType> {
const contractInstance =
- await this._web3Wrapper.getContractInstanceFromArtifactAsync<A>(artifact, addressIfExists);
+ await this._web3Wrapper.getContractInstanceFromArtifactAsync<ContractType>(artifact, addressIfExists);
return contractInstance;
}
- private _onLogStateChanged(removed: boolean, log: Web3.LogEntry): void {
+ private _onLogStateChanged<ArgsType extends ContractEventArgs>(removed: boolean, log: Web3.LogEntry): void {
_.forEach(this._filters, (filter: Web3.FilterObject, filterToken: string) => {
if (filterUtils.matchesFilter(log, filter)) {
- const decodedLog = this._tryToDecodeLogOrNoop(log) as LogWithDecodedArgs;
+ const decodedLog = this._tryToDecodeLogOrNoop(log) as LogWithDecodedArgs<ArgsType>;
const logEvent = {
...decodedLog,
removed,