refactor to make address conversion in runTx instead of callers

pull/1/head
Iuri Matias 5 years ago
parent 3d8dceb62e
commit e483fa3c3f
  1. 3
      src/app/tabs/runTab/model/recorder.js
  2. 41
      src/blockchain/blockchain.js

@ -248,12 +248,11 @@ class Recorder {
record.data = { dataHex: data.data, funArgs: tx.record.parameters, funAbi: fnABI, contractBytecode: tx.record.bytecode, contractName: tx.record.contractName, timestamp: tx.timestamp }
self.blockchain.runTx(record, confirmationCb, continueCb, promptCb,
function (err, txResult) {
function (err, txResult, rawAddress) {
if (err) {
console.error(err)
return logCallBack(err + '. Execution failed at ' + index)
}
const rawAddress = self.blockchain.getAddressFromTransactionResult(txResult)
if (rawAddress) {
const stringAddress = self.addressToString(rawAddress)
const address = ethutil.toChecksumAddress(stringAddress)

@ -118,21 +118,13 @@ class Blockchain {
}
this.runTx({ data: data, useCall: false }, confirmationCb, continueCb, promptCb,
(error, txResult) => {
(error, txResult, address) => {
if (error) {
return finalCb(`creation of ${selectedContract.name} errored: ${error}`)
}
const isVM = this.executionContext.isVM()
if (isVM) {
const vmError = txExecution.checkVMError(txResult)
if (vmError.error) {
return finalCb(vmError.message)
}
}
if (txResult.result.status && txResult.result.status === '0x0') {
return finalCb(`creation of ${selectedContract.name} errored: transaction execution failed`)
}
const address = isVM ? txResult.result.createdAddress : txResult.result.contractAddress
finalCb(null, selectedContract, address)
}
)
@ -360,18 +352,7 @@ class Blockchain {
*/
callFunction (to, data, funAbi, confirmationCb, continueCb, promptCb, callback) {
const useCall = funAbi.stateMutability === 'view' || funAbi.stateMutability === 'pure'
this.runTx({to, data, useCall}, confirmationCb, continueCb, promptCb, (error, txResult) => {
const isVM = this.executionContext.isVM()
if (isVM) {
const vmError = txExecution.checkVMError(txResult)
if (vmError.error) {
return callback(vmError.message)
}
}
// see universaldapp.js line 660 => 700 to check possible values of txResult (error case)
callback(error, txResult)
})
this.runTx({to, data, useCall}, confirmationCb, continueCb, promptCb, callback)
}
/**
@ -470,7 +451,23 @@ class Blockchain {
}
)
}
], cb)
],
(error, txResult) => {
const isVM = this.executionContext.isVM()
if (isVM) {
const vmError = txExecution.checkVMError(txResult)
if (vmError.error) {
return cb(vmError.message)
}
}
let address = null
if (txResult && txResult.result) {
address = isVM ? txResult.result.createdAddress : txResult.result.contractAddress
}
cb(error, txResult, address)
})
}
}

Loading…
Cancel
Save