Skip to content

Commit

Permalink
added status property to receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
frozeman committed Apr 13, 2018
1 parent 1ebfbd9 commit 85f4534
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 32 deletions.
2 changes: 2 additions & 0 deletions docs/web3-eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,7 @@ Returns

``Promise`` returns ``Object`` - A transaction receipt object, or ``null`` when no receipt was found:

- ``status`` - ``Boolean``: ``TRUE`` if the transaction was susccessfull, ``FALSE``, if the EVM reverted the transaction.
- ``blockHash`` 32 Bytes - ``String``: Hash of the block where this transaction was in.
- ``blockNumber`` - ``Number``: Block number where this transaction was in.
- ``transactionHash`` 32 Bytes - ``String``: Hash of the transaction.
Expand All @@ -904,6 +905,7 @@ Example
.then(console.log);
> {
"status": true,
"transactionHash": "0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b",
"transactionIndex": 0,
"blockHash": "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46",
Expand Down
4 changes: 4 additions & 0 deletions packages/web3-core-helpers/src/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ var outputTransactionReceiptFormatter = function (receipt){
receipt.contractAddress = utils.toChecksumAddress(receipt.contractAddress);
}

if(typeof receipt.status !== 'undefined') {
receipt.status = Boolean(parseInt(receipt.status));
}

return receipt;
};

Expand Down
72 changes: 40 additions & 32 deletions packages/web3-core-method/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
if (!isContractDeployment && !promiseResolved) {

if(!receipt.outOfGas &&
(!gasProvided || gasProvided !== receipt.gasUsed)) {
(!gasProvided || gasProvided !== receipt.gasUsed) &&
(receipt.status === true || receipt.status === '0x1' || typeof receipt.status === 'undefined')) {
defer.eventEmitter.emit('receipt', receipt);
defer.resolve(receipt);

Expand All @@ -361,7 +362,14 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
if(receipt) {
receipt = JSON.stringify(receipt, null, 2);
}
utils._fireError(new Error("Transaction ran out of gas. Please provide more gas:\n"+ receipt), defer.eventEmitter, defer.reject);
if (receipt.status === false || receipt.status === '0x0') {

This comment has been minimized.

Copy link
@Xcrux

Xcrux Apr 22, 2018

this if will never be true because receipt is the result of JSON.stringify()

utils._fireError(new Error("Transaction has been reverted by the EVM:\n" + receipt),
defer.eventEmitter, defer.reject);
} else {
utils._fireError(
new Error("Transaction ran out of gas. Please provide more gas:\n" + receipt),
defer.eventEmitter, defer.reject);
}
}

if (canUnsubscribe) {
Expand Down Expand Up @@ -400,34 +408,34 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
}
};

// start watching for confirmation depending on the support features of the provider
var startWatching = function(existingReceipt) {
// if provider allows PUB/SUB
if (_.isFunction(this.requestManager.provider.on)) {
_ethereumCall.subscribe('newBlockHeaders', checkConfirmation.bind(null, existingReceipt, false));
} else {
intervalId = setInterval(checkConfirmation.bind(null, existingReceipt, true), 1000);
}
}.bind(this);


// first check if we already have a confirmed transaction
_ethereumCall.getTransactionReceipt(result)
.then(function(receipt) {
if (receipt && receipt.blockHash) {
if (defer.eventEmitter.listeners('confirmation').length > 0) {
// We must keep on watching for new Blocks, if a confirmation listener is present
startWatching(receipt);
}
checkConfirmation(receipt, false);

} else if (!promiseResolved) {
startWatching();
}
})
.catch(function(){
if (!promiseResolved) startWatching();
});
// start watching for confirmation depending on the support features of the provider
var startWatching = function(existingReceipt) {
// if provider allows PUB/SUB
if (_.isFunction(this.requestManager.provider.on)) {
_ethereumCall.subscribe('newBlockHeaders', checkConfirmation.bind(null, existingReceipt, false));
} else {
intervalId = setInterval(checkConfirmation.bind(null, existingReceipt, true), 1000);
}
}.bind(this);


// first check if we already have a confirmed transaction
_ethereumCall.getTransactionReceipt(result)
.then(function(receipt) {
if (receipt && receipt.blockHash) {
if (defer.eventEmitter.listeners('confirmation').length > 0) {
// We must keep on watching for new Blocks, if a confirmation listener is present
startWatching(receipt);
}
checkConfirmation(receipt, false);

} else if (!promiseResolved) {
startWatching();
}
})
.catch(function(){
if (!promiseResolved) startWatching();
});

};

Expand Down Expand Up @@ -493,7 +501,7 @@ Method.prototype.buildCall = function() {

}

// return PROMIEVENT
// return PROMIEVENT
} else {
defer.eventEmitter.emit('transactionHash', result);

Expand Down Expand Up @@ -530,7 +538,7 @@ Method.prototype.buildCall = function() {
return method.accounts.signTransaction(_.omit(tx, 'from'), wallet.privateKey).then(sendSignedTx);
}

// ETH_SIGN
// ETH_SIGN
} else if (payload.method === 'eth_sign') {
var data = payload.params[1];
wallet = getWallet(payload.params[0], method.accounts);
Expand Down
48 changes: 48 additions & 0 deletions test/eth.getTransactionReceipt.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,54 @@ var tests = [{
result: txResult,
formattedResult: formattedTxResult,
call: 'eth_'+ method
},{
args: ['0xff960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265'],
formattedArgs: ['0xff960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265'],
result: {
"status": "0x1",
"blockHash": "0x6fd9e2a26ab",
"blockNumber": "0x15df",
"transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"transactionIndex": "0x1",
"contractAddress":"0x407d73d8a49eeb85d32cf465507dd71d507100c1",
"cumulativeGasUsed":"0x7f110",
"gasUsed": "0x7f110",
},
formattedResult: {
"status": true,
"blockHash": "0x6fd9e2a26ab",
"blockNumber": 5599,
"transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"transactionIndex": 1,
"contractAddress":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address
"cumulativeGasUsed": 520464,
"gasUsed": 520464,
},
call: 'eth_'+ method
},{
args: ['0xdd960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265'],
formattedArgs: ['0xdd960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265'],
result: {
"status": "0x0",
"blockHash": "0x6fd9e2a26ab",
"blockNumber": "0x15df",
"transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"transactionIndex": "0x10",
"contractAddress":"0x407d73d8a49eeb85d32cf465507dd71d507100c1",
"cumulativeGasUsed":"0x7f110",
"gasUsed": "0x7f110",
},
formattedResult: {
"status": false,
"blockHash": "0x6fd9e2a26ab",
"blockNumber": 5599,
"transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"transactionIndex": 16,
"contractAddress":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address
"cumulativeGasUsed": 520464,
"gasUsed": 520464,
},
call: 'eth_'+ method
}];


Expand Down

0 comments on commit 85f4534

Please sign in to comment.