move udapp function call to blockchain module

pull/1/head
Iuri Matias 5 years ago
parent 8757ec5426
commit 36e72f9290
  1. 41
      src/app/tabs/runTab/model/blockchain.js
  2. 44
      src/app/ui/universal-dapp-ui.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

@ -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) => {

Loading…
Cancel
Save