diff --git a/src/compiler/rust/canister/src/ic/instruction_counter.rs b/src/compiler/rust/canister/src/ic/instruction_counter.rs index d7f862c93a..160ad0ba45 100644 --- a/src/compiler/rust/canister/src/ic/instruction_counter.rs +++ b/src/compiler/rust/canister/src/ic/instruction_counter.rs @@ -6,6 +6,6 @@ pub fn native_function<'a>( _args: &[CallbackArg], ) -> Result, anyhow::Error> { let instruction_counter_js_value: JSValue = - candid::encode_one(ic_cdk::api::instruction_counter())?.into(); + ic_cdk::api::instruction_counter().to_string().into(); to_qjs_value(&context, &instruction_counter_js_value) } diff --git a/src/compiler/rust/canister/src/ic/performance_counter.rs b/src/compiler/rust/canister/src/ic/performance_counter.rs index d7d0b796c5..69b6452388 100644 --- a/src/compiler/rust/canister/src/ic/performance_counter.rs +++ b/src/compiler/rust/canister/src/ic/performance_counter.rs @@ -7,15 +7,16 @@ pub fn native_function<'a>( _this: &CallbackArg, args: &[CallbackArg], ) -> Result, anyhow::Error> { - let counter_type_vec_u8: Vec = args + let counter_type_string: String = args .get(0) .expect("performanceCounter must have one argument") .to_js_value()? .try_into()?; - let counter_type: u32 = candid::decode_one(&counter_type_vec_u8)?; - let return_js_value: JSValue = - candid::encode_one(ic_cdk::api::call::performance_counter(counter_type))?.into(); + ic_cdk::api::call::performance_counter(counter_type_string.parse()?) + .to_string() + .into(); + to_qjs_value(&context, &return_js_value) } diff --git a/src/compiler/rust/canister/src/ic/stable64_grow.rs b/src/compiler/rust/canister/src/ic/stable64_grow.rs index 348f35b9d6..a9e4bba78e 100644 --- a/src/compiler/rust/canister/src/ic/stable64_grow.rs +++ b/src/compiler/rust/canister/src/ic/stable64_grow.rs @@ -7,15 +7,15 @@ pub fn native_function<'a>( _this: &CallbackArg, args: &[CallbackArg], ) -> Result, anyhow::Error> { - let new_pages_bytes: Vec = args + let new_pages_string: String = args .get(0) .expect("stable64Grow must have one argument") .to_js_value()? .try_into()?; - let new_pages: u64 = candid::decode_one(&new_pages_bytes)?; + let return_js_value: JSValue = ic_cdk::api::stable::stable64_grow(new_pages_string.parse()?)? + .to_string() + .into(); - let return_js_value: JSValue = - candid::encode_one(ic_cdk::api::stable::stable64_grow(new_pages)?)?.into(); to_qjs_value(&context, &return_js_value) } diff --git a/src/compiler/rust/canister/src/ic/stable64_read.rs b/src/compiler/rust/canister/src/ic/stable64_read.rs index e7173248ab..3492f3d7fb 100644 --- a/src/compiler/rust/canister/src/ic/stable64_read.rs +++ b/src/compiler/rust/canister/src/ic/stable64_read.rs @@ -7,15 +7,19 @@ pub fn native_function<'a>( _this: &CallbackArg, args: &[CallbackArg], ) -> Result, anyhow::Error> { - let params_bytes: Vec = args + let offset_string: String = args .get(0) .expect("stable64Read must have two arguments") .to_js_value()? .try_into()?; - let (offset, length): (u64, u64) = candid::decode_args(¶ms_bytes)?; + let length_string: String = args + .get(1) + .expect("stable64Read must have two arguments") + .to_js_value()? + .try_into()?; - let mut buf: Vec = vec![0; length as usize]; - ic_cdk::api::stable::stable64_read(offset, &mut buf); + let mut buf: Vec = vec![0; length_string.parse()?]; + ic_cdk::api::stable::stable64_read(offset_string.parse()?, &mut buf); to_qjs_value(&context, &buf.into()) } diff --git a/src/compiler/rust/canister/src/ic/stable64_size.rs b/src/compiler/rust/canister/src/ic/stable64_size.rs index 171f412d47..e3b291ad9e 100644 --- a/src/compiler/rust/canister/src/ic/stable64_size.rs +++ b/src/compiler/rust/canister/src/ic/stable64_size.rs @@ -5,6 +5,6 @@ pub fn native_function<'a>( _this: &CallbackArg, _args: &[CallbackArg], ) -> Result, anyhow::Error> { - let return_js_value: JSValue = candid::encode_one(ic_cdk::api::stable::stable64_size())?.into(); + let return_js_value: JSValue = ic_cdk::api::stable::stable64_size().to_string().into(); to_qjs_value(&context, &return_js_value) } diff --git a/src/compiler/rust/canister/src/ic/stable64_write.rs b/src/compiler/rust/canister/src/ic/stable64_write.rs index 8901b0a73b..644c2db0c0 100644 --- a/src/compiler/rust/canister/src/ic/stable64_write.rs +++ b/src/compiler/rust/canister/src/ic/stable64_write.rs @@ -7,15 +7,19 @@ pub fn native_function<'a>( _this: &CallbackArg, args: &[CallbackArg], ) -> Result, anyhow::Error> { - let params_bytes: Vec = args + let offset_string: String = args .get(0) .expect("stable64Write must have two arguments") .to_js_value()? .try_into()?; - let (offset, buf): (u64, Vec) = candid::decode_args(¶ms_bytes)?; + let buf: Vec = args + .get(1) + .expect("stable64Write must have two arguments") + .to_js_value()? + .try_into()?; - ic_cdk::api::stable::stable64_write(offset, &buf); + ic_cdk::api::stable::stable64_write(offset_string.parse()?, &buf); context.undefined_value() } diff --git a/src/compiler/rust/canister/src/ic/stable_grow.rs b/src/compiler/rust/canister/src/ic/stable_grow.rs index 2229cd2d3c..56cbd25aa6 100644 --- a/src/compiler/rust/canister/src/ic/stable_grow.rs +++ b/src/compiler/rust/canister/src/ic/stable_grow.rs @@ -7,15 +7,15 @@ pub fn native_function<'a>( _this: &CallbackArg, args: &[CallbackArg], ) -> Result, anyhow::Error> { - let new_pages_bytes: Vec = args + let new_pages_string: String = args .get(0) .expect("stableGrow must have one argument") .to_js_value()? .try_into()?; - let new_pages: u32 = candid::decode_one(&new_pages_bytes)?; + let return_js_value: JSValue = ic_cdk::api::stable::stable_grow(new_pages_string.parse()?)? + .to_string() + .into(); - let return_js_value: JSValue = - candid::encode_one(ic_cdk::api::stable::stable_grow(new_pages)?)?.into(); to_qjs_value(&context, &return_js_value) } diff --git a/src/compiler/rust/canister/src/ic/stable_read.rs b/src/compiler/rust/canister/src/ic/stable_read.rs index 0f9a8beae9..1fb4990bfc 100644 --- a/src/compiler/rust/canister/src/ic/stable_read.rs +++ b/src/compiler/rust/canister/src/ic/stable_read.rs @@ -7,16 +7,20 @@ pub fn native_function<'a>( _this: &CallbackArg, args: &[CallbackArg], ) -> Result, anyhow::Error> { - let params_bytes: Vec = args + let offset_string: String = args .get(0) .expect("stableRead must have two arguments") .to_js_value()? .try_into()?; - let (offset, length): (u32, u32) = candid::decode_args(¶ms_bytes)?; + let length_string: String = args + .get(1) + .expect("stableRead must have two arguments") + .to_js_value()? + .try_into()?; - let mut buf: Vec = vec![0; length as usize]; - ic_cdk::api::stable::stable_read(offset, &mut buf); + let mut buf: Vec = vec![0; length_string.parse()?]; + ic_cdk::api::stable::stable_read(offset_string.parse()?, &mut buf); to_qjs_value(&context, &buf.into()) } diff --git a/src/compiler/rust/canister/src/ic/stable_size.rs b/src/compiler/rust/canister/src/ic/stable_size.rs index 449dc359c3..99b65dc0a8 100644 --- a/src/compiler/rust/canister/src/ic/stable_size.rs +++ b/src/compiler/rust/canister/src/ic/stable_size.rs @@ -5,6 +5,6 @@ pub fn native_function<'a>( _this: &CallbackArg, _args: &[CallbackArg], ) -> Result, anyhow::Error> { - let return_js_value: JSValue = candid::encode_one(ic_cdk::api::stable::stable_size())?.into(); + let return_js_value: JSValue = ic_cdk::api::stable::stable_size().to_string().into(); to_qjs_value(&context, &return_js_value) } diff --git a/src/compiler/rust/canister/src/ic/stable_write.rs b/src/compiler/rust/canister/src/ic/stable_write.rs index 5d93c4cb19..4acc1e2ec3 100644 --- a/src/compiler/rust/canister/src/ic/stable_write.rs +++ b/src/compiler/rust/canister/src/ic/stable_write.rs @@ -7,15 +7,19 @@ pub fn native_function<'a>( _this: &CallbackArg, args: &[CallbackArg], ) -> Result, anyhow::Error> { - let params_bytes: Vec = args + let offset_string: String = args .get(0) .expect("stableWrite must have two arguments") .to_js_value()? .try_into()?; - let (offset, buf): (u32, Vec) = candid::decode_args(¶ms_bytes)?; + let buf: Vec = args + .get(1) + .expect("stableWrite must have two arguments") + .to_js_value()? + .try_into()?; - ic_cdk::api::stable::stable_write(offset, &buf); + ic_cdk::api::stable::stable_write(offset_string.parse()?, &buf); context.undefined_value() } diff --git a/src/compiler/rust/canister/src/ic/time.rs b/src/compiler/rust/canister/src/ic/time.rs index 522e30f1d1..5b263705c2 100644 --- a/src/compiler/rust/canister/src/ic/time.rs +++ b/src/compiler/rust/canister/src/ic/time.rs @@ -5,6 +5,6 @@ pub fn native_function<'a>( _this: &CallbackArg, _args: &[CallbackArg], ) -> Result, anyhow::Error> { - let time_js_value: JSValue = candid::encode_one(ic_cdk::api::time())?.into(); + let time_js_value: JSValue = ic_cdk::api::time().to_string().into(); to_qjs_value(&context, &time_js_value) } diff --git a/src/lib/ic/instruction_counter.ts b/src/lib/ic/instruction_counter.ts index 38ff196575..32b2417b41 100644 --- a/src/lib/ic/instruction_counter.ts +++ b/src/lib/ic/instruction_counter.ts @@ -14,7 +14,6 @@ export function instructionCounter(): nat64 { return undefined as any; } - const instructionCounterCandidBytes = - globalThis._azleIc.instructionCounter(); - return decode(nat64, instructionCounterCandidBytes); + const instructionCounterString = globalThis._azleIc.instructionCounter(); + return BigInt(instructionCounterString); } diff --git a/src/lib/ic/performance_counter.ts b/src/lib/ic/performance_counter.ts index fe7edb9637..c157e57d47 100644 --- a/src/lib/ic/performance_counter.ts +++ b/src/lib/ic/performance_counter.ts @@ -1,7 +1,5 @@ import { nat32 } from '../candid/types/primitive/nats/nat32'; import { nat64 } from '../candid/types/primitive/nats/nat64'; -import { decode } from '../candid/serde/decode'; -import { encode } from '../candid/serde/encode'; /** * Gets the value of the specified performance counter @@ -17,11 +15,9 @@ export function performanceCounter(counterType: nat32): nat64 { return undefined as any; } - const counterTypeCandidBytes = encode(nat32, counterType).buffer; - - const performanceCounterCandidBytes = globalThis._azleIc.performanceCounter( - counterTypeCandidBytes + const performanceCounterString = globalThis._azleIc.performanceCounter( + counterType.toString() ); - return decode(nat64, performanceCounterCandidBytes); + return BigInt(performanceCounterString); } diff --git a/src/lib/ic/stable_64_grow.ts b/src/lib/ic/stable_64_grow.ts index 4542fa6868..67253b1ffe 100644 --- a/src/lib/ic/stable_64_grow.ts +++ b/src/lib/ic/stable_64_grow.ts @@ -1,6 +1,4 @@ import { nat64 } from '../candid/types/primitive/nats/nat64'; -import { decode } from '../candid/serde/decode'; -import { encode } from '../candid/serde/encode'; /** * Attempts to grow the stable memory by `newPages`. @@ -13,7 +11,5 @@ export function stable64Grow(newPages: nat64): nat64 { return undefined as any; } - const newPagesCandidBytes = encode(nat64, newPages).buffer; - - return decode(nat64, globalThis._azleIc.stable64Grow(newPagesCandidBytes)); + return BigInt(globalThis._azleIc.stable64Grow(newPages.toString())); } diff --git a/src/lib/ic/stable_64_read.ts b/src/lib/ic/stable_64_read.ts index 1b38df0503..36a0584c12 100644 --- a/src/lib/ic/stable_64_read.ts +++ b/src/lib/ic/stable_64_read.ts @@ -15,5 +15,7 @@ export function stable64Read(offset: nat64, length: nat64): Uint8Array { const paramsCandidBytes = encode([nat64, nat64], [offset, length]).buffer; - return new Uint8Array(globalThis._azleIc.stable64Read(paramsCandidBytes)); + return new Uint8Array( + globalThis._azleIc.stable64Read(offset.toString(), length.toString()) + ); } diff --git a/src/lib/ic/stable_64_size.ts b/src/lib/ic/stable_64_size.ts index f12b3ac0ec..8adcab458b 100644 --- a/src/lib/ic/stable_64_size.ts +++ b/src/lib/ic/stable_64_size.ts @@ -11,5 +11,5 @@ export function stable64Size(): nat64 { return undefined as any; } - return decode(nat64, globalThis._azleIc.stable64Size()); + return BigInt(globalThis._azleIc.stable64Size()); } diff --git a/src/lib/ic/stable_64_write.ts b/src/lib/ic/stable_64_write.ts index 73eac9ef2e..5bb54f741c 100644 --- a/src/lib/ic/stable_64_write.ts +++ b/src/lib/ic/stable_64_write.ts @@ -1,6 +1,5 @@ import { blob } from '../candid/types/constructed/blob'; import { nat64 } from '../candid/types/primitive/nats/nat64'; -import { encode } from '../candid/serde/encode'; /** * Writes data to the stable memory location specified by an offset. @@ -12,12 +11,10 @@ import { encode } from '../candid/serde/encode'; * @param offset the location at which to write * @param buffer the data to write */ -export function stable64Write(offset: nat64, buffer: blob): void { +export function stable64Write(offset: nat64, buf: blob): void { if (globalThis._azleIc === undefined) { return undefined as any; } - const paramsCandidBytes = encode([nat64, blob], [offset, buffer]).buffer; - - return globalThis._azleIc.stable64Write(paramsCandidBytes); + return globalThis._azleIc.stable64Write(offset.toString(), buf.buffer); } diff --git a/src/lib/ic/stable_grow.ts b/src/lib/ic/stable_grow.ts index 553615d6dd..d70a823116 100644 --- a/src/lib/ic/stable_grow.ts +++ b/src/lib/ic/stable_grow.ts @@ -1,6 +1,4 @@ import { nat32 } from '../candid/types/primitive/nats/nat32'; -import { decode } from '../candid/serde/decode'; -import { encode } from '../candid/serde/encode'; /** * Attempts to grow the stable memory by `newPages`. @@ -12,10 +10,5 @@ export function stableGrow(newPages: nat32): nat32 { return undefined as any; } - const newPagesCandidBytes = encode(nat32, newPages).buffer; - - return decode( - nat32, - globalThis._azleIc.stableGrow(newPagesCandidBytes) - ) as number; + return Number(globalThis._azleIc.stableGrow(newPages.toString())); } diff --git a/src/lib/ic/stable_read.ts b/src/lib/ic/stable_read.ts index 4de6a65882..187b1a7791 100644 --- a/src/lib/ic/stable_read.ts +++ b/src/lib/ic/stable_read.ts @@ -12,7 +12,7 @@ export function stableRead(offset: nat32, length: nat32): Uint8Array { return undefined as any; } - const paramsCandidBytes = encode([nat32, nat32], [offset, length]).buffer; - - return new Uint8Array(globalThis._azleIc.stableRead(paramsCandidBytes)); + return new Uint8Array( + globalThis._azleIc.stableRead(offset.toString(), length.toString()) + ); } diff --git a/src/lib/ic/stable_size.ts b/src/lib/ic/stable_size.ts index 71cb1cae8e..8534712bdf 100644 --- a/src/lib/ic/stable_size.ts +++ b/src/lib/ic/stable_size.ts @@ -10,5 +10,5 @@ export function stableSize(): nat32 { return undefined as any; } - return decode(nat32, globalThis._azleIc.stableSize()) as number; + return Number(globalThis._azleIc.stableSize()); } diff --git a/src/lib/ic/stable_write.ts b/src/lib/ic/stable_write.ts index ae704011da..9ed526005f 100644 --- a/src/lib/ic/stable_write.ts +++ b/src/lib/ic/stable_write.ts @@ -11,12 +11,10 @@ import { encode } from '../candid/serde/encode'; * @param offset the location at which to write * @param buffer the data to write */ -export function stableWrite(offset: nat32, buffer: blob): void { +export function stableWrite(offset: nat32, buf: blob): void { if (globalThis._azleIc === undefined) { return undefined as any; } - const paramsCandidBytes = encode([nat32, blob], [offset, buffer]).buffer; - - return globalThis._azleIc.stableWrite(paramsCandidBytes); + return globalThis._azleIc.stableWrite(offset.toString(), buf.buffer); } diff --git a/src/lib/ic/time.ts b/src/lib/ic/time.ts index eca31f9252..7521f7114a 100644 --- a/src/lib/ic/time.ts +++ b/src/lib/ic/time.ts @@ -10,6 +10,5 @@ export function time(): nat64 { return undefined as any; } - const timeCandidBytes = globalThis._azleIc.time(); - return decode(nat64, timeCandidBytes); + return BigInt(globalThis._azleIc.time()); } diff --git a/src/lib/ic/types/azle_ic.ts b/src/lib/ic/types/azle_ic.ts index c915aab141..35c2513665 100644 --- a/src/lib/ic/types/azle_ic.ts +++ b/src/lib/ic/types/azle_ic.ts @@ -28,7 +28,7 @@ export type AzleIc = { clearTimer: (timerIdBytes: ArrayBufferLike) => void; dataCertificate: () => ArrayBufferLike | undefined; id: () => string; - instructionCounter: () => ArrayBufferLike; + instructionCounter: () => string; isController: (principalBytes: ArrayBufferLike) => boolean; msgCyclesAccept: (maxAmountCandidBytes: ArrayBufferLike) => ArrayBufferLike; msgCyclesAccept128: ( @@ -44,9 +44,7 @@ export type AzleIc = { argsRawBuffer: ArrayBufferLike, paymentCandidBytes: ArrayBufferLike ) => void; - performanceCounter: ( - counterTypeCandidBytes: ArrayBufferLike - ) => ArrayBufferLike; + performanceCounter: (counterType: string) => string; rejectCode: () => number; replyRaw: (bytes: ArrayBufferLike) => void; setCertifiedData: (dataBytes: ArrayBufferLike) => void; @@ -59,15 +57,15 @@ export type AzleIc = { timerCallbackId: string ) => ArrayBufferLike; stableBytes: () => ArrayBufferLike; - stableGrow: (newPagesCandidBytes: ArrayBufferLike) => ArrayBufferLike; - stableRead: (paramsCandidBytes: ArrayBufferLike) => ArrayBufferLike; - stableSize: () => ArrayBufferLike; - stableWrite: (paramsCandidBytes: ArrayBufferLike) => void; - stable64Grow: (newPagesCandidBytes: ArrayBufferLike) => ArrayBufferLike; - stable64Read: (paramsCandidBytes: ArrayBufferLike) => ArrayBufferLike; - stable64Size: () => ArrayBufferLike; - stable64Write: (paramsCandidBytes: ArrayBufferLike) => void; - time: () => ArrayBufferLike; + stableGrow: (newPages: string) => string; + stableRead: (offset: string, length: string) => ArrayBufferLike; + stableSize: () => string; + stableWrite: (offset: string, buf: ArrayBufferLike) => void; + stable64Grow: (newPages: string) => string; + stable64Read: (offset: string, length: string) => ArrayBufferLike; + stable64Size: () => string; + stable64Write: (offset: string, buf: ArrayBufferLike) => void; + time: () => string; // These calls aren't intercepted by our IC object, they go right to the // rust version and come out. Since they don't need to be intercepted I am // assuming that their types are the same as the types declared by our