From 50ee23ebfa5270f98c64c8be5ba4a7061c47bc27 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 25 Oct 2017 14:27:10 +0300 Subject: Normalize the way we return the transaction status --- src/index.ts | 1 + src/types.ts | 18 +++++++++++++++--- src/web3_wrapper.ts | 19 +++++++++++++++++-- 3 files changed, 33 insertions(+), 5 deletions(-) (limited to 'src') 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 { export interface LogWithDecodedArgs extends Web3.LogEntry, DecodedArgs {} -export interface TransactionReceiptWithDecodedLogs extends Web3.TransactionReceipt { +export interface TransactionReceiptWithDecodedLogs extends TransactionReceipt { logs: Array|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 { + public async getTransactionReceiptAsync(txHash: string): Promise { 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; + } + } } -- cgit v1.2.3 From a2f89347a9951443323afb2afe75d48204eb0aa1 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 25 Oct 2017 15:21:02 +0300 Subject: Fix tests --- src/web3_wrapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index 56b08ebec..be81fe78c 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -33,7 +33,7 @@ export class Web3Wrapper { } public async getTransactionReceiptAsync(txHash: string): Promise { const transactionReceipt = await promisify(this.web3.eth.getTransactionReceipt)(txHash); - transactionReceipt.status = this.normalizeTxReceiptStatus(status); + transactionReceipt.status = this.normalizeTxReceiptStatus(transactionReceipt.status); return transactionReceipt; } public getCurrentProvider(): Web3.Provider { -- cgit v1.2.3