Skip to content

Commit

Permalink
fix: view function use buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
hanakannzashi committed Jun 26, 2024
1 parent 146e516 commit 2732595
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/accounts/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<any> {
Expand All @@ -102,4 +104,4 @@ export async function viewFunction(connection: Connection, {
}

return result.result && result.result.length > 0 && parse(Buffer.from(result.result));
}
}

0 comments on commit 2732595

Please sign in to comment.