aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-11-22 03:09:23 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-11-22 03:09:23 +0800
commitc8c95b4bd2e57be11bd250c652babbad9d6ffd35 (patch)
tree9bbbb5894ff2ff5a537fa7852dada50f6795ab08 /packages/0x.js
parent037f466e1f80f635b48f3235258402e2ce75fb7b (diff)
downloaddexon-sol-tools-c8c95b4bd2e57be11bd250c652babbad9d6ffd35.tar
dexon-sol-tools-c8c95b4bd2e57be11bd250c652babbad9d6ffd35.tar.gz
dexon-sol-tools-c8c95b4bd2e57be11bd250c652babbad9d6ffd35.tar.bz2
dexon-sol-tools-c8c95b4bd2e57be11bd250c652babbad9d6ffd35.tar.lz
dexon-sol-tools-c8c95b4bd2e57be11bd250c652babbad9d6ffd35.tar.xz
dexon-sol-tools-c8c95b4bd2e57be11bd250c652babbad9d6ffd35.tar.zst
dexon-sol-tools-c8c95b4bd2e57be11bd250c652babbad9d6ffd35.zip
Add postFormatter for logs
Diffstat (limited to 'packages/0x.js')
-rw-r--r--packages/0x.js/src/web3_wrapper.ts34
-rw-r--r--packages/0x.js/test/token_wrapper_test.ts2
2 files changed, 33 insertions, 3 deletions
diff --git a/packages/0x.js/src/web3_wrapper.ts b/packages/0x.js/src/web3_wrapper.ts
index c937f9288..af96c7650 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.toDecimal(rawLog.logIndex),
+ blockNumber: this.toDecimal(rawLog.blockNumber),
+ transactionIndex: this.toDecimal(rawLog.transactionIndex),
+ };
+ return formattedLog;
+ }
+ private toDecimal(hex: string|null): number|null {
+ if (_.isNull(hex)) {
+ return null;
+ }
+ const decimal = this.web3.toDecimal(hex);
+ return decimal;
+ }
}
diff --git a/packages/0x.js/test/token_wrapper_test.ts b/packages/0x.js/test/token_wrapper_test.ts
index b30762e8c..07276877d 100644
--- a/packages/0x.js/test/token_wrapper_test.ts
+++ b/packages/0x.js/test/token_wrapper_test.ts
@@ -361,6 +361,8 @@ describe('TokenWrapper', () => {
(async () => {
const callback = (err: Error, logEvent: DecodedLogEvent<TransferContractEventArgs>) => {
expect(logEvent).to.not.be.undefined();
+ expect(logEvent.logIndex).to.be.equal(0);
+ expect(logEvent.transactionIndex).to.be.equal(0);
const args = logEvent.args;
expect(args._from).to.be.equal(coinbase);
expect(args._to).to.be.equal(addressWithoutFunds);