@ -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 is Call = funAbi . stateMutability === 'view' || funAbi . stateMutability === 'pure'
const use Call = 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 \t The execution might have thrown. \n `
msg = ` \t \n \t The execution might have thrown. \n `
ret . error = true
ret . error = true
@ -88,11 +88,11 @@ module.exports = {
msg = ` \t The transaction ran out of gas. Please increase the Gas Limit. \n `
msg = ` \t The 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 = ` \t The transaction has been reverted to the initial state. \n Reason provided by the contract: " ${ reason } ". `
msg = ` \t The transaction has been reverted to the initial state. \n Reason provided by the contract: " ${ reason } ". `
} else {
} 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. `
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. `