Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: view function use buffer #1356

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is already exported from @near-js/transactions, please import it from there and remove bytesJsonStringify.

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));
}
}
Loading