diff --git a/src/modules/blockchain/implementation/web3-service.js b/src/modules/blockchain/implementation/web3-service.js index 63545eedf2..5f7478ec2f 100644 --- a/src/modules/blockchain/implementation/web3-service.js +++ b/src/modules/blockchain/implementation/web3-service.js @@ -61,7 +61,7 @@ class Web3Service { await this.initializeWeb3(); this.startBlock = await this.getBlockNumber(); await this.initializeContracts(); - // this.initializeProviderDebugging(); + this.initializeProviderDebugging(); } initializeTransactionQueue(concurrency) { @@ -189,32 +189,38 @@ class Web3Service { const { method } = info.request; if (['call', 'estimateGas'].includes(method)) { - const contractInstance = this.contractAddresses[info.request.params.to]; - const inputData = info.request.params.data; + const contractInstance = this.contractAddresses[info.request.params.transaction.to]; + const inputData = info.request.params.transaction.data; const decodedInputData = this._decodeInputData( inputData, contractInstance.interface, ); - + const functionFragment = contractInstance.interface.getFunction( + inputData.slice(0, 10), + ); + const functionName = functionFragment.name; + const inputs = functionFragment.inputs.map( + (input, i) => `${input.name}=${decodedInputData[i]}`, + ); if (info.backend.error) { const decodedErrorData = this._decodeErrorData( info.backend.error, contractInstance.interface, ); this.logger.debug( - `${decodedInputData} ${method} has failed; Error: ${decodedErrorData}; ` + + `${functionName}(${inputs}) ${method} has failed; Error: ${decodedErrorData}; ` + `RPC: ${info.backend.provider.connection.url}.`, ); } else if (info.backend.result !== undefined) { - let message = `${decodedInputData} ${method} has been successfully executed; `; + let message = `${functionName}(${inputs}) ${method} has been successfully executed; `; - if (info.backend.result !== null) { + if (info.backend.result !== null && method !== 'estimateGas') { const decodedResultData = this._decodeResultData( inputData.slice(0, 10), info.backend.result, contractInstance.interface, ); - message += `Result: ${decodedResultData} `; + message += `Result: ${decodedResultData}; `; } message += `RPC: ${info.backend.provider.connection.url}.`; @@ -395,10 +401,17 @@ class Web3Service { result = await contractInstance[functionName](...args); } catch (error) { const decodedErrorData = this._decodeErrorData(error, contractInstance.interface); + + const functionFragment = contractInstance.interface.getFunction( + error.transaction.data.slice(0, 10), + ); + const inputs = functionFragment.inputs.map( + (input, i) => `${input.name}=${args[i]}`, + ); + // eslint-disable-next-line no-await-in-loop await this.handleError( - Error(`Call failed, reason: ${decodedErrorData}`), - functionName, + Error(`Call ${functionName}(${inputs}) failed, reason: ${decodedErrorData}`), ); } } @@ -419,9 +432,18 @@ class Web3Service { gasLimit = await contractInstance.estimateGas[functionName](...args); } catch (error) { const decodedErrorData = this._decodeErrorData(error, contractInstance.interface); + + const functionFragment = contractInstance.interface.getFunction( + error.transaction.data.slice(0, 10), + ); + const inputs = functionFragment.inputs.map( + (input, i) => `${input.name}=${args[i]}`, + ); + await this.handleError( - Error(`Gas estimation failed, reason: ${decodedErrorData}`), - functionName, + Error( + `Gas estimation ${functionName}(${inputs}) failed, reason: ${decodedErrorData}`, + ), ); }