Merge pull request #848 from ethereum/fixReceipt

Use tx and receipt when resolving / listening
pull/7/head
yann300 7 years ago committed by GitHub
commit e5539241a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 33
      remix-lib/src/execution/txListener.js

@ -52,7 +52,7 @@ class TxListener {
} }
addExecutionCosts(txResult, call) addExecutionCosts(txResult, call)
this._resolveTx(call, (error, resolvedData) => { this._resolveTx(call, call, (error, resolvedData) => {
if (!error) { if (!error) {
this.event.trigger('newCall', [call]) this.event.trigger('newCall', [call])
} }
@ -200,14 +200,14 @@ class TxListener {
_resolve (transactions, callback) { _resolve (transactions, callback) {
async.each(transactions, (tx, cb) => { async.each(transactions, (tx, cb) => {
executionContext.web3().eth.getTransactionReceipt(tx.hash, (error, receipt) => { this._api.resolveReceipt(tx, (error, receipt) => {
if (error) return cb(error) if (error) return cb(error)
this._resolveTx(receipt, (error, resolvedData) => { this._resolveTx(tx, receipt, (error, resolvedData) => {
if (error) cb(error) if (error) cb(error)
if (resolvedData) { if (resolvedData) {
this.event.trigger('txResolved', [receipt, resolvedData]) this.event.trigger('txResolved', [tx, receipt, resolvedData])
} }
this.event.trigger('newTransaction', [receipt]) this.event.trigger('newTransaction', [tx, receipt])
cb() cb()
}) })
}) })
@ -216,10 +216,11 @@ class TxListener {
}) })
} }
_resolveTx (tx, cb) { _resolveTx (tx, receipt, cb) {
var contracts = this._api.contracts() var contracts = this._api.contracts()
if (!contracts) return cb() if (!contracts) return cb()
var contractName var contractName
var fun
if (!tx.to || tx.to === '0x0') { // testrpc returns 0x0 in that case if (!tx.to || tx.to === '0x0') { // testrpc returns 0x0 in that case
// contract creation / resolve using the creation bytes code // contract creation / resolve using the creation bytes code
// if web3: we have to call getTransactionReceipt to get the created address // if web3: we have to call getTransactionReceipt to get the created address
@ -227,17 +228,13 @@ class TxListener {
var code = tx.input var code = tx.input
contractName = this._tryResolveContract(code, contracts, true) contractName = this._tryResolveContract(code, contracts, true)
if (contractName) { if (contractName) {
this._api.resolveReceipt(tx, (error, receipt) => { var address = receipt.contractAddress
if (error) return cb(error) this._resolvedContracts[address] = contractName
var address = receipt.contractAddress fun = this._resolveFunction(contractName, contracts, tx, true)
this._resolvedContracts[address] = contractName if (this._resolvedTransactions[tx.hash]) {
var fun = this._resolveFunction(contractName, contracts, tx, true) this._resolvedTransactions[tx.hash].contractAddress = address
if (this._resolvedTransactions[tx.hash]) { }
this._resolvedTransactions[tx.hash].contractAddress = address return cb(null, {to: null, contractName: contractName, function: fun, creationAddress: address})
}
return cb(null, {to: null, contractName: contractName, function: fun, creationAddress: address})
})
return
} }
return cb() return cb()
} else { } else {
@ -259,7 +256,7 @@ class TxListener {
return return
} }
if (contractName) { if (contractName) {
var fun = this._resolveFunction(contractName, contracts, tx, false) fun = this._resolveFunction(contractName, contracts, tx, false)
return cb(null, {to: tx.to, contractName: contractName, function: fun}) return cb(null, {to: tx.to, contractName: contractName, function: fun})
} }
return cb() return cb()

Loading…
Cancel
Save