From 0a2c679de355db6f700597b9b19beed880d0fdef Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Wed, 8 Nov 2023 14:28:31 +0100 Subject: [PATCH] Make executeContractFunction and callContractFunction logs more readable by logging argName=argValue --- .../blockchain/implementation/web3-service.js | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/modules/blockchain/implementation/web3-service.js b/src/modules/blockchain/implementation/web3-service.js index 807bc098d2..2acf5a30a0 100644 --- a/src/modules/blockchain/implementation/web3-service.js +++ b/src/modules/blockchain/implementation/web3-service.js @@ -401,9 +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 ${functionName}(${args}) failed, reason: ${decodedErrorData}`), + Error(`Call ${functionName}(${inputs}) failed, reason: ${decodedErrorData}`), ); } } @@ -424,9 +432,17 @@ 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 ${functionName}(${args}) failed, reason: ${decodedErrorData}`, + `Gas estimation ${functionName}(${inputs}) failed, reason: ${decodedErrorData}`, ), ); }