From 2732595588d298cbfad0d20e3e1e863ba2fcb17e Mon Sep 17 00:00:00 2001 From: coffee Date: Wed, 26 Jun 2024 17:10:09 +0800 Subject: [PATCH] fix: view function use buffer --- packages/accounts/src/utils.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/accounts/src/utils.ts b/packages/accounts/src/utils.ts index 6a0bdca49b..734215e6c5 100644 --- a/packages/accounts/src/utils.ts +++ b/packages/accounts/src/utils.ts @@ -12,8 +12,10 @@ function parseJsonFromRawResponse(response: Uint8Array): any { return JSON.parse(Buffer.from(response).toString()); } -function bytesJsonStringify(input: any): Buffer { - return Buffer.from(JSON.stringify(input)); +export function stringifyJsonOrBytes(args: any): Buffer { + const isUint8Array = + args.byteLength !== undefined && args.byteLength === args.length; + return isUint8Array ? args : Buffer.from(JSON.stringify(args)); } export function validateArgs(args: any) { @@ -75,7 +77,7 @@ export async function viewFunction(connection: Connection, { methodName, args = {}, parse = parseJsonFromRawResponse, - stringify = bytesJsonStringify, + stringify = stringifyJsonOrBytes, jsContract = false, blockQuery = { finality: 'optimistic' } }: ViewFunctionCallOptions): Promise { @@ -102,4 +104,4 @@ export async function viewFunction(connection: Connection, { } return result.result && result.result.length > 0 && parse(Buffer.from(result.result)); -} \ No newline at end of file +}