Skip to content

Commit

Permalink
update args type
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Nov 20, 2024
1 parent db47e85 commit 9005b85
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 18 deletions.
Binary file modified canister_templates/stable.wasm
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ic_cdk::{
api::{call::arg_data_raw, performance_counter},
trap,
};
use rquickjs::{Function, Object};
use rquickjs::{Function, Object, TypedArray};

use crate::{
benchmarking::record_benchmark, error::quickjs_call_with_error_handling, quickjs_with_ctx,
Expand Down Expand Up @@ -45,7 +45,9 @@ fn execute_method_js_with_result(
vec![]
};

quickjs_call_with_error_handling(ctx.clone(), method_callback, (candid_args,))?;
let candid_args_uint8_array = TypedArray::<u8>::new(ctx.clone(), candid_args)?;

quickjs_call_with_error_handling(ctx.clone(), method_callback, (candid_args_uint8_array,))?;

Ok(())
})?;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stable/canister_methods/heartbeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function heartbeat<This, Args extends any[], Return>(
try {
await executeAndReplyWithCandidSerde(
'heartbeat',
[],
new Uint8Array(),
originalMethod.bind(globalThis._azleCanisterClassInstance),
[],
undefined,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/stable/canister_methods/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ export function init<This, Args extends any[], Return>(
);

globalThis._azleCallbacks[indexString] = async (
...args: any[]
arg: Uint8Array
): Promise<void> => {
try {
await executeAndReplyWithCandidSerde(
'init',
args,
arg,
originalMethod.bind(globalThis._azleCanisterClassInstance),
paramIdlTypes,
undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stable/canister_methods/inspect_message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function inspectMessage<This, Args extends any[], Return>(
try {
await executeAndReplyWithCandidSerde(
'inspectMessage',
[],
new Uint8Array(),
originalMethod.bind(globalThis._azleCanisterClassInstance),
[],
undefined,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/stable/canister_methods/post_upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ export function postUpgrade<This, Args extends any[], Return>(
);

globalThis._azleCallbacks[indexString] = async (
...args: any[]
arg: Uint8Array
): Promise<void> => {
try {
await executeAndReplyWithCandidSerde(
'postUpgrade',
args,
arg,
originalMethod.bind(globalThis._azleCanisterClassInstance),
paramIdlTypes,
undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stable/canister_methods/pre_upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function preUpgrade<This, Args extends any[], Return>(
try {
await executeAndReplyWithCandidSerde(
'preUpgrade',
[],
new Uint8Array(),
originalMethod.bind(globalThis._azleCanisterClassInstance),
[],
undefined,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/stable/canister_methods/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ export function query<This, Args extends any[], Return>(
);

globalThis._azleCallbacks[indexString] = async (
...args: any[]
arg: Uint8Array
): Promise<void> => {
try {
await executeAndReplyWithCandidSerde(
'query',
args,
arg,
originalMethod.bind(globalThis._azleCanisterClassInstance),
paramIdlTypes,
returnIdlType,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/stable/canister_methods/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export function update<This, Args extends any[], Return>(
);

globalThis._azleCallbacks[indexString] = async (
...args: any[]
arg: Uint8Array
): Promise<void> => {
try {
await executeAndReplyWithCandidSerde(
'update',
args,
arg,
originalMethod.bind(globalThis._azleCanisterClassInstance),
paramIdlTypes,
returnIdlType,
Expand Down
8 changes: 4 additions & 4 deletions src/lib/stable/execute_with_candid_serde.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type CanisterMethodMode =

export async function executeAndReplyWithCandidSerde(
mode: CanisterMethodMode,
args: any[],
args: Uint8Array,
callback: (...args: any) => any,
paramIdlTypes: IDL.Type[],
returnIdlType: IDL.Type | undefined,
Expand All @@ -26,7 +26,7 @@ export async function executeAndReplyWithCandidSerde(

function decodeArgs(
mode: CanisterMethodMode,
args: any[],
args: Uint8Array,
paramIdlTypes: IDL.Type[]
): JsonValue[] {
if (
Expand All @@ -35,7 +35,7 @@ function decodeArgs(
mode === 'query' ||
mode === 'update'
) {
return idlDecode(paramIdlTypes, args[0]);
return idlDecode(paramIdlTypes, args);
} else {
return [];
}
Expand Down Expand Up @@ -78,7 +78,7 @@ export function idlEncode(

export function idlDecode(
retTypes: IDL.Type[],
bytes: ArrayBuffer
bytes: Uint8Array
): JsonValue[] {
try {
return IDL.decode(retTypes, bytes);
Expand Down
4 changes: 3 additions & 1 deletion src/lib/stable/ic_apis/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export async function call<Args extends any[] | undefined, Return = any>(
} else {
const idlType =
returnTypeIdl === undefined ? [] : [returnTypeIdl];
resolve(idlDecode(idlType, result)[0] as Return);
resolve(
idlDecode(idlType, new Uint8Array(result))[0] as Return
);
}

delete globalThis._azleResolveIds[globalResolveId];
Expand Down

0 comments on commit 9005b85

Please sign in to comment.