suggested changes

pull/5370/head
aniket-engg 5 years ago committed by Aniket
parent 190571f5eb
commit 1114be0c05
  1. 24
      remix-lib/src/execution/txExecution.js
  2. 4
      remix-lib/src/execution/txHelper.js
  3. 4
      remix-lib/src/universalDapp.js

@ -1,5 +1,5 @@
'use strict' 'use strict'
var ethers = require('ethers') const ethers = require('ethers')
module.exports = { module.exports = {
/** /**
@ -20,7 +20,7 @@ module.exports = {
if (!callbacks.confirmationCb || !callbacks.gasEstimationForceSend || !callbacks.promptCb) { if (!callbacks.confirmationCb || !callbacks.gasEstimationForceSend || !callbacks.promptCb) {
return finalCallback('all the callbacks must have been defined') return finalCallback('all the callbacks must have been defined')
} }
var tx = { from: from, to: null, data: data, useCall: false, value: value, gasLimit: gasLimit } const tx = { from: from, to: null, data: data, useCall: false, value: value, gasLimit: gasLimit }
txRunner.rawRun(tx, callbacks.confirmationCb, callbacks.gasEstimationForceSend, callbacks.promptCb, (error, txResult) => { txRunner.rawRun(tx, callbacks.confirmationCb, callbacks.gasEstimationForceSend, callbacks.promptCb, (error, txResult) => {
// see universaldapp.js line 660 => 700 to check possible values of txResult (error case) // see universaldapp.js line 660 => 700 to check possible values of txResult (error case)
finalCallback(error, txResult) finalCallback(error, txResult)
@ -43,8 +43,8 @@ module.exports = {
* @param {Function} finalCallback - last callback. * @param {Function} finalCallback - last callback.
*/ */
callFunction: function (from, to, data, value, gasLimit, funAbi, txRunner, callbacks, finalCallback) { callFunction: function (from, to, data, value, gasLimit, funAbi, txRunner, callbacks, finalCallback) {
const isCall = funAbi.stateMutability === 'view' || funAbi.stateMutability === 'pure' const useCall = funAbi.stateMutability === 'view' || funAbi.stateMutability === 'pure'
var tx = { from: from, to: to, data: data, useCall: isCall, value: value, gasLimit: gasLimit } const tx = { from, to, data, useCall, value, gasLimit }
txRunner.rawRun(tx, callbacks.confirmationCb, callbacks.gasEstimationForceSend, callbacks.promptCb, (error, txResult) => { txRunner.rawRun(tx, callbacks.confirmationCb, callbacks.gasEstimationForceSend, callbacks.promptCb, (error, txResult) => {
// see universaldapp.js line 660 => 700 to check possible values of txResult (error case) // see universaldapp.js line 660 => 700 to check possible values of txResult (error case)
finalCallback(error, txResult) finalCallback(error, txResult)
@ -58,7 +58,7 @@ module.exports = {
* @return {Object} - { error: true/false, message: DOMNode } * @return {Object} - { error: true/false, message: DOMNode }
*/ */
checkVMError: function (txResult) { checkVMError: function (txResult) {
var errorCode = { const errorCode = {
OUT_OF_GAS: 'out of gas', OUT_OF_GAS: 'out of gas',
STACK_UNDERFLOW: 'stack underflow', STACK_UNDERFLOW: 'stack underflow',
STACK_OVERFLOW: 'stack overflow', STACK_OVERFLOW: 'stack overflow',
@ -71,16 +71,16 @@ module.exports = {
STOP: 'stop', STOP: 'stop',
REFUND_EXHAUSTED: 'refund exhausted' REFUND_EXHAUSTED: 'refund exhausted'
} }
var ret = { let ret = {
error: false, error: false,
message: '' message: ''
} }
if (!txResult.result.execResult.exceptionError) { if (!txResult.result.execResult.exceptionError) {
return ret return ret
} }
var exceptionError = txResult.result.execResult.exceptionError.error || '' const exceptionError = txResult.result.execResult.exceptionError.error || ''
var error = `VM error: ${exceptionError}.\n` const error = `VM error: ${exceptionError}.\n`
var msg let msg
if (exceptionError === errorCode.INVALID_OPCODE) { if (exceptionError === errorCode.INVALID_OPCODE) {
msg = `\t\n\tThe execution might have thrown.\n` msg = `\t\n\tThe execution might have thrown.\n`
ret.error = true ret.error = true
@ -88,11 +88,11 @@ module.exports = {
msg = `\tThe transaction ran out of gas. Please increase the Gas Limit.\n` msg = `\tThe transaction ran out of gas. Please increase the Gas Limit.\n`
ret.error = true ret.error = true
} else if (exceptionError === errorCode.REVERT) { } else if (exceptionError === errorCode.REVERT) {
var returnData = txResult.result.execResult.returnValue const returnData = txResult.result.execResult.returnValue
// It is the hash of Error(string) // It is the hash of Error(string)
if (returnData && (returnData.slice(0, 4).toString('hex') === '08c379a0')) { if (returnData && (returnData.slice(0, 4).toString('hex') === '08c379a0')) {
var abiCoder = new ethers.utils.AbiCoder() const abiCoder = new ethers.utils.AbiCoder()
var reason = abiCoder.decode(['string'], returnData.slice(4))[0] const reason = abiCoder.decode(['string'], returnData.slice(4))[0]
msg = `\tThe transaction has been reverted to the initial state.\nReason provided by the contract: "${reason}".` msg = `\tThe transaction has been reverted to the initial state.\nReason provided by the contract: "${reason}".`
} else { } else {
msg = `\tThe transaction has been reverted to the initial state.\nNote: The called function should be payable if you send value and the value you send should be less than your current balance.` msg = `\tThe transaction has been reverted to the initial state.\nNote: The called function should be payable if you send value and the value you send should be less than your current balance.`

@ -42,9 +42,7 @@ module.exports = {
sortAbiFunction: function (contractabi) { sortAbiFunction: function (contractabi) {
// Check if function is constant (introduced with Solidity 0.6.0) // Check if function is constant (introduced with Solidity 0.6.0)
function isConstant (funcABI) { const isConstant = ({stateMutability}) => stateMutability === 'view' || stateMutability === 'pure'
return (funcABI.stateMutability === 'view' || funcABI.stateMutability === 'pure')
}
// Sorts the list of ABI entries. Constant functions will appear first, // Sorts the list of ABI entries. Constant functions will appear first,
// followed by non-constant functions. Within those t wo groupings, functions // followed by non-constant functions. Within those t wo groupings, functions
// will be sorted by their names. // will be sorted by their names.

@ -232,8 +232,8 @@ module.exports = class UniversalDApp {
* @param {Function} callback - callback. * @param {Function} callback - callback.
*/ */
callFunction (to, data, funAbi, confirmationCb, continueCb, promptCb, callback) { callFunction (to, data, funAbi, confirmationCb, continueCb, promptCb, callback) {
const isCall = funAbi.stateMutability === 'view' || funAbi.stateMutability === 'pure' const useCall = funAbi.stateMutability === 'view' || funAbi.stateMutability === 'pure'
this.runTx({to: to, data: data, useCall: isCall}, confirmationCb, continueCb, promptCb, (error, txResult) => { this.runTx({to, data, useCall}, confirmationCb, continueCb, promptCb, (error, txResult) => {
// see universaldapp.js line 660 => 700 to check possible values of txResult (error case) // see universaldapp.js line 660 => 700 to check possible values of txResult (error case)
callback(error, txResult) callback(error, txResult)
}) })

Loading…
Cancel
Save