From b988b0e6bcc1a1c06ee0852313561b0f0d2079c3 Mon Sep 17 00:00:00 2001 From: Dmytro Vynnyk Date: Mon, 23 Dec 2024 12:57:18 +0100 Subject: [PATCH] Fix List and Map fromBytes parsers --- src/types/clvalue/List.ts | 4 ++++ src/types/clvalue/Map.ts | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/types/clvalue/List.ts b/src/types/clvalue/List.ts index 7a64e1ff0..0c37b198e 100644 --- a/src/types/clvalue/List.ts +++ b/src/types/clvalue/List.ts @@ -163,6 +163,10 @@ export class CLValueList { bytes: innerBytes } = CLValueParser.fromBytesByType(remainder, clType.elementsType); + if (!inner) { + continue; + } + elements.push(inner); remainder = innerBytes; } diff --git a/src/types/clvalue/Map.ts b/src/types/clvalue/Map.ts index 3146aad74..76fc56b7f 100644 --- a/src/types/clvalue/Map.ts +++ b/src/types/clvalue/Map.ts @@ -195,7 +195,7 @@ export class CLValueMap { const { result: u32, bytes: u32Bytes } = CLValueUInt32.fromBytes(bytes); const size = u32.getValue().toNumber(); - let remainder = u32Bytes; + const remainder = u32Bytes; if (size === 0) { return { result: mapResult, bytes: remainder }; @@ -205,11 +205,15 @@ export class CLValueMap { if (remainder.length) { const keyVal = CLValueParser.fromBytesByType(remainder, mapType.key); - remainder = keyVal?.bytes; + if (!keyVal.result) { + continue; + } const valVal = CLValueParser.fromBytesByType(remainder, mapType.val); - remainder = valVal.bytes; + if (!valVal.result) { + continue; + } mapResult.append(keyVal?.result, valVal?.result); }