Skip to content

Commit a56058a

Browse files
authored
fix: converts string to bigint in specific cases when parsing v2 traces (#4)
The objectToMapRecursive function now converts string values to bigint when the key is 'uint' and the value is a numeric string. This is required for some numeric string values that exceed the safe integer range when users are working with legacy simulation traces emitted from v2 of algosdk
1 parent 7fdf199 commit a56058a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/common/utils.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,18 @@ function objectToMapRecursive(obj: any): any {
9090
}
9191

9292
return new Map(
93-
Object.entries(obj).map(([key, value]) => [
94-
key,
95-
objectToMapRecursive(value),
96-
]),
93+
Object.entries(obj).map(([key, value]) => {
94+
let processedValue = value;
95+
96+
// Convert string to bigint if key is "uint" and value is a numeric string
97+
if (key === 'uint' && typeof value === 'string' && /^\d+$/.test(value)) {
98+
processedValue = BigInt(value);
99+
} else {
100+
processedValue = objectToMapRecursive(value);
101+
}
102+
103+
return [key, processedValue];
104+
}),
97105
);
98106
}
99107

0 commit comments

Comments
 (0)