diff options
author | Fabio Berger <me@fabioberger.com> | 2017-11-22 04:03:26 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-11-22 04:03:26 +0800 |
commit | f7f1397e52d246426e4d7bbff89a0b770faed3ee (patch) | |
tree | fdf4e42d3b744a5ee97cab33017401215e8da55a /packages/0x.js/src/web3_wrapper.ts | |
parent | 3660ba28d73d70d08bf14c33ef680e5ef3ec7f3b (diff) | |
parent | e3cc2834789ec5d4affceee2d03015085b24d907 (diff) | |
download | dexon-sol-tools-f7f1397e52d246426e4d7bbff89a0b770faed3ee.tar dexon-sol-tools-f7f1397e52d246426e4d7bbff89a0b770faed3ee.tar.gz dexon-sol-tools-f7f1397e52d246426e4d7bbff89a0b770faed3ee.tar.bz2 dexon-sol-tools-f7f1397e52d246426e4d7bbff89a0b770faed3ee.tar.lz dexon-sol-tools-f7f1397e52d246426e4d7bbff89a0b770faed3ee.tar.xz dexon-sol-tools-f7f1397e52d246426e4d7bbff89a0b770faed3ee.tar.zst dexon-sol-tools-f7f1397e52d246426e4d7bbff89a0b770faed3ee.zip |
Merge branch 'development' into addWebsite
* development:
Fix a typo in postpublish utils tags -> tag
Publish
Revert "Publish"
Publish
Add instanceOf assertion
Rename toDecimal to hexToDecimal
Add PR numbers
Add postFormatter for logs
Diffstat (limited to 'packages/0x.js/src/web3_wrapper.ts')
-rw-r--r-- | packages/0x.js/src/web3_wrapper.ts | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/packages/0x.js/src/web3_wrapper.ts b/packages/0x.js/src/web3_wrapper.ts index c937f9288..f6b6ca09a 100644 --- a/packages/0x.js/src/web3_wrapper.ts +++ b/packages/0x.js/src/web3_wrapper.ts @@ -5,6 +5,17 @@ import promisify = require('es6-promisify'); import {ZeroExError, Artifact, TransactionReceipt} from './types'; import {Contract} from './contract'; +interface RawLogEntry { + logIndex: string|null; + transactionIndex: string|null; + transactionHash: string; + blockHash: string|null; + blockNumber: string|null; + address: string; + data: string; + topics: string[]; +} + export class Web3Wrapper { private web3: Web3; private defaults: Partial<Web3.TxData>; @@ -137,8 +148,9 @@ export class Web3Wrapper { method: 'eth_getLogs', params: [serializedFilter], }; - const logs = await this.sendRawPayloadAsync(payload); - return logs; + const rawLogs = await this.sendRawPayloadAsync<RawLogEntry[]>(payload); + const formattedLogs = _.map(rawLogs, this.formatLog.bind(this)); + return formattedLogs; } private getContractInstance<A extends Web3.ContractInstance>(abi: Web3.ContractAbi, address: string): A { const web3ContractInstance = this.web3.eth.contract(abi).at(address); @@ -149,7 +161,7 @@ export class Web3Wrapper { const networkId = await promisify(this.web3.version.getNetwork)(); return networkId; } - private async sendRawPayloadAsync(payload: Web3.JSONRPCRequestPayload): Promise<any> { + private async sendRawPayloadAsync<A>(payload: Web3.JSONRPCRequestPayload): Promise<A> { const sendAsync = this.web3.currentProvider.sendAsync.bind(this.web3.currentProvider); const response = await promisify(sendAsync)(payload); const result = response.result; @@ -169,4 +181,20 @@ export class Web3Wrapper { return status; } } + private formatLog(rawLog: RawLogEntry): Web3.LogEntry { + const formattedLog = { + ...rawLog, + logIndex: this.hexToDecimal(rawLog.logIndex), + blockNumber: this.hexToDecimal(rawLog.blockNumber), + transactionIndex: this.hexToDecimal(rawLog.transactionIndex), + }; + return formattedLog; + } + private hexToDecimal(hex: string|null): number|null { + if (_.isNull(hex)) { + return null; + } + const decimal = this.web3.toDecimal(hex); + return decimal; + } } |