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 } 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, self.blockchain.runTx(record, confirmationCb, continueCb, promptCb,
function (err, txResult) { function (err, txResult, rawAddress) {
if (err) { if (err) {
console.error(err) console.error(err)
return logCallBack(err + '. Execution failed at ' + index) return logCallBack(err + '. Execution failed at ' + index)
} }
const rawAddress = self.blockchain.getAddressFromTransactionResult(txResult)
if (rawAddress) { if (rawAddress) {
const stringAddress = self.addressToString(rawAddress) const stringAddress = self.addressToString(rawAddress)
const address = ethutil.toChecksumAddress(stringAddress) const address = ethutil.toChecksumAddress(stringAddress)

@ -118,21 +118,13 @@ class Blockchain {
} }
this.runTx({ data: data, useCall: false }, confirmationCb, continueCb, promptCb, this.runTx({ data: data, useCall: false }, confirmationCb, continueCb, promptCb,
(error, txResult) => { (error, txResult, address) => {
if (error) { if (error) {
return finalCb(`creation of ${selectedContract.name} errored: ${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') { if (txResult.result.status && txResult.result.status === '0x0') {
return finalCb(`creation of ${selectedContract.name} errored: transaction execution failed`) return finalCb(`creation of ${selectedContract.name} errored: transaction execution failed`)
} }
const address = isVM ? txResult.result.createdAddress : txResult.result.contractAddress
finalCb(null, selectedContract, address) finalCb(null, selectedContract, address)
} }
) )
@ -360,18 +352,7 @@ class Blockchain {
*/ */
callFunction (to, data, funAbi, confirmationCb, continueCb, promptCb, callback) { callFunction (to, data, funAbi, confirmationCb, continueCb, promptCb, callback) {
const useCall = funAbi.stateMutability === 'view' || funAbi.stateMutability === 'pure' const useCall = funAbi.stateMutability === 'view' || funAbi.stateMutability === 'pure'
this.runTx({to, data, useCall}, confirmationCb, continueCb, promptCb, (error, txResult) => { this.runTx({to, data, useCall}, confirmationCb, continueCb, promptCb, callback)
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)
})
} }
/** /**
@ -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