forked from ethereum/mist
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ethereum#3265 from ethereum/transactionReceipt-inj…
…ection Transaction receipt contractAddress injection
- Loading branch information
Showing
4 changed files
with
319 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.