diff --git a/src/app/tabs/runTab/model/blockchain.js b/src/app/tabs/runTab/model/blockchain.js index 60fcae6a48..599f9a38b8 100644 --- a/src/app/tabs/runTab/model/blockchain.js +++ b/src/app/tabs/runTab/model/blockchain.js @@ -265,6 +265,45 @@ class Blockchain { this.udapp.startListening(txlistener) } + runOrCallContractMethod (contractName, contractABI, funABI, value, address, params, lookupOnly, logMsg, logCallback, outputCb, callbacksInContext) { + // contractsDetails is used to resolve libraries + txFormat.buildData(contractName, contractABI, {}, false, funABI, params, (error, data) => { + if (!error) { + if (!lookupOnly) { + logCallback(`${logMsg} pending ... `) + } else { + logCallback(`${logMsg}`) + } + if (funABI.type === 'fallback') data.dataHex = value + this.udapp.callFunction(address, data, funABI, callbacksInContext.confirmationCb.bind(callbacksInContext), callbacksInContext.continueCb.bind(callbacksInContext), callbacksInContext.promptCb.bind(callbacksInContext), (error, txResult) => { + if (!error) { + var isVM = this.executionContext.isVM() + if (isVM) { + var vmError = txExecution.checkVMError(txResult) + if (vmError.error) { + logCallback(`${logMsg} errored: ${vmError.message} `) + return + } + } + if (lookupOnly) { + const returnValue = (this.executionContext.isVM() ? txResult.result.execResult.returnValue : ethJSUtil.toBuffer(txResult.result)) + outputCb(returnValue) + } + } else { + logCallback(`${logMsg} errored: ${error} `) + } + }) + } else { + logCallback(`${logMsg} errored: ${error} `) + } + }, (msg) => { + logCallback(msg) + }, (data, runTxCallback) => { + // called for libraries deployment + this.udapp.runTx(data, callbacksInContext.confirmationCb.bind(callbacksInContext), runTxCallback) + }) + } + } module.exports = Blockchain diff --git a/src/app/ui/universal-dapp-ui.js b/src/app/ui/universal-dapp-ui.js index 509bbb6874..a3af0c564c 100644 --- a/src/app/ui/universal-dapp-ui.js +++ b/src/app/ui/universal-dapp-ui.js @@ -10,7 +10,6 @@ var copyToClipboard = require('./copy-to-clipboard') var css = require('../../universal-dapp-styles') var MultiParamManager = require('./multiParamManager') var remixLib = require('remix-lib') -var txExecution = remixLib.execution.txExecution var txFormat = remixLib.execution.txFormat var TreeView = require('./TreeView') var txCallBacks = require('./sendTxCallbacks') @@ -232,55 +231,20 @@ UniversalDAppUI.prototype.getCallButton = function (args) { } UniversalDAppUI.prototype.runTransaction = function (lookupOnly, args, valArr, inputsValues, outputOverride) { - let self = this const functionName = args.funABI.type === 'function' ? args.funABI.name : `(${args.funABI.type})` const logMsg = `${lookupOnly ? 'call' : 'transact'} to ${args.contractName}.${functionName}` - var value = inputsValues + const callbacksInContext = txCallBacks.getCallBacksWithContext(this, this.executionContext) - const outputCb = (decoded) => { + const outputCb = (returnValue) => { if (outputOverride) { + const decoded = decodeResponseToTreeView(returnValue, args.funABI) outputOverride.innerHTML = '' outputOverride.appendChild(decoded) } } - // contractsDetails is used to resolve libraries - const callbacksInContext = txCallBacks.getCallBacksWithContext(self, self.executionContext) - txFormat.buildData(args.contractName, args.contractABI, {}, false, args.funABI, args.funABI.type !== 'fallback' ? value : '', (error, data) => { - if (!error) { - if (!lookupOnly) { - self.logCallback(`${logMsg} pending ... `) - } else { - self.logCallback(`${logMsg}`) - } - if (args.funABI.type === 'fallback') data.dataHex = value - self.udapp.callFunction(args.address, data, args.funABI, callbacksInContext.confirmationCb.bind(callbacksInContext), callbacksInContext.continueCb.bind(callbacksInContext), callbacksInContext.promptCb.bind(callbacksInContext), (error, txResult) => { - if (!error) { - var isVM = self.executionContext.isVM() - if (isVM) { - var vmError = txExecution.checkVMError(txResult) - if (vmError.error) { - self.logCallback(`${logMsg} errored: ${vmError.message} `) - return - } - } - if (lookupOnly) { - const decoded = decodeResponseToTreeView(self.executionContext.isVM() ? txResult.result.execResult.returnValue : ethJSUtil.toBuffer(txResult.result), args.funABI) - outputCb(decoded) - } - } else { - self.logCallback(`${logMsg} errored: ${error} `) - } - }) - } else { - self.logCallback(`${logMsg} errored: ${error} `) - } - }, (msg) => { - self.logCallback(msg) - }, (data, runTxCallback) => { - // called for libraries deployment - self.udapp.runTx(data, callbacksInContext.confirmationCb.bind(callbacksInContext), runTxCallback) - }) + const params = args.funABI.type !== 'fallback' ? inputsValues : '' + this.blockchain.runOrCallContractMethod(args.contractName, args.contractAbi, args.funABI, inputsValues, args.address, params, lookupOnly, logMsg, this.logCallback, outputCb, callbacksInContext) } module.exports = UniversalDAppUI