aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-10-06 17:58:17 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-10-06 17:58:17 +0800
commit1043def46c137c9d308b3201eddc0d08afa34b10 (patch)
treea4aed6fae86cf0235b52aab5ee9aeff409d6df6d /src
parent6af2ba5cffa582130b1c50639cabd9d6385dbd9e (diff)
downloaddexon-sol-tools-1043def46c137c9d308b3201eddc0d08afa34b10.tar
dexon-sol-tools-1043def46c137c9d308b3201eddc0d08afa34b10.tar.gz
dexon-sol-tools-1043def46c137c9d308b3201eddc0d08afa34b10.tar.bz2
dexon-sol-tools-1043def46c137c9d308b3201eddc0d08afa34b10.tar.lz
dexon-sol-tools-1043def46c137c9d308b3201eddc0d08afa34b10.tar.xz
dexon-sol-tools-1043def46c137c9d308b3201eddc0d08afa34b10.tar.zst
dexon-sol-tools-1043def46c137c9d308b3201eddc0d08afa34b10.zip
Install js-sha3 and use it for keccak256
Diffstat (limited to 'src')
-rw-r--r--src/contract_wrappers/contract_wrapper.ts9
-rw-r--r--src/utils/filter_utils.ts5
-rw-r--r--src/web3_wrapper.ts4
3 files changed, 5 insertions, 13 deletions
diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts
index f3ebae871..0bd7cc8b1 100644
--- a/src/contract_wrappers/contract_wrapper.ts
+++ b/src/contract_wrappers/contract_wrapper.ts
@@ -38,9 +38,7 @@ export class ContractWrapper {
protected _subscribe(address: string, eventName: ContractEvents,
indexFilterValues: IndexedFilterValues, abi: Web3.ContractAbi,
callback: EventCallback): string {
- const filter = filterUtils.getFilter(
- this._web3Wrapper.keccak256.bind(this._web3Wrapper), address, eventName, indexFilterValues, abi,
- );
+ const filter = filterUtils.getFilter(address, eventName, indexFilterValues, abi);
if (_.isEmpty(this._filters)) {
this._startBlockAndLogStream();
}
@@ -62,10 +60,7 @@ export class ContractWrapper {
protected async _getLogsAsync(address: string, eventName: ContractEvents, subscriptionOpts: SubscriptionOpts,
indexFilterValues: IndexedFilterValues,
abi: Web3.ContractAbi): Promise<LogWithDecodedArgs[]> {
- const filter = filterUtils.getFilter(
- this._web3Wrapper.keccak256.bind(this._web3Wrapper), address, eventName, indexFilterValues, abi,
- subscriptionOpts,
- );
+ 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;
diff --git a/src/utils/filter_utils.ts b/src/utils/filter_utils.ts
index ee39b6836..2bd745815 100644
--- a/src/utils/filter_utils.ts
+++ b/src/utils/filter_utils.ts
@@ -2,6 +2,7 @@ import * as _ from 'lodash';
import * as Web3 from 'web3';
import * as uuid from 'uuid/v4';
import * as ethUtil from 'ethereumjs-util';
+import * as jsSHA3 from 'js-sha3';
import {ContractEvents, IndexedFilterValues, SubscriptionOpts} from '../types';
const TOPIC_LENGTH = 32;
@@ -10,12 +11,12 @@ export const filterUtils = {
generateUUID(): string {
return uuid();
},
- getFilter(keccak256: (data: string) => string, address: string, eventName: ContractEvents,
+ getFilter(address: string, eventName: ContractEvents,
indexFilterValues: IndexedFilterValues, abi: Web3.ContractAbi,
subscriptionOpts?: SubscriptionOpts): Web3.FilterObject {
const eventAbi = _.find(abi, {name: eventName}) as Web3.EventAbi;
const eventSignature = filterUtils.getEventSignatureFromAbiByName(eventAbi, eventName);
- const topicForEventSignature = keccak256(eventSignature);
+ const topicForEventSignature = jsSHA3.keccak256(eventSignature);
const topicsForIndexedArgs = filterUtils.getTopicsForIndexedArgs(eventAbi, indexFilterValues);
const topics = [topicForEventSignature, ...topicsForIndexedArgs];
let filter: Web3.FilterObject = {
diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts
index fd9b74b8b..9de75c809 100644
--- a/src/web3_wrapper.ts
+++ b/src/web3_wrapper.ts
@@ -116,10 +116,6 @@ export class Web3Wrapper {
const logs = await this.sendRawPayloadAsync(payload);
return logs;
}
- public keccak256(data: string): string {
- const hash = this.web3.sha3(data);
- return hash;
- }
private getContractInstance<A extends Web3.ContractInstance>(abi: Web3.ContractAbi, address: string): A {
const web3ContractInstance = this.web3.eth.contract(abi).at(address);
const contractInstance = new Contract(web3ContractInstance, this.defaults) as any as A;