mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-23 11:38:12 +00:00
Merge pull request #254 from ethereum/getReceipt
add getTransactionReceipt method
This commit is contained in:
commit
ea0e48d700
42
dist/web3-light.js
vendored
42
dist/web3-light.js
vendored
@ -2162,6 +2162,13 @@ var getTransactionFromBlock = new Method({
|
||||
outputFormatter: formatters.outputTransactionFormatter
|
||||
});
|
||||
|
||||
var getTransactionReceipt = new Method({
|
||||
name: 'getTransactionReceipt',
|
||||
call: 'eth_getTransactionReceipt',
|
||||
params: 1,
|
||||
outputFormatter: formatters.outputTransactionReceiptFormatter
|
||||
});
|
||||
|
||||
var getTransactionCount = new Method({
|
||||
name: 'getTransactionCount',
|
||||
call: 'eth_getTransactionCount',
|
||||
@ -2240,6 +2247,7 @@ var methods = [
|
||||
getBlockUncleCount,
|
||||
getTransaction,
|
||||
getTransactionFromBlock,
|
||||
getTransactionReceipt,
|
||||
getTransactionCount,
|
||||
call,
|
||||
estimateGas,
|
||||
@ -2798,8 +2806,8 @@ var inputTransactionFormatter = function (options){
|
||||
* Formats the output of a transaction to its proper values
|
||||
*
|
||||
* @method outputTransactionFormatter
|
||||
* @param {Object} transaction
|
||||
* @returns {Object} transaction
|
||||
* @param {Object} tx
|
||||
* @returns {Object}
|
||||
*/
|
||||
var outputTransactionFormatter = function (tx){
|
||||
if(tx.blockNumber !== null)
|
||||
@ -2813,12 +2821,36 @@ var outputTransactionFormatter = function (tx){
|
||||
return tx;
|
||||
};
|
||||
|
||||
/**
|
||||
* Formats the output of a transaction receipt to its proper values
|
||||
*
|
||||
* @method outputTransactionReceiptFormatter
|
||||
* @param {Object} receipt
|
||||
* @returns {Object}
|
||||
*/
|
||||
var outputTransactionReceiptFormatter = function (receipt){
|
||||
if(receipt.blockNumber !== null)
|
||||
receipt.blockNumber = utils.toDecimal(receipt.blockNumber);
|
||||
if(receipt.transactionIndex !== null)
|
||||
receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex);
|
||||
receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed);
|
||||
receipt.gasUsed = utils.toDecimal(receipt.gasUsed);
|
||||
|
||||
if(utils.isArray(receipt.logs)) {
|
||||
receipt.logs = receipt.logs.map(function(log){
|
||||
return outputLogFormatter(log);
|
||||
});
|
||||
}
|
||||
|
||||
return receipt;
|
||||
};
|
||||
|
||||
/**
|
||||
* Formats the output of a block to its proper values
|
||||
*
|
||||
* @method outputBlockFormatter
|
||||
* @param {Object} block object
|
||||
* @returns {Object} block object
|
||||
* @param {Object} block
|
||||
* @returns {Object}
|
||||
*/
|
||||
var outputBlockFormatter = function(block) {
|
||||
|
||||
@ -2926,6 +2958,7 @@ module.exports = {
|
||||
inputPostFormatter: inputPostFormatter,
|
||||
outputBigNumberFormatter: outputBigNumberFormatter,
|
||||
outputTransactionFormatter: outputTransactionFormatter,
|
||||
outputTransactionReceiptFormatter: outputTransactionReceiptFormatter,
|
||||
outputBlockFormatter: outputBlockFormatter,
|
||||
outputLogFormatter: outputLogFormatter,
|
||||
outputPostFormatter: outputPostFormatter
|
||||
@ -3209,7 +3242,6 @@ HttpProvider.prototype.send = function (payload) {
|
||||
|
||||
request.open('POST', this.host, false);
|
||||
request.setRequestHeader('Content-type','application/json');
|
||||
request.setRequestHeader('Connection','Keep-Alive');
|
||||
|
||||
try {
|
||||
request.send(JSON.stringify(payload));
|
||||
|
4
dist/web3-light.min.js
vendored
4
dist/web3-light.min.js
vendored
File diff suppressed because one or more lines are too long
42
dist/web3.js
vendored
42
dist/web3.js
vendored
@ -2162,6 +2162,13 @@ var getTransactionFromBlock = new Method({
|
||||
outputFormatter: formatters.outputTransactionFormatter
|
||||
});
|
||||
|
||||
var getTransactionReceipt = new Method({
|
||||
name: 'getTransactionReceipt',
|
||||
call: 'eth_getTransactionReceipt',
|
||||
params: 1,
|
||||
outputFormatter: formatters.outputTransactionReceiptFormatter
|
||||
});
|
||||
|
||||
var getTransactionCount = new Method({
|
||||
name: 'getTransactionCount',
|
||||
call: 'eth_getTransactionCount',
|
||||
@ -2240,6 +2247,7 @@ var methods = [
|
||||
getBlockUncleCount,
|
||||
getTransaction,
|
||||
getTransactionFromBlock,
|
||||
getTransactionReceipt,
|
||||
getTransactionCount,
|
||||
call,
|
||||
estimateGas,
|
||||
@ -2798,8 +2806,8 @@ var inputTransactionFormatter = function (options){
|
||||
* Formats the output of a transaction to its proper values
|
||||
*
|
||||
* @method outputTransactionFormatter
|
||||
* @param {Object} transaction
|
||||
* @returns {Object} transaction
|
||||
* @param {Object} tx
|
||||
* @returns {Object}
|
||||
*/
|
||||
var outputTransactionFormatter = function (tx){
|
||||
if(tx.blockNumber !== null)
|
||||
@ -2813,12 +2821,36 @@ var outputTransactionFormatter = function (tx){
|
||||
return tx;
|
||||
};
|
||||
|
||||
/**
|
||||
* Formats the output of a transaction receipt to its proper values
|
||||
*
|
||||
* @method outputTransactionReceiptFormatter
|
||||
* @param {Object} receipt
|
||||
* @returns {Object}
|
||||
*/
|
||||
var outputTransactionReceiptFormatter = function (receipt){
|
||||
if(receipt.blockNumber !== null)
|
||||
receipt.blockNumber = utils.toDecimal(receipt.blockNumber);
|
||||
if(receipt.transactionIndex !== null)
|
||||
receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex);
|
||||
receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed);
|
||||
receipt.gasUsed = utils.toDecimal(receipt.gasUsed);
|
||||
|
||||
if(utils.isArray(receipt.logs)) {
|
||||
receipt.logs = receipt.logs.map(function(log){
|
||||
return outputLogFormatter(log);
|
||||
});
|
||||
}
|
||||
|
||||
return receipt;
|
||||
};
|
||||
|
||||
/**
|
||||
* Formats the output of a block to its proper values
|
||||
*
|
||||
* @method outputBlockFormatter
|
||||
* @param {Object} block object
|
||||
* @returns {Object} block object
|
||||
* @param {Object} block
|
||||
* @returns {Object}
|
||||
*/
|
||||
var outputBlockFormatter = function(block) {
|
||||
|
||||
@ -2926,6 +2958,7 @@ module.exports = {
|
||||
inputPostFormatter: inputPostFormatter,
|
||||
outputBigNumberFormatter: outputBigNumberFormatter,
|
||||
outputTransactionFormatter: outputTransactionFormatter,
|
||||
outputTransactionReceiptFormatter: outputTransactionReceiptFormatter,
|
||||
outputBlockFormatter: outputBlockFormatter,
|
||||
outputLogFormatter: outputLogFormatter,
|
||||
outputPostFormatter: outputPostFormatter
|
||||
@ -3209,7 +3242,6 @@ HttpProvider.prototype.send = function (payload) {
|
||||
|
||||
request.open('POST', this.host, false);
|
||||
request.setRequestHeader('Content-type','application/json');
|
||||
request.setRequestHeader('Connection','Keep-Alive');
|
||||
|
||||
try {
|
||||
request.send(JSON.stringify(payload));
|
||||
|
87
dist/web3.js.map
vendored
87
dist/web3.js.map
vendored
File diff suppressed because one or more lines are too long
7
dist/web3.min.js
vendored
7
dist/web3.min.js
vendored
File diff suppressed because one or more lines are too long
@ -152,6 +152,13 @@ var getTransactionFromBlock = new Method({
|
||||
outputFormatter: formatters.outputTransactionFormatter
|
||||
});
|
||||
|
||||
var getTransactionReceipt = new Method({
|
||||
name: 'getTransactionReceipt',
|
||||
call: 'eth_getTransactionReceipt',
|
||||
params: 1,
|
||||
outputFormatter: formatters.outputTransactionReceiptFormatter
|
||||
});
|
||||
|
||||
var getTransactionCount = new Method({
|
||||
name: 'getTransactionCount',
|
||||
call: 'eth_getTransactionCount',
|
||||
@ -230,6 +237,7 @@ var methods = [
|
||||
getBlockUncleCount,
|
||||
getTransaction,
|
||||
getTransactionFromBlock,
|
||||
getTransactionReceipt,
|
||||
getTransactionCount,
|
||||
call,
|
||||
estimateGas,
|
||||
|
@ -85,8 +85,8 @@ var inputTransactionFormatter = function (options){
|
||||
* Formats the output of a transaction to its proper values
|
||||
*
|
||||
* @method outputTransactionFormatter
|
||||
* @param {Object} transaction
|
||||
* @returns {Object} transaction
|
||||
* @param {Object} tx
|
||||
* @returns {Object}
|
||||
*/
|
||||
var outputTransactionFormatter = function (tx){
|
||||
if(tx.blockNumber !== null)
|
||||
@ -100,12 +100,36 @@ var outputTransactionFormatter = function (tx){
|
||||
return tx;
|
||||
};
|
||||
|
||||
/**
|
||||
* Formats the output of a transaction receipt to its proper values
|
||||
*
|
||||
* @method outputTransactionReceiptFormatter
|
||||
* @param {Object} receipt
|
||||
* @returns {Object}
|
||||
*/
|
||||
var outputTransactionReceiptFormatter = function (receipt){
|
||||
if(receipt.blockNumber !== null)
|
||||
receipt.blockNumber = utils.toDecimal(receipt.blockNumber);
|
||||
if(receipt.transactionIndex !== null)
|
||||
receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex);
|
||||
receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed);
|
||||
receipt.gasUsed = utils.toDecimal(receipt.gasUsed);
|
||||
|
||||
if(utils.isArray(receipt.logs)) {
|
||||
receipt.logs = receipt.logs.map(function(log){
|
||||
return outputLogFormatter(log);
|
||||
});
|
||||
}
|
||||
|
||||
return receipt;
|
||||
};
|
||||
|
||||
/**
|
||||
* Formats the output of a block to its proper values
|
||||
*
|
||||
* @method outputBlockFormatter
|
||||
* @param {Object} block object
|
||||
* @returns {Object} block object
|
||||
* @param {Object} block
|
||||
* @returns {Object}
|
||||
*/
|
||||
var outputBlockFormatter = function(block) {
|
||||
|
||||
@ -213,6 +237,7 @@ module.exports = {
|
||||
inputPostFormatter: inputPostFormatter,
|
||||
outputBigNumberFormatter: outputBigNumberFormatter,
|
||||
outputTransactionFormatter: outputTransactionFormatter,
|
||||
outputTransactionReceiptFormatter: outputTransactionReceiptFormatter,
|
||||
outputBlockFormatter: outputBlockFormatter,
|
||||
outputLogFormatter: outputLogFormatter,
|
||||
outputPostFormatter: outputPostFormatter
|
||||
|
@ -37,7 +37,6 @@ HttpProvider.prototype.send = function (payload) {
|
||||
|
||||
request.open('POST', this.host, false);
|
||||
request.setRequestHeader('Content-type','application/json');
|
||||
request.setRequestHeader('Connection','Keep-Alive');
|
||||
|
||||
try {
|
||||
request.send(JSON.stringify(payload));
|
||||
|
@ -6,7 +6,6 @@ var testMethod = require('./helpers/test.method.js');
|
||||
var method = 'getTransaction';
|
||||
|
||||
var txResult = {
|
||||
"status": "mined",
|
||||
"hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
|
||||
"nonce":"0x5",
|
||||
"blockHash": "0x6fd9e2a26ab",
|
||||
@ -20,7 +19,6 @@ var txResult = {
|
||||
"input":"0x603880600c6000396000f30060"
|
||||
};
|
||||
var formattedTxResult = {
|
||||
"status": "mined",
|
||||
"hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
|
||||
"nonce":5,
|
||||
"blockHash": "0x6fd9e2a26ab",
|
||||
|
70
test/web3.eth.getTransactionReceipt.js
Normal file
70
test/web3.eth.getTransactionReceipt.js
Normal file
@ -0,0 +1,70 @@
|
||||
var chai = require('chai');
|
||||
var web3 = require('../index');
|
||||
var BigNumber = require('bignumber.js');
|
||||
var testMethod = require('./helpers/test.method.js');
|
||||
|
||||
var method = 'getTransactionReceipt';
|
||||
|
||||
var txResult = {
|
||||
"blockHash": "0x6fd9e2a26ab",
|
||||
"blockNumber": "0x15df",
|
||||
"transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
|
||||
"transactionIndex": "0x1",
|
||||
"contractAddress":"0x407d73d8a49eeb85d32cf465507dd71d507100c1",
|
||||
"cumulativeGasUsed":"0x7f110",
|
||||
"gasUsed": "0x7f110",
|
||||
"logs": [{
|
||||
transactionIndex: '0x3e8',
|
||||
logIndex: '0x3e8',
|
||||
blockNumber: '0x3e8',
|
||||
transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
data: '0x7b2274657374223a2274657374227',
|
||||
topics: ['0x68656c6c6f','0x6d79746f70696373']
|
||||
},{
|
||||
transactionIndex: null,
|
||||
logIndex: null,
|
||||
blockNumber: null,
|
||||
transactionHash: null,
|
||||
blockHash: null,
|
||||
data: '0x7b2274657374223a2274657374227',
|
||||
topics: ['0x68656c6c6f','0x6d79746f70696373']
|
||||
}]
|
||||
};
|
||||
var formattedTxResult = {
|
||||
"blockHash": "0x6fd9e2a26ab",
|
||||
"blockNumber": 5599,
|
||||
"transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
|
||||
"transactionIndex": 1,
|
||||
"contractAddress":"0x407d73d8a49eeb85d32cf465507dd71d507100c1",
|
||||
"cumulativeGasUsed": 520464,
|
||||
"gasUsed": 520464,
|
||||
"logs": [{
|
||||
transactionIndex: 1000,
|
||||
logIndex: 1000,
|
||||
blockNumber: 1000,
|
||||
transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
data: '0x7b2274657374223a2274657374227',
|
||||
topics: ['0x68656c6c6f','0x6d79746f70696373']
|
||||
},{
|
||||
transactionIndex: null,
|
||||
logIndex: null,
|
||||
blockNumber: null,
|
||||
transactionHash: null,
|
||||
blockHash: null,
|
||||
data: '0x7b2274657374223a2274657374227',
|
||||
topics: ['0x68656c6c6f','0x6d79746f70696373']
|
||||
}]
|
||||
};
|
||||
|
||||
var tests = [{
|
||||
args: ['0x2dbab4c0612bf9caf4c195085547dc0612bf9caf4c1950855'],
|
||||
formattedArgs: ['0x2dbab4c0612bf9caf4c195085547dc0612bf9caf4c1950855'],
|
||||
result: txResult,
|
||||
formattedResult: formattedTxResult,
|
||||
call: 'eth_'+ method
|
||||
}];
|
||||
|
||||
testMethod.runTests('eth', method, tests);
|
||||
|
Loading…
x
Reference in New Issue
Block a user