aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-11-13 10:24:00 +0800
committerGitHub <noreply@github.com>2017-11-13 10:24:00 +0800
commita74ec0effa818a86233fe64cb0dad2c61bbb4bb6 (patch)
tree24438eda01318a80b5cbc7f1939d1640764a9859 /src
parentb0be323e899ea7be42b6c695b4fd6d526070b213 (diff)
parente33027c6244b99a1fb181404668bd2a259d923e2 (diff)
downloaddexon-sol-tools-a74ec0effa818a86233fe64cb0dad2c61bbb4bb6.tar
dexon-sol-tools-a74ec0effa818a86233fe64cb0dad2c61bbb4bb6.tar.gz
dexon-sol-tools-a74ec0effa818a86233fe64cb0dad2c61bbb4bb6.tar.bz2
dexon-sol-tools-a74ec0effa818a86233fe64cb0dad2c61bbb4bb6.tar.lz
dexon-sol-tools-a74ec0effa818a86233fe64cb0dad2c61bbb4bb6.tar.xz
dexon-sol-tools-a74ec0effa818a86233fe64cb0dad2c61bbb4bb6.tar.zst
dexon-sol-tools-a74ec0effa818a86233fe64cb0dad2c61bbb4bb6.zip
Merge pull request #200 from 0xProject/feature/receipt-status
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 7963ec43e..1b3e893ba 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 20f994ac7..11683378f 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -418,8 +418,6 @@ export interface ZeroExConfig {
orderWatcherConfig?: OrderStateWatcherConfig;
}
-export type TransactionReceipt = Web3.TransactionReceipt;
-
export enum AbiType {
Function = 'function',
Constructor = 'constructor',
@@ -433,7 +431,7 @@ export interface DecodedLogArgs {
export interface LogWithDecodedArgs<ArgsType> extends Web3.DecodedLogEntry<ArgsType> {}
-export interface TransactionReceiptWithDecodedLogs extends Web3.TransactionReceipt {
+export interface TransactionReceiptWithDecodedLogs extends TransactionReceipt {
logs: Array<LogWithDecodedArgs<DecodedLogArgs>|Web3.LogEntry>;
}
@@ -511,3 +509,17 @@ export type OrderState = OrderStateValid|OrderStateInvalid;
export type OnOrderStateChangeCallbackSync = (orderState: OrderState) => void;
export type OnOrderStateChangeCallbackAsync = (orderState: OrderState) => Promise<void>;
export type OnOrderStateChangeCallback = OnOrderStateChangeCallbackAsync|OnOrderStateChangeCallbackSync;
+
+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 d03c102b2..c937f9288 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 {
@@ -37,8 +37,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(transactionReceipt.status);
return transactionReceipt;
}
public getCurrentProvider(): Web3.Provider {
@@ -154,4 +155,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;
+ }
+ }
}