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