Skip to content

Commit

Permalink
refactor: improve method to extract tuple elements
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ42 committed Nov 24, 2023
1 parent 439dbe6 commit a9a2439
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/lib/decodeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,8 @@ const isValidTupleDefinition = (tupleContent: string): boolean => {
return true;
};

const extractValueTypesFromTuple = (tupleContent: string): string[] => {
let valueTypeToDecode = tupleContent;

if (tupleContent.includes(COMPACT_BYTES_ARRAY_STRING)) {
valueTypeToDecode = tupleContent.replace(COMPACT_BYTES_ARRAY_STRING, '');
}

return valueTypeToDecode
.substring(1, valueTypeToDecode.length - 1)
.split(',');
};
const extractTupleElements = (tupleContent: string): string[] =>
tupleContent.substring(1, tupleContent.length - 1).split(',');

const extractTupleElements = (tupleContent: string): string[] =>
tupleContent.substring(1, tupleContent.length - 1).split(',');
Expand Down Expand Up @@ -148,11 +139,11 @@ export const decodeTupleKeyValue = (
): Array<string> => {
// We assume data has already been validated at this stage

const valueTypeParts = extractValueTypesFromTuple(valueType);
// Sanitize the string to keep only the tuple, if we are dealing with `CompactBytesArray`
const valueTypeToDecode = valueType.replace(COMPACT_BYTES_ARRAY_STRING, '');

const valueContentParts = valueContent
.substring(1, valueContent.length - 1)
.split(',');
const valueTypeParts = extractTupleElements(valueTypeToDecode);
const valueContentParts = extractTupleElements(valueContent);

const bytesLengths: number[] = [];

Expand Down

0 comments on commit a9a2439

Please sign in to comment.