Skip to content

Commit

Permalink
fix: Handle falsy bigints in json-rpc (#2403)
Browse files Browse the repository at this point in the history
Resolves #2402
  • Loading branch information
sirasistant authored Sep 19, 2023
1 parent 02e788a commit d100650
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions yarn-project/foundation/src/json-rpc/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ export function convertFromJsonObj(cc: ClassConverter, obj: any): any {
* @returns The encoded object.
*/
export function convertToJsonObj(cc: ClassConverter, obj: any): any {
// Bigint is a primitive type that needs special handling since it's not serialisable
if (typeof obj === 'bigint') {
return {
type: 'bigint',
data: obj.toString(),
};
}

if (!obj) {
return obj; // Primitive type
}
Expand All @@ -126,13 +134,6 @@ export function convertToJsonObj(cc: ClassConverter, obj: any): any {
return { type: 'Buffer', data: obj.toString('base64') };
}

if (typeof obj === 'bigint') {
return {
type: 'bigint',
data: obj.toString(),
};
}

// Is this a convertible type?
if (cc.isRegisteredClass(obj.constructor)) {
return cc.toJsonObj(obj);
Expand Down

0 comments on commit d100650

Please sign in to comment.