Skip to content

Commit

Permalink
Implement fix to function encoding when parameter includes bool
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgall committed Feb 10, 2024
1 parent fad870b commit 3b5e9ec
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/utils/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,32 @@ export const encodeFunction = (
}
});

const boolify = (parameter: string) => {
if (['false'].includes(parameter.toLowerCase())) {
return false;
} else if (['true'].includes(parameter.toLowerCase())) {
return true;
} else {
return parameter;
}
};

const parametersFixedWithBool = parametersFixed?.map(parameter => {
if (typeof parameter === 'string') {
return boolify(parameter);
} else if (Array.isArray(parameter)) {
return parameter.map(innerParameter => {
return boolify(innerParameter);
});
} else {
throw new Error('parameter type not as expected');
}
});

try {
return new utils.Interface([functionSignature]).encodeFunctionData(
_functionName,
parametersFixed
parametersFixedWithBool
);
} catch (e) {
logError(e);
Expand Down

0 comments on commit 3b5e9ec

Please sign in to comment.