From 81887f8c847b9970ebc3b9b922622f42f0ff7ed8 Mon Sep 17 00:00:00 2001 From: Alvaro Rodriguez Date: Tue, 19 Sep 2023 17:11:30 +0200 Subject: [PATCH] fix: Handle falsy bigints in json-rpc --- yarn-project/foundation/src/json-rpc/convert.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/yarn-project/foundation/src/json-rpc/convert.ts b/yarn-project/foundation/src/json-rpc/convert.ts index bcd5b15d3c7..53a3fe0d3b3 100644 --- a/yarn-project/foundation/src/json-rpc/convert.ts +++ b/yarn-project/foundation/src/json-rpc/convert.ts @@ -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 } @@ -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);