Merge pull request #200 from 0xProject/feature/receipt-status
Normalize the way we return the transaction status
This commit is contained in:
commit
a74ec0effa
@ -29,6 +29,7 @@ export {
|
|||||||
ContractEventArg,
|
ContractEventArg,
|
||||||
Web3Provider,
|
Web3Provider,
|
||||||
ZeroExConfig,
|
ZeroExConfig,
|
||||||
|
TransactionReceipt,
|
||||||
TransactionReceiptWithDecodedLogs,
|
TransactionReceiptWithDecodedLogs,
|
||||||
LogWithDecodedArgs,
|
LogWithDecodedArgs,
|
||||||
MethodOpts,
|
MethodOpts,
|
||||||
|
18
src/types.ts
18
src/types.ts
@ -418,8 +418,6 @@ export interface ZeroExConfig {
|
|||||||
orderWatcherConfig?: OrderStateWatcherConfig;
|
orderWatcherConfig?: OrderStateWatcherConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TransactionReceipt = Web3.TransactionReceipt;
|
|
||||||
|
|
||||||
export enum AbiType {
|
export enum AbiType {
|
||||||
Function = 'function',
|
Function = 'function',
|
||||||
Constructor = 'constructor',
|
Constructor = 'constructor',
|
||||||
@ -433,7 +431,7 @@ export interface DecodedLogArgs {
|
|||||||
|
|
||||||
export interface LogWithDecodedArgs<ArgsType> extends Web3.DecodedLogEntry<ArgsType> {}
|
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>;
|
logs: Array<LogWithDecodedArgs<DecodedLogArgs>|Web3.LogEntry>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -511,3 +509,17 @@ export type OrderState = OrderStateValid|OrderStateInvalid;
|
|||||||
export type OnOrderStateChangeCallbackSync = (orderState: OrderState) => void;
|
export type OnOrderStateChangeCallbackSync = (orderState: OrderState) => void;
|
||||||
export type OnOrderStateChangeCallbackAsync = (orderState: OrderState) => Promise<void>;
|
export type OnOrderStateChangeCallbackAsync = (orderState: OrderState) => Promise<void>;
|
||||||
export type OnOrderStateChangeCallback = OnOrderStateChangeCallbackAsync|OnOrderStateChangeCallbackSync;
|
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[];
|
||||||
|
}
|
||||||
|
@ -2,7 +2,7 @@ import * as _ from 'lodash';
|
|||||||
import * as Web3 from 'web3';
|
import * as Web3 from 'web3';
|
||||||
import BigNumber from 'bignumber.js';
|
import BigNumber from 'bignumber.js';
|
||||||
import promisify = require('es6-promisify');
|
import promisify = require('es6-promisify');
|
||||||
import {ZeroExError, Artifact} from './types';
|
import {ZeroExError, Artifact, TransactionReceipt} from './types';
|
||||||
import {Contract} from './contract';
|
import {Contract} from './contract';
|
||||||
|
|
||||||
export class Web3Wrapper {
|
export class Web3Wrapper {
|
||||||
@ -37,8 +37,9 @@ export class Web3Wrapper {
|
|||||||
const nodeVersion = await promisify(this.web3.version.getNode)();
|
const nodeVersion = await promisify(this.web3.version.getNode)();
|
||||||
return nodeVersion;
|
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);
|
const transactionReceipt = await promisify(this.web3.eth.getTransactionReceipt)(txHash);
|
||||||
|
transactionReceipt.status = this.normalizeTxReceiptStatus(transactionReceipt.status);
|
||||||
return transactionReceipt;
|
return transactionReceipt;
|
||||||
}
|
}
|
||||||
public getCurrentProvider(): Web3.Provider {
|
public getCurrentProvider(): Web3.Provider {
|
||||||
@ -154,4 +155,18 @@ export class Web3Wrapper {
|
|||||||
const result = response.result;
|
const result = response.result;
|
||||||
return 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ describe('TokenWrapper', () => {
|
|||||||
const preBalance = await zeroEx.token.getBalanceAsync(token.address, toAddress);
|
const preBalance = await zeroEx.token.getBalanceAsync(token.address, toAddress);
|
||||||
expect(preBalance).to.be.bignumber.equal(0);
|
expect(preBalance).to.be.bignumber.equal(0);
|
||||||
const txHash = await zeroEx.token.transferAsync(token.address, fromAddress, toAddress, transferAmount);
|
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);
|
const postBalance = await zeroEx.token.getBalanceAsync(token.address, toAddress);
|
||||||
return expect(postBalance).to.be.bignumber.equal(transferAmount);
|
return expect(postBalance).to.be.bignumber.equal(transferAmount);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user