aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-10-25 19:27:10 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-11-13 04:05:06 +0800
commit50ee23ebfa5270f98c64c8be5ba4a7061c47bc27 (patch)
tree8be0036bef63e9c15fd31744f0db303227af1e13 /src
parent719c51f61a65e3e179ba2a78fa48105247ba2b41 (diff)
downloaddexon-sol-tools-50ee23ebfa5270f98c64c8be5ba4a7061c47bc27.tar
dexon-sol-tools-50ee23ebfa5270f98c64c8be5ba4a7061c47bc27.tar.gz
dexon-sol-tools-50ee23ebfa5270f98c64c8be5ba4a7061c47bc27.tar.bz2
dexon-sol-tools-50ee23ebfa5270f98c64c8be5ba4a7061c47bc27.tar.lz
dexon-sol-tools-50ee23ebfa5270f98c64c8be5ba4a7061c47bc27.tar.xz
dexon-sol-tools-50ee23ebfa5270f98c64c8be5ba4a7061c47bc27.tar.zst
dexon-sol-tools-50ee23ebfa5270f98c64c8be5ba4a7061c47bc27.zip
Normalize the way we return the transaction status
Diffstat (limited to 'src')
-rw-r--r--src/index.ts1
-rw-r--r--src/types.ts18
-rw-r--r--src/web3_wrapper.ts19
3 files changed, 33 insertions, 5 deletions
diff --git a/src/index.ts b/src/index.ts
index 249c20519..a69b7c141 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -29,6 +29,7 @@ export {
ContractEventArg,
Web3Provider,
ZeroExConfig,
+ TransactionReceipt,
TransactionReceiptWithDecodedLogs,
LogWithDecodedArgs,
MethodOpts,
diff --git a/src/types.ts b/src/types.ts
index af3c36736..a18164e20 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -403,8 +403,6 @@ export interface ZeroExConfig {
etherTokenContractAddress?: string;
}
-export type TransactionReceipt = Web3.TransactionReceipt;
-
export enum AbiType {
Function = 'function',
Constructor = 'constructor',
@@ -423,7 +421,7 @@ export interface DecodedArgs<ArgsType> {
export interface LogWithDecodedArgs<ArgsType> extends Web3.LogEntry, DecodedArgs<ArgsType> {}
-export interface TransactionReceiptWithDecodedLogs extends Web3.TransactionReceipt {
+export interface TransactionReceiptWithDecodedLogs extends TransactionReceipt {
logs: Array<LogWithDecodedArgs<DecodedLogArgs>|Web3.LogEntry>;
}
@@ -473,3 +471,17 @@ export enum TransferType {
Trade = 'trade',
Fee = 'fee',
}
+
+export interface TransactionReceipt {
+ blockHash: string;
+ blockNumber: number;
+ transactionHash: string;
+ transactionIndex: number;
+ from: string;
+ to: string;
+ status: null|0|1;
+ cumulativeGasUsed: number;
+ gasUsed: number;
+ contractAddress: string|null;
+ logs: Web3.LogEntry[];
+}
diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts
index 3b1e4477b..56b08ebec 100644
--- a/src/web3_wrapper.ts
+++ b/src/web3_wrapper.ts
@@ -2,7 +2,7 @@ import * as _ from 'lodash';
import * as Web3 from 'web3';
import BigNumber from 'bignumber.js';
import promisify = require('es6-promisify');
-import {ZeroExError, Artifact} from './types';
+import {ZeroExError, Artifact, TransactionReceipt} from './types';
import {Contract} from './contract';
export class Web3Wrapper {
@@ -31,8 +31,9 @@ export class Web3Wrapper {
const nodeVersion = await promisify(this.web3.version.getNode)();
return nodeVersion;
}
- public async getTransactionReceiptAsync(txHash: string): Promise<Web3.TransactionReceipt> {
+ public async getTransactionReceiptAsync(txHash: string): Promise<TransactionReceipt> {
const transactionReceipt = await promisify(this.web3.eth.getTransactionReceipt)(txHash);
+ transactionReceipt.status = this.normalizeTxReceiptStatus(status);
return transactionReceipt;
}
public getCurrentProvider(): Web3.Provider {
@@ -144,4 +145,18 @@ export class Web3Wrapper {
const result = response.result;
return result;
}
+ private normalizeTxReceiptStatus(status: undefined|null|string|0|1): null|0|1 {
+ // Transaction status might have four values
+ // undefined - Testrpc and other old clients
+ // null - New clients on old transactions
+ // number - Parity
+ // hex - Geth
+ if (_.isString(status)) {
+ return this.web3.toDecimal(status) as 0|1;
+ } else if (_.isUndefined(status)) {
+ return null;
+ } else {
+ return status;
+ }
+ }
}