@0x/web3-wrapper
Advanced tools
Comparing version 3.1.4 to 3.1.5
[ | ||
{ | ||
"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": 1542821676 | ||
}, | ||
{ | ||
"timestamp": 1542208198, | ||
@@ -4,0 +18,0 @@ "version": "3.1.4", |
@@ -8,2 +8,7 @@ <!-- | ||
## v3.1.5 - _November 21, 2018_ | ||
* Add unmarshalling of transaction receipts (#1291) | ||
* Return `undefined` instead of `null` if transaction receipt not found (#1291) | ||
## v3.1.4 - _November 14, 2018_ | ||
@@ -10,0 +15,0 @@ |
@@ -5,3 +5,3 @@ export { Web3Wrapper } from './web3_wrapper'; | ||
export { BlockParam, TxData, Provider, TransactionReceipt, Transaction, TraceParams, TransactionTrace, BlockWithoutTransactionData, LogEntry, FilterObject, CallData, TransactionReceiptWithDecodedLogs, BlockWithTransactionData, LogTopic, JSONRPCRequestPayload, TransactionReceiptStatus, DecodedLogArgs, StructLog, JSONRPCErrorCallback, BlockParamLiteral, ContractEventArg, DecodedLogEntry, LogEntryEvent, OpCode, TxDataPayable, JSONRPCResponsePayload, JSONRPCResponseError, RawLogEntry, DecodedLogEntryEvent, LogWithDecodedArgs, AbiDefinition, RawLog, FunctionAbi, EventAbi, EventParameter, MethodAbi, ConstructorAbi, FallbackAbi, DataItem, ConstructorStateMutability, StateMutability, } from 'ethereum-types'; | ||
export { Web3WrapperErrors, NodeType, CallDataRPC, BlockWithoutTransactionDataRPC, BlockWithTransactionDataRPC, TransactionRPC, TxDataRPC, } from './types'; | ||
export { Web3WrapperErrors, NodeType, CallDataRPC, BlockWithoutTransactionDataRPC, BlockWithTransactionDataRPC, TransactionReceiptStatusRPC, TransactionReceiptRPC, LogEntryRPC, TransactionRPC, TxDataRPC, } from './types'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import { BlockWithoutTransactionData, BlockWithTransactionData, CallData, CallTxDataBase, LogEntry, RawLogEntry, Transaction, TxData } from 'ethereum-types'; | ||
import { BlockWithoutTransactionDataRPC, BlockWithTransactionDataRPC, CallDataRPC, CallTxDataBaseRPC, TransactionRPC, TxDataRPC } from './types'; | ||
import { BlockWithoutTransactionData, BlockWithTransactionData, CallData, CallTxDataBase, LogEntry, RawLogEntry, Transaction, TransactionReceipt, TxData } from 'ethereum-types'; | ||
import { BlockWithoutTransactionDataRPC, BlockWithTransactionDataRPC, CallDataRPC, CallTxDataBaseRPC, TransactionReceiptRPC, TransactionRPC, TxDataRPC } from './types'; | ||
/** | ||
@@ -26,2 +26,8 @@ * Utils to convert ethereum structures from user-space format to RPC format. (marshall/unmarshall) | ||
/** | ||
* Unmarshall transaction receipt | ||
* @param txReceiptRpc transaction receipt to unmarshall | ||
* @return unmarshalled transaction receipt | ||
*/ | ||
unmarshalTransactionReceipt(txReceiptRpc: TransactionReceiptRPC): TransactionReceipt; | ||
/** | ||
* Unmarshall transaction data | ||
@@ -28,0 +34,0 @@ * @param txDataRpc transaction data to unmarshall |
@@ -57,2 +57,11 @@ "use strict"; | ||
/** | ||
* Unmarshall transaction receipt | ||
* @param txReceiptRpc transaction receipt to unmarshall | ||
* @return unmarshalled transaction receipt | ||
*/ | ||
unmarshalTransactionReceipt: function (txReceiptRpc) { | ||
var txReceipt = __assign({}, txReceiptRpc, { blockNumber: utils_2.utils.convertHexToNumber(txReceiptRpc.blockNumber), transactionIndex: utils_2.utils.convertHexToNumber(txReceiptRpc.transactionIndex), cumulativeGasUsed: utils_2.utils.convertHexToNumber(txReceiptRpc.cumulativeGasUsed), gasUsed: utils_2.utils.convertHexToNumber(txReceiptRpc.gasUsed), logs: _.map(txReceiptRpc.logs, exports.marshaller.unmarshalLog.bind(exports.marshaller)) }); | ||
return txReceipt; | ||
}, | ||
/** | ||
* Unmarshall transaction data | ||
@@ -59,0 +68,0 @@ * @param txDataRpc transaction data to unmarshall |
@@ -42,2 +42,26 @@ export declare enum Web3WrapperErrors { | ||
} | ||
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 declare type TransactionReceiptStatusRPC = null | string | 0 | 1; | ||
export interface CallTxDataBaseRPC { | ||
@@ -44,0 +68,0 @@ to?: string; |
@@ -91,7 +91,7 @@ import { AbiDecoder, BigNumber } from '@0x/utils'; | ||
/** | ||
* 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. | ||
*/ | ||
getTransactionReceiptAsync(txHash: string): Promise<TransactionReceipt>; | ||
getTransactionReceiptIfExistsAsync(txHash: string): Promise<TransactionReceipt | undefined>; | ||
/** | ||
@@ -98,0 +98,0 @@ * Retrieves the transaction data for a given transaction |
@@ -264,9 +264,9 @@ "use strict"; | ||
/** | ||
* 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. | ||
*/ | ||
Web3Wrapper.prototype.getTransactionReceiptAsync = function (txHash) { | ||
Web3Wrapper.prototype.getTransactionReceiptIfExistsAsync = function (txHash) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var transactionReceipt; | ||
var transactionReceiptRpc, transactionReceipt; | ||
return __generator(this, function (_a) { | ||
@@ -281,7 +281,12 @@ switch (_a.label) { | ||
case 1: | ||
transactionReceipt = _a.sent(); | ||
if (!_.isNull(transactionReceipt)) { | ||
transactionReceipt.status = Web3Wrapper._normalizeTxReceiptStatus(transactionReceipt.status); | ||
transactionReceiptRpc = _a.sent(); | ||
if (!_.isNull(transactionReceiptRpc)) { | ||
transactionReceiptRpc.status = Web3Wrapper._normalizeTxReceiptStatus(transactionReceiptRpc.status); | ||
transactionReceipt = marshaller_1.marshaller.unmarshalTransactionReceipt(transactionReceiptRpc); | ||
return [2 /*return*/, transactionReceipt]; | ||
} | ||
return [2 /*return*/, transactionReceipt]; | ||
else { | ||
return [2 /*return*/, undefined]; | ||
} | ||
return [2 /*return*/]; | ||
} | ||
@@ -822,6 +827,6 @@ }); | ||
} | ||
return [4 /*yield*/, this.getTransactionReceiptAsync(txHash)]; | ||
return [4 /*yield*/, this.getTransactionReceiptIfExistsAsync(txHash)]; | ||
case 1: | ||
transactionReceipt = _a.sent(); | ||
if (!_.isNull(transactionReceipt) && !_.isNull(transactionReceipt.blockNumber)) { | ||
if (!_.isUndefined(transactionReceipt) && !_.isNull(transactionReceipt.blockNumber)) { | ||
logsWithDecodedArgs = _.map(transactionReceipt.logs, this.abiDecoder.tryToDecodeLogOrNoop.bind(this.abiDecoder)); | ||
@@ -845,6 +850,6 @@ transactionReceiptWithDecodedLogArgs = __assign({}, transactionReceipt, { logs: logsWithDecodedArgs }); | ||
} | ||
return [4 /*yield*/, this.getTransactionReceiptAsync(txHash)]; | ||
return [4 /*yield*/, this.getTransactionReceiptIfExistsAsync(txHash)]; | ||
case 1: | ||
transactionReceipt = _a.sent(); | ||
if (!_.isNull(transactionReceipt)) { | ||
if (!_.isUndefined(transactionReceipt)) { | ||
utils_1.intervalUtils.clearAsyncExcludingInterval(intervalId); | ||
@@ -851,0 +856,0 @@ logsWithDecodedArgs = _.map(transactionReceipt.logs, this.abiDecoder.tryToDecodeLogOrNoop.bind(this.abiDecoder)); |
@@ -210,2 +210,27 @@ "use strict"; | ||
}); | ||
describe('#getTransactionReceiptAsync/awaitTransactionSuccessAsync', function () { | ||
it('get block number', function () { return __awaiter(_this, void 0, void 0, function () { | ||
var payload, txHash, receiptIfExists, receipt; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
payload = { from: addresses[0], to: addresses[1], value: 1 }; | ||
return [4 /*yield*/, web3Wrapper.sendTransactionAsync(payload)]; | ||
case 1: | ||
txHash = _a.sent(); | ||
return [4 /*yield*/, web3Wrapper.awaitTransactionSuccessAsync(txHash)]; | ||
case 2: | ||
_a.sent(); | ||
return [4 /*yield*/, web3Wrapper.getTransactionReceiptIfExistsAsync(txHash)]; | ||
case 3: | ||
receiptIfExists = _a.sent(); | ||
expect(receiptIfExists).to.not.be.undefined(); | ||
receipt = receiptIfExists; | ||
expect(receipt.transactionIndex).to.be.a('number'); | ||
expect(receipt.transactionHash).to.be.equal(txHash); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
}); | ||
describe('#getBlockIfExistsAsync', function () { | ||
@@ -212,0 +237,0 @@ it('gets block when supplied a valid BlockParamLiteral value', function () { return __awaiter(_this, void 0, void 0, function () { |
{ | ||
"name": "@0x/web3-wrapper", | ||
"version": "3.1.4", | ||
"version": "3.1.5", | ||
"engines": { | ||
@@ -13,2 +13,3 @@ "node": ">=6.12" | ||
"build:ci": "yarn build", | ||
"watch_without_deps": "tsc -w", | ||
"clean": "shx rm -rf lib generated_docs", | ||
@@ -57,6 +58,6 @@ "lint": "tslint --format stylish --project .", | ||
"dependencies": { | ||
"@0x/assert": "^1.0.17", | ||
"@0x/json-schemas": "^2.1.1", | ||
"@0x/assert": "^1.0.18", | ||
"@0x/json-schemas": "^2.1.2", | ||
"@0x/typescript-typings": "^3.0.4", | ||
"@0x/utils": "^2.0.5", | ||
"@0x/utils": "^2.0.6", | ||
"ethereum-types": "^1.1.2", | ||
@@ -70,3 +71,3 @@ "ethereumjs-util": "^5.1.1", | ||
}, | ||
"gitHead": "fe1b7f15e8531615a54e46581cb734e635d3c755" | ||
"gitHead": "f46a49fd13c88dd86c9661d76bace18844642c04" | ||
} |
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'; | ||
@@ -101,2 +101,14 @@ import * as _ from 'lodash'; | ||
}); | ||
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', () => { | ||
@@ -103,0 +115,0 @@ it('gets block when supplied a valid BlockParamLiteral value', async () => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
171791
37
2622
1
Updated@0x/assert@^1.0.18
Updated@0x/json-schemas@^2.1.2
Updated@0x/utils@^2.0.6