Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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