Skip to content

Commit

Permalink
Fixed function to get sighash of the smart contract function
Browse files Browse the repository at this point in the history
  • Loading branch information
u-hubar committed Nov 13, 2023
1 parent 066ff12 commit 8d569a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
);
Expand Down Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions src/modules/blockchain/implementation/web3-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
);
Expand Down

0 comments on commit 8d569a3

Please sign in to comment.