Normalize the way we return the transaction status
This commit is contained in:
@@ -85,7 +85,7 @@
|
||||
"types-ethereumjs-util": "0xProject/types-ethereumjs-util",
|
||||
"typescript": "^2.4.1",
|
||||
"web3-provider-engine": "^13.0.1",
|
||||
"web3-typescript-typings": "^0.6.2",
|
||||
"web3-typescript-typings": "^0.6.4",
|
||||
"webpack": "^3.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
|
@@ -29,6 +29,7 @@ export {
|
||||
ContractEventArg,
|
||||
Web3Provider,
|
||||
ZeroExConfig,
|
||||
TransactionReceipt,
|
||||
TransactionReceiptWithDecodedLogs,
|
||||
LogWithDecodedArgs,
|
||||
MethodOpts,
|
||||
|
18
src/types.ts
18
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[];
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -62,7 +62,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);
|
||||
});
|
||||
|
Reference in New Issue
Block a user