diff options
author | Leonid <logvinov.leon@gmail.com> | 2017-10-04 19:30:36 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-04 19:30:36 +0800 |
commit | 836d9be7fee9986c8ffa380633d873ba557511f4 (patch) | |
tree | bdbe710ada39c7619efa5087cdd4eee6256cbf33 /src/web3_wrapper.ts | |
parent | 5d554ab88246563a8efcbde1b92e45ab926214d5 (diff) | |
parent | e5bdf60460330a24597e018f3611e7bc939c1362 (diff) | |
download | dexon-sol-tools-836d9be7fee9986c8ffa380633d873ba557511f4.tar dexon-sol-tools-836d9be7fee9986c8ffa380633d873ba557511f4.tar.gz dexon-sol-tools-836d9be7fee9986c8ffa380633d873ba557511f4.tar.bz2 dexon-sol-tools-836d9be7fee9986c8ffa380633d873ba557511f4.tar.lz dexon-sol-tools-836d9be7fee9986c8ffa380633d873ba557511f4.tar.xz dexon-sol-tools-836d9be7fee9986c8ffa380633d873ba557511f4.tar.zst dexon-sol-tools-836d9be7fee9986c8ffa380633d873ba557511f4.zip |
Merge pull request #178 from 0xProject/feature/getLogs
Add zeroEx.getLogsAsync
Diffstat (limited to 'src/web3_wrapper.ts')
-rw-r--r-- | src/web3_wrapper.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index 0bf80a6e4..7576f3d40 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -9,10 +9,12 @@ export class Web3Wrapper { private web3: Web3; private defaults: Partial<Web3.TxData>; private networkIdIfExists?: number; + private jsonRpcRequestId: number; constructor(provider: Web3.Provider, defaults: Partial<Web3.TxData>) { this.web3 = new Web3(); this.web3.setProvider(provider); this.defaults = defaults; + this.jsonRpcRequestId = 0; } public setProvider(provider: Web3.Provider) { delete this.networkIdIfExists; @@ -100,6 +102,20 @@ export class Web3Wrapper { const addresses: string[] = await promisify(this.web3.eth.getAccounts)(); return addresses; } + public async getLogsAsync(filter: Web3.FilterObject): Promise<Web3.LogEntry[]> { + const payload = { + jsonrpc: '2.0', + id: this.jsonRpcRequestId++, + method: 'eth_getLogs', + params: [filter], + }; + 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; @@ -109,4 +125,10 @@ export class Web3Wrapper { const networkId = await promisify(this.web3.version.getNetwork)(); return networkId; } + private async sendRawPayloadAsync(payload: Web3.JSONRPCRequestPayload): Promise<any> { + const sendAsync = this.web3.currentProvider.sendAsync.bind(this.web3.currentProvider); + const response = await promisify(sendAsync)(payload); + const result = response.result; + return result; + } } |