Skip to content

Commit

Permalink
Merge pull request ethereum#3265 from ethereum/transactionReceipt-inj…
Browse files Browse the repository at this point in the history
…ection

Transaction receipt contractAddress injection
  • Loading branch information
evertonfraga authored Nov 16, 2017
2 parents ed1578a + ad3c0e2 commit c58353f
Show file tree
Hide file tree
Showing 4 changed files with 319 additions and 11 deletions.
2 changes: 1 addition & 1 deletion modules/ipc/methods/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = class BaseProcessor {

const ret = await conn.socket.send(payload, {
fullResult: true,
})
});

return ret.result;
}
Expand Down
60 changes: 60 additions & 0 deletions modules/ipc/methods/eth_getTransactionReceipt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const _ = global._;
const BaseProcessor = require('./base');
const eth = require('ethereumjs-util');

/**
* Process method: eth_getTransactionReceipt
*/

module.exports = class extends BaseProcessor {

sanitizeRequestPayload(conn, payload, isPartOfABatch) {
return super.sanitizeRequestPayload(conn, payload, isPartOfABatch);
}

async exec(conn, payload) {
const txHash = payload.params[0];

// Sends regular eth_getTransactionReceipt request
const ret = await conn.socket.send(payload, {
fullResult: true
});

// If that contains a contractAddress already, fine.
if (ret.result.result.contractAddress != null) {
return ret.result;
}

// Due to a geth's light client v1 bug, it does not return
// contractAddress value on the receipts. Let's fix that.
// 1. GET TRANSACTION from AND nonce VALUES
const transactionInfo = await conn.socket.send({
jsonrpc: '2.0',
id: _.uuid(),
method: 'eth_getTransactionByHash',
params: [txHash]
}, { fullResult: true });


const fromAddress = transactionInfo.result.result.from;
const nonce = parseInt(transactionInfo.result.result.nonce, 16);
const possibleContractAddress = `0x${eth.generateAddress(fromAddress, nonce).toString('hex')}`;


// 2. GET CODE FROM ADDRESS
const contractCode = await conn.socket.send({
jsonrpc: '2.0',
id: _.uuid(),
method: 'eth_getCode',
params: [possibleContractAddress, 'latest']
}, { fullResult: true });
const contractCodeResult = contractCode.result.result;

// 3. IF IT EXISTS, ASSIGN TO RETURN VALUE
if (contractCodeResult && contractCodeResult.length > 2) {
ret.result.result.contractAddress = possibleContractAddress;
}

return ret.result;
}
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"ethereum-client-binaries": "^1.6.1",
"ethereum-keyfile-recognizer": "^1.0.2",
"ethereumjs-abi": "^0.6.3",
"ethereumjs-util": "^5.1.2",
"fs-promise": "^2.0.0",
"got": "^6.7.1",
"i18next": "^7.1.3",
Expand Down
Loading

0 comments on commit c58353f

Please sign in to comment.