From 8d569a3f33a49c6cce978cb886c6f2b10ce9993a Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Mon, 13 Nov 2023 16:24:59 +0100 Subject: [PATCH] Fixed function to get sighash of the smart contract function --- .../update/receiver/submit-update-commit-command.js | 4 ++-- src/modules/blockchain/implementation/web3-service.js | 11 ++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/commands/protocols/update/receiver/submit-update-commit-command.js b/src/commands/protocols/update/receiver/submit-update-commit-command.js index a78f971fbc..7a6cbe098f 100644 --- a/src/commands/protocols/update/receiver/submit-update-commit-command.js +++ b/src/commands/protocols/update/receiver/submit-update-commit-command.js @@ -31,7 +31,7 @@ class SubmitUpdateCommitCommand extends Command { this.logger.trace( `Started ${command.name} for the Service Agreement with the ID: ${agreementId}, ` + - `Blockchain: ${blockchain}, Contract: ${contract}, Token ID: ${tokenId},` + + `Blockchain: ${blockchain}, Contract: ${contract}, Token ID: ${tokenId}, ` + `Keyword: ${keyword}, Hash function ID: ${hashFunctionId}, Operation ID: ${operationId}, ` + `Retry number: ${COMMAND_RETRIES.SUBMIT_UPDATE_COMMIT - command.retries + 1}`, ); @@ -126,7 +126,7 @@ class SubmitUpdateCommitCommand extends Command { this.logger.trace( `Successfully executed ${command.name} for the Service Agreement with the ID: ${agreementId}, ` + - `Blockchain: ${blockchain}, Contract: ${contract}, Token ID: ${tokenId},` + + `Blockchain: ${blockchain}, Contract: ${contract}, Token ID: ${tokenId}, ` + `Keyword: ${keyword}, Hash function ID: ${hashFunctionId}, Epoch: ${epoch}, ` + `Operation ID: ${operationId}, Retry number: ${ COMMAND_RETRIES.SUBMIT_UPDATE_COMMIT - command.retries + 1 diff --git a/src/modules/blockchain/implementation/web3-service.js b/src/modules/blockchain/implementation/web3-service.js index 26436179ed..c36e21e403 100644 --- a/src/modules/blockchain/implementation/web3-service.js +++ b/src/modules/blockchain/implementation/web3-service.js @@ -515,9 +515,9 @@ class Web3Service { } _getFunctionSighash(contractInstance, functionName, args) { - const functions = contractInstance.interface.functions.filter( - (func) => func.name === functionName, - ); + const functions = Object.keys(contractInstance.interface.functions) + .filter((key) => contractInstance.interface.functions[key].name === functionName) + .map((key) => ({ signature: key, ...contractInstance.interface.functions[key] })); for (const func of functions) { try { @@ -526,11 +526,8 @@ class Web3Service { // needed function fragment ethers.utils.defaultAbiCoder.encode(func.inputs, args); - const signature = `${func.name}(${func.inputs - .map((input) => input.type) - .join(',')})`; const sighash = ethers.utils.hexDataSlice( - ethers.utils.keccak256(ethers.utils.toUtf8Bytes(signature)), + ethers.utils.keccak256(ethers.utils.toUtf8Bytes(func.signature)), 0, 4, );