From be5db3c44b145ea770633cb67e8d25bf6201c237 Mon Sep 17 00:00:00 2001 From: Kirill Klimenko Date: Thu, 8 Feb 2024 19:03:12 +0100 Subject: [PATCH] Fix tuple type encoding --- src/utils/crypto.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/utils/crypto.ts b/src/utils/crypto.ts index 7ddaf1e2e7..ca45dbd7ef 100644 --- a/src/utils/crypto.ts +++ b/src/utils/crypto.ts @@ -37,7 +37,8 @@ export const encodeFunction = ( : undefined; const parametersFixed: Array | undefined = parameters ? [] : undefined; - parameters?.forEach(param => { + let tupleIndex: number | undefined = undefined; + parameters?.forEach((param, i) => { if (param.startsWith('[') && param.endsWith(']')) { parametersFixed!!.push( param @@ -45,6 +46,16 @@ export const encodeFunction = ( .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); }