Skip to content

Commit

Permalink
Fix tuple type encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrila committed Feb 8, 2024
1 parent dbe4563 commit be5db3c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/utils/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,25 @@ export const encodeFunction = (
: undefined;

const parametersFixed: Array<string | string[]> | undefined = parameters ? [] : undefined;
parameters?.forEach(param => {
let tupleIndex: number | undefined = undefined;
parameters?.forEach((param, i) => {
if (param.startsWith('[') && param.endsWith(']')) {
parametersFixed!!.push(
param
.substring(1, param.length - 1)
.split(',')
.map(p => (p = p.trim()))
);
} else if (param.startsWith('(')) {
// This is part of tuple param, we need to re-assemble it. There should be better solution to this within splitIgnoreBrackets with regex.
// However, we probably want to rebuild proposal builder to be more like ProposalTemplate builder
tupleIndex = i;
parametersFixed!!.push(param + ',');
} else if (typeof tupleIndex === 'number' && !param.endsWith(')')) {
parametersFixed!![tupleIndex!] = parametersFixed!![tupleIndex!] + param + ',';
} else if (param.endsWith(')')) {
parametersFixed!![tupleIndex!] = parametersFixed!![tupleIndex!] + param;
tupleIndex = undefined;
} else {
parametersFixed!!.push(param);
}
Expand Down

0 comments on commit be5db3c

Please sign in to comment.