aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/contract-wrappers/CHANGELOG.json10
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts3
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts3
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts2
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts34
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts4
-rw-r--r--packages/contract-wrappers/src/schemas/tx_opts_schema.ts1
-rw-r--r--packages/contract-wrappers/src/types.ts2
-rw-r--r--packages/web3-wrapper/CHANGELOG.json13
-rw-r--r--packages/web3-wrapper/package.json1
-rw-r--r--packages/web3-wrapper/src/index.ts3
-rw-r--r--packages/web3-wrapper/src/marshaller.ts18
-rw-r--r--packages/web3-wrapper/src/types.ts27
-rw-r--r--packages/web3-wrapper/src/web3_wrapper.ts26
-rw-r--r--packages/web3-wrapper/test/web3_wrapper_test.ts14
15 files changed, 149 insertions, 12 deletions
diff --git a/packages/contract-wrappers/CHANGELOG.json b/packages/contract-wrappers/CHANGELOG.json
index fbf3972a9..1ea966fc6 100644
--- a/packages/contract-wrappers/CHANGELOG.json
+++ b/packages/contract-wrappers/CHANGELOG.json
@@ -1,5 +1,15 @@
[
{
+ "version": "4.1.0",
+ "changes": [
+ {
+ "note":
+ "Add a `nonce` field for `TxOpts` so that it's now possible to re-broadcast stuck transactions with a higher gas amount",
+ "pr": 1292
+ }
+ ]
+ },
+ {
"timestamp": 1542208198,
"version": "4.0.2",
"changes": [
diff --git a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts
index 5e0ec1951..ad42cfd4f 100644
--- a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts
@@ -111,6 +111,7 @@ export class ERC20TokenWrapper extends ContractWrapper {
from: normalizedOwnerAddress,
gas: txOpts.gasLimit,
gasPrice: txOpts.gasPrice,
+ nonce: txOpts.nonce,
}),
);
return txHash;
@@ -281,6 +282,7 @@ export class ERC20TokenWrapper extends ContractWrapper {
from: normalizedFromAddress,
gas: txOpts.gasLimit,
gasPrice: txOpts.gasPrice,
+ nonce: txOpts.nonce,
}),
);
return txHash;
@@ -342,6 +344,7 @@ export class ERC20TokenWrapper extends ContractWrapper {
from: normalizedSenderAddress,
gas: txOpts.gasLimit,
gasPrice: txOpts.gasPrice,
+ nonce: txOpts.nonce,
}),
);
return txHash;
diff --git a/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts
index 1610af47b..3bc7dc8e7 100644
--- a/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts
@@ -238,6 +238,7 @@ export class ERC721TokenWrapper extends ContractWrapper {
gas: txOpts.gasLimit,
gasPrice: txOpts.gasPrice,
from: normalizedOwnerAddress,
+ nonce: txOpts.nonce,
}),
);
return txHash;
@@ -298,6 +299,7 @@ export class ERC721TokenWrapper extends ContractWrapper {
gas: txOpts.gasLimit,
gasPrice: txOpts.gasPrice,
from: tokenOwnerAddress,
+ nonce: txOpts.nonce,
}),
);
return txHash;
@@ -369,6 +371,7 @@ export class ERC721TokenWrapper extends ContractWrapper {
gas: txOpts.gasLimit,
gasPrice: txOpts.gasPrice,
from: normalizedSenderAddress,
+ nonce: txOpts.nonce,
}),
);
return txHash;
diff --git a/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts
index 913c47cf7..6093f0f95 100644
--- a/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts
@@ -71,6 +71,7 @@ export class EtherTokenWrapper extends ContractWrapper {
value: amountInWei,
gas: txOpts.gasLimit,
gasPrice: txOpts.gasPrice,
+ nonce: txOpts.nonce,
}),
);
return txHash;
@@ -112,6 +113,7 @@ export class EtherTokenWrapper extends ContractWrapper {
from: normalizedWithdrawerAddress,
gas: txOpts.gasLimit,
gasPrice: txOpts.gasPrice,
+ nonce: txOpts.nonce,
}),
);
return txHash;
diff --git a/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts
index c76e51eee..c9556971a 100644
--- a/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts
@@ -196,6 +196,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
});
}
@@ -207,6 +208,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
},
);
return txHash;
@@ -243,6 +245,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
},
);
}
@@ -254,6 +257,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
},
);
return txHash;
@@ -287,6 +291,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
});
}
const txHash = await exchangeInstance.fillOrKillOrder.sendTransactionAsync(
@@ -297,6 +302,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
},
);
return txHash;
@@ -336,6 +342,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedSenderAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
});
}
const txHash = await exchangeInstance.executeTransaction.sendTransactionAsync(
@@ -347,6 +354,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedSenderAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
},
);
return txHash;
@@ -382,6 +390,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
});
}
const txHash = await exchangeInstance.batchFillOrders.sendTransactionAsync(
@@ -392,6 +401,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
},
);
return txHash;
@@ -425,6 +435,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
});
}
const txHash = await exchangeInstance.marketBuyOrders.sendTransactionAsync(
@@ -435,6 +446,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
},
);
return txHash;
@@ -468,6 +480,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
});
}
const txHash = await exchangeInstance.marketSellOrders.sendTransactionAsync(
@@ -478,6 +491,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
},
);
return txHash;
@@ -511,6 +525,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
});
}
const txHash = await exchangeInstance.marketBuyOrdersNoThrow.sendTransactionAsync(
@@ -521,6 +536,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
},
);
return txHash;
@@ -554,6 +570,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
});
}
const txHash = await exchangeInstance.marketSellOrdersNoThrow.sendTransactionAsync(
@@ -564,6 +581,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
},
);
return txHash;
@@ -599,6 +617,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
});
}
const txHash = await exchangeInstance.batchFillOrdersNoThrow.sendTransactionAsync(
@@ -609,6 +628,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
},
);
return txHash;
@@ -644,6 +664,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
});
}
const txHash = await exchangeInstance.batchFillOrKillOrders.sendTransactionAsync(
@@ -654,6 +675,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
},
);
return txHash;
@@ -682,12 +704,14 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedMakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
});
}
const txHash = await exchangeInstance.batchCancelOrders.sendTransactionAsync(orders, {
from: normalizedMakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
});
return txHash;
}
@@ -735,6 +759,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
},
);
}
@@ -747,6 +772,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
},
);
return txHash;
@@ -781,12 +807,14 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
});
}
const txHash = await exchangeInstance.preSign.sendTransactionAsync(hash, signerAddress, signature, {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
});
return txHash;
}
@@ -956,12 +984,14 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedMakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
});
}
const txHash = await exchangeInstance.cancelOrder.sendTransactionAsync(order, {
from: normalizedMakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
});
return txHash;
}
@@ -992,6 +1022,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedSenderAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
});
}
const txHash = await exchangeInstance.setSignatureValidatorApproval.sendTransactionAsync(
@@ -1001,6 +1032,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedSenderAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
},
);
return txHash;
@@ -1030,12 +1062,14 @@ export class ExchangeWrapper extends ContractWrapper {
from: normalizedSenderAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
});
}
const txHash = await exchangeInstance.cancelOrdersUpTo.sendTransactionAsync(targetOrderEpoch, {
from: normalizedSenderAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
});
return txHash;
}
diff --git a/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts
index 80742e030..5497f92b5 100644
--- a/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts
@@ -124,6 +124,7 @@ export class ForwarderWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
},
);
}
@@ -140,6 +141,7 @@ export class ForwarderWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
},
);
return txHash;
@@ -213,6 +215,7 @@ export class ForwarderWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
},
);
}
@@ -230,6 +233,7 @@ export class ForwarderWrapper extends ContractWrapper {
from: normalizedTakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
+ nonce: orderTransactionOpts.nonce,
},
);
return txHash;
diff --git a/packages/contract-wrappers/src/schemas/tx_opts_schema.ts b/packages/contract-wrappers/src/schemas/tx_opts_schema.ts
index 83c819be2..1c1588db7 100644
--- a/packages/contract-wrappers/src/schemas/tx_opts_schema.ts
+++ b/packages/contract-wrappers/src/schemas/tx_opts_schema.ts
@@ -3,6 +3,7 @@ export const txOptsSchema = {
properties: {
gasPrice: { $ref: '/numberSchema' },
gasLimit: { type: 'number' },
+ nonce: { type: 'number' },
},
type: 'object',
};
diff --git a/packages/contract-wrappers/src/types.ts b/packages/contract-wrappers/src/types.ts
index 5a5bdd530..14d4649ae 100644
--- a/packages/contract-wrappers/src/types.ts
+++ b/packages/contract-wrappers/src/types.ts
@@ -142,10 +142,12 @@ export interface MethodOpts {
/**
* gasPrice: Gas price in Wei to use for a transaction
* gasLimit: The amount of gas to send with a transaction (in Gwei)
+ * nonce: The nonce to use for a transaction. If not specified, it defaults to the next incremented nonce.
*/
export interface TransactionOpts {
gasPrice?: BigNumber;
gasLimit?: number;
+ nonce?: number;
}
/**
diff --git a/packages/web3-wrapper/CHANGELOG.json b/packages/web3-wrapper/CHANGELOG.json
index b938f6986..cc65c2a7d 100644
--- a/packages/web3-wrapper/CHANGELOG.json
+++ b/packages/web3-wrapper/CHANGELOG.json
@@ -1,5 +1,18 @@
[
{
+ "version": "3.1.5",
+ "changes": [
+ {
+ "note": "Add unmarshalling of transaction receipts",
+ "pr": 1291
+ },
+ {
+ "note": "Return `undefined` instead of `null` if transaction receipt not found",
+ "pr": 1291
+ }
+ ]
+ },
+ {
"timestamp": 1542208198,
"version": "3.1.4",
"changes": [
diff --git a/packages/web3-wrapper/package.json b/packages/web3-wrapper/package.json
index 2469f7627..8d4d7ec35 100644
--- a/packages/web3-wrapper/package.json
+++ b/packages/web3-wrapper/package.json
@@ -10,6 +10,7 @@
"scripts": {
"build": "tsc -b",
"build:ci": "yarn build",
+ "watch_without_deps": "tsc -w",
"clean": "shx rm -rf lib generated_docs",
"lint": "tslint --format stylish --project .",
"test": "yarn run_mocha",
diff --git a/packages/web3-wrapper/src/index.ts b/packages/web3-wrapper/src/index.ts
index 679563a2b..4d20ba9be 100644
--- a/packages/web3-wrapper/src/index.ts
+++ b/packages/web3-wrapper/src/index.ts
@@ -52,6 +52,9 @@ export {
CallDataRPC,
BlockWithoutTransactionDataRPC,
BlockWithTransactionDataRPC,
+ TransactionReceiptStatusRPC,
+ TransactionReceiptRPC,
+ LogEntryRPC,
TransactionRPC,
TxDataRPC,
} from './types';
diff --git a/packages/web3-wrapper/src/marshaller.ts b/packages/web3-wrapper/src/marshaller.ts
index 299c6a64c..7bd274c85 100644
--- a/packages/web3-wrapper/src/marshaller.ts
+++ b/packages/web3-wrapper/src/marshaller.ts
@@ -9,6 +9,7 @@ import {
LogEntry,
RawLogEntry,
Transaction,
+ TransactionReceipt,
TxData,
} from 'ethereum-types';
import ethUtil = require('ethereumjs-util');
@@ -21,6 +22,7 @@ import {
BlockWithTransactionDataRPC,
CallDataRPC,
CallTxDataBaseRPC,
+ TransactionReceiptRPC,
TransactionRPC,
TxDataRPC,
} from './types';
@@ -92,6 +94,22 @@ export const marshaller = {
return tx;
},
/**
+ * Unmarshall transaction receipt
+ * @param txReceiptRpc transaction receipt to unmarshall
+ * @return unmarshalled transaction receipt
+ */
+ unmarshalTransactionReceipt(txReceiptRpc: TransactionReceiptRPC): TransactionReceipt {
+ const txReceipt = {
+ ...txReceiptRpc,
+ blockNumber: utils.convertHexToNumber(txReceiptRpc.blockNumber),
+ transactionIndex: utils.convertHexToNumber(txReceiptRpc.transactionIndex),
+ cumulativeGasUsed: utils.convertHexToNumber(txReceiptRpc.cumulativeGasUsed),
+ gasUsed: utils.convertHexToNumber(txReceiptRpc.gasUsed),
+ logs: _.map(txReceiptRpc.logs, marshaller.unmarshalLog.bind(marshaller)),
+ };
+ return txReceipt;
+ },
+ /**
* Unmarshall transaction data
* @param txDataRpc transaction data to unmarshall
* @return unmarshalled transaction data
diff --git a/packages/web3-wrapper/src/types.ts b/packages/web3-wrapper/src/types.ts
index e81039186..eb5a35f07 100644
--- a/packages/web3-wrapper/src/types.ts
+++ b/packages/web3-wrapper/src/types.ts
@@ -41,6 +41,33 @@ export interface TransactionRPC {
input: string;
}
+export interface TransactionReceiptRPC {
+ blockHash: string;
+ blockNumber: string;
+ transactionHash: string;
+ transactionIndex: string;
+ from: string;
+ to: string;
+ status: TransactionReceiptStatusRPC;
+ cumulativeGasUsed: string;
+ gasUsed: string;
+ contractAddress: string | null;
+ logs: LogEntryRPC[];
+}
+
+export interface LogEntryRPC {
+ logIndex: string | null;
+ transactionIndex: string | null;
+ transactionHash: string;
+ blockHash: string | null;
+ blockNumber: string | null;
+ address: string;
+ data: string;
+ topics: string[];
+}
+
+export type TransactionReceiptStatusRPC = null | string | 0 | 1;
+
export interface CallTxDataBaseRPC {
to?: string;
value?: string;
diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts
index be1713f20..f1247e48a 100644
--- a/packages/web3-wrapper/src/web3_wrapper.ts
+++ b/packages/web3-wrapper/src/web3_wrapper.ts
@@ -27,6 +27,7 @@ import {
BlockWithoutTransactionDataRPC,
BlockWithTransactionDataRPC,
NodeType,
+ TransactionReceiptRPC,
TransactionRPC,
Web3WrapperErrors,
} from './types';
@@ -212,20 +213,23 @@ export class Web3Wrapper {
return networkId;
}
/**
- * Retrieves the transaction receipt for a given transaction hash
+ * Retrieves the transaction receipt for a given transaction hash if found
* @param txHash Transaction hash
- * @returns The transaction receipt, including it's status (0: failed, 1: succeeded or undefined: not found)
+ * @returns The transaction receipt, including it's status (0: failed, 1: succeeded). Returns undefined if transaction not found.
*/
- public async getTransactionReceiptAsync(txHash: string): Promise<TransactionReceipt> {
+ public async getTransactionReceiptIfExistsAsync(txHash: string): Promise<TransactionReceipt | undefined> {
assert.isHexString('txHash', txHash);
- const transactionReceipt = await this.sendRawPayloadAsync<TransactionReceipt>({
+ const transactionReceiptRpc = await this.sendRawPayloadAsync<TransactionReceiptRPC>({
method: 'eth_getTransactionReceipt',
params: [txHash],
});
- if (!_.isNull(transactionReceipt)) {
- transactionReceipt.status = Web3Wrapper._normalizeTxReceiptStatus(transactionReceipt.status);
+ if (!_.isNull(transactionReceiptRpc)) {
+ transactionReceiptRpc.status = Web3Wrapper._normalizeTxReceiptStatus(transactionReceiptRpc.status);
+ const transactionReceipt = marshaller.unmarshalTransactionReceipt(transactionReceiptRpc);
+ return transactionReceipt;
+ } else {
+ return undefined;
}
- return transactionReceipt;
}
/**
* Retrieves the transaction data for a given transaction
@@ -572,8 +576,8 @@ export class Web3Wrapper {
assert.isNumber('timeoutMs', timeoutMs);
}
// Immediately check if the transaction has already been mined.
- let transactionReceipt = await this.getTransactionReceiptAsync(txHash);
- if (!_.isNull(transactionReceipt) && !_.isNull(transactionReceipt.blockNumber)) {
+ let transactionReceipt = await this.getTransactionReceiptIfExistsAsync(txHash);
+ if (!_.isUndefined(transactionReceipt) && !_.isNull(transactionReceipt.blockNumber)) {
const logsWithDecodedArgs = _.map(
transactionReceipt.logs,
this.abiDecoder.tryToDecodeLogOrNoop.bind(this.abiDecoder),
@@ -600,8 +604,8 @@ export class Web3Wrapper {
return reject(Web3WrapperErrors.TransactionMiningTimeout);
}
- transactionReceipt = await this.getTransactionReceiptAsync(txHash);
- if (!_.isNull(transactionReceipt)) {
+ transactionReceipt = await this.getTransactionReceiptIfExistsAsync(txHash);
+ if (!_.isUndefined(transactionReceipt)) {
intervalUtils.clearAsyncExcludingInterval(intervalId);
const logsWithDecodedArgs = _.map(
transactionReceipt.logs,
diff --git a/packages/web3-wrapper/test/web3_wrapper_test.ts b/packages/web3-wrapper/test/web3_wrapper_test.ts
index 164253777..935c67636 100644
--- a/packages/web3-wrapper/test/web3_wrapper_test.ts
+++ b/packages/web3-wrapper/test/web3_wrapper_test.ts
@@ -1,5 +1,5 @@
import * as chai from 'chai';
-import { BlockParamLiteral, JSONRPCErrorCallback, JSONRPCRequestPayload } from 'ethereum-types';
+import { BlockParamLiteral, JSONRPCErrorCallback, JSONRPCRequestPayload, TransactionReceipt } from 'ethereum-types';
import * as Ganache from 'ganache-core';
import * as _ from 'lodash';
import 'mocha';
@@ -98,6 +98,18 @@ describe('Web3Wrapper tests', () => {
expect(typeof blockNumber).to.be.equal('number');
});
});
+ describe('#getTransactionReceiptAsync/awaitTransactionSuccessAsync', () => {
+ it('get block number', async () => {
+ const payload = { from: addresses[0], to: addresses[1], value: 1 };
+ const txHash = await web3Wrapper.sendTransactionAsync(payload);
+ await web3Wrapper.awaitTransactionSuccessAsync(txHash);
+ const receiptIfExists = await web3Wrapper.getTransactionReceiptIfExistsAsync(txHash);
+ expect(receiptIfExists).to.not.be.undefined();
+ const receipt = receiptIfExists as TransactionReceipt;
+ expect(receipt.transactionIndex).to.be.a('number');
+ expect(receipt.transactionHash).to.be.equal(txHash);
+ });
+ });
describe('#getBlockIfExistsAsync', () => {
it('gets block when supplied a valid BlockParamLiteral value', async () => {
const blockParamLiteral = BlockParamLiteral.Earliest;