From 36e72f92905cc69aceb00cbbc752c44a2e822288 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 30 Dec 2019 16:14:10 -0500 Subject: [PATCH] move udapp function call to blockchain module --- src/app/tabs/runTab/model/blockchain.js | 41 +++++++++++++++++++++++ src/app/ui/universal-dapp-ui.js | 44 +++---------------------- 2 files changed, 45 insertions(+), 40 deletions(-) diff --git a/src/app/tabs/runTab/model/blockchain.js b/src/app/tabs/runTab/model/blockchain.js index 1c6782a3ac..173f6c93e7 100644 --- a/src/app/tabs/runTab/model/blockchain.js +++ b/src/app/tabs/runTab/model/blockchain.js @@ -265,6 +265,47 @@ class Blockchain { this.udapp.startListening(txlistener) } + runOrCallContractMethod (contractName, contractAbi, funABI, value, address, callType, lookupOnly, logMsg, logCallback, outputCb, confirmationCb, continueCb, promptCb) { + // contractsDetails is used to resolve libraries + txFormat.buildData(contractName, contractAbi, {}, false, funABI, callType, (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, confirmationCb, continueCb, promptCb, (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, confirmationCb, runTxCallback) + }) + } + } module.exports = Blockchain diff --git a/src/app/ui/universal-dapp-ui.js b/src/app/ui/universal-dapp-ui.js index 0593d3ffbc..8b93a0fc8d 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 confirmDialog = require('./confirmDialog') @@ -189,8 +188,6 @@ UniversalDAppUI.prototype.getCallButton = function (args) { logMsg = `transact to ${args.contractName}.${(args.funABI.name) ? args.funABI.name : '(fallback)'}` } - var value = inputsValues - const confirmationCb = self.getConfirmationCb(modalDialog, confirmDialog) const continueCb = (error, continueTxExecution, cancelCb) => { if (error) { @@ -215,7 +212,8 @@ UniversalDAppUI.prototype.getCallButton = function (args) { } } - const outputCb = (decoded) => { + const outputCb = (returnValue) => { + const decoded = decodeResponseToTreeView(returnValue, args.funABI) outputOverride.innerHTML = '' outputOverride.appendChild(decoded) } @@ -224,42 +222,8 @@ UniversalDAppUI.prototype.getCallButton = function (args) { modalCustom.promptPassphrase('Passphrase requested', 'Personal mode is enabled. Please provide passphrase of account', '', okCb, cancelCb) } - // contractsDetails is used to resolve libraries - 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, confirmationCb, continueCb, promptCb, (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, confirmationCb, runTxCallback) - }) + const callType = args.funABI.type !== 'fallback' ? inputsValues : '' + self.blockchain.runOrCallContractMethod(args.contractName, args.contractAbi, args.funABI, inputsValues, args.address, callType, lookupOnly, logMsg, self.logCallback, outputCb, confirmationCb, continueCb, promptCb) } const multiParamManager = new MultiParamManager(lookupOnly, args.funABI, (valArray, inputsValues, domEl) => {