Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Transaction receipt contractAddress injection #3265

Merged
merged 2 commits into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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