diff options
author | Leonid <logvinov.leon@gmail.com> | 2017-11-23 01:24:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-23 01:24:59 +0800 |
commit | beed223281115152e2d4282fa2c2e76515a98f45 (patch) | |
tree | 589be7ea7f90efdb541c55de14c9a97c1c4804bb /packages/0x.js/src | |
parent | 351b7557b65e4cdef2177585d52021ee5a0f3e42 (diff) | |
parent | 66750f7349435dbcdb783a214e21800466ec3ac1 (diff) | |
download | dexon-sol-tools-beed223281115152e2d4282fa2c2e76515a98f45.tar.gz dexon-sol-tools-beed223281115152e2d4282fa2c2e76515a98f45.tar.zst dexon-sol-tools-beed223281115152e2d4282fa2c2e76515a98f45.zip |
Merge branch 'development' into feature/orderExpired
Diffstat (limited to 'packages/0x.js/src')
-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 12d7caaf8..7bd8ea093 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>; @@ -139,8 +150,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); @@ -151,7 +163,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; @@ -171,4 +183,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; + } } |