Merge pull request #200 from 0xProject/feature/receipt-status

Normalize the way we return the transaction status
This commit is contained in:
Fabio Berger 2017-11-12 21:24:00 -05:00 committed by GitHub
commit a74ec0effa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 951 additions and 689 deletions

View File

@ -29,6 +29,7 @@ export {
ContractEventArg,
Web3Provider,
ZeroExConfig,
TransactionReceipt,
TransactionReceiptWithDecodedLogs,
LogWithDecodedArgs,
MethodOpts,

View File

@ -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[];
}

View File

@ -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;
}
}
}

View File

@ -63,7 +63,7 @@ describe('TokenWrapper', () => {
const preBalance = await zeroEx.token.getBalanceAsync(token.address, toAddress);
expect(preBalance).to.be.bignumber.equal(0);
const txHash = await zeroEx.token.transferAsync(token.address, fromAddress, toAddress, transferAmount);
await zeroEx.awaitTransactionMinedAsync(txHash);
const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
const postBalance = await zeroEx.token.getBalanceAsync(token.address, toAddress);
return expect(postBalance).to.be.bignumber.equal(transferAmount);
});

1600
yarn.lock

File diff suppressed because it is too large Load Diff