Skip to content

Commit

Permalink
attempt to fix number conversions, always use strings
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Jan 17, 2024
1 parent 889e588 commit 0b28751
Show file tree
Hide file tree
Showing 21 changed files with 52 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/compiler/rust/canister/src/ic/arg_data_raw_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use wasmedge_quickjs::{Context, JsFn, JsValue};
pub struct NativeFunction;
impl JsFn for NativeFunction {
fn call(context: &mut Context, this_val: JsValue, argv: &[JsValue]) -> JsValue {
i32::try_from(ic_cdk::api::call::arg_data_raw_size())
.unwrap()
context
.new_string(&ic_cdk::api::call::arg_data_raw_size().to_string())
.into()
}
}
4 changes: 3 additions & 1 deletion src/compiler/rust/canister/src/ic/canister_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use wasmedge_quickjs::{Context, JsFn, JsValue};
pub struct NativeFunction;
impl JsFn for NativeFunction {
fn call(context: &mut Context, this_val: JsValue, argv: &[JsValue]) -> JsValue {
ic_cdk::api::canister_balance().into()
context
.new_string(&ic_cdk::api::canister_balance().to_string())
.into()
}
}
4 changes: 3 additions & 1 deletion src/compiler/rust/canister/src/ic/canister_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use wasmedge_quickjs::{Context, JsFn, JsValue};
pub struct NativeFunction;
impl JsFn for NativeFunction {
fn call(context: &mut Context, this_val: JsValue, argv: &[JsValue]) -> JsValue {
ic_cdk::api::canister_version().into()
context
.new_string(&ic_cdk::api::canister_version().to_string())
.into()
}
}
4 changes: 3 additions & 1 deletion src/compiler/rust/canister/src/ic/instruction_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use wasmedge_quickjs::{Context, JsFn, JsValue};
pub struct NativeFunction;
impl JsFn for NativeFunction {
fn call(context: &mut Context, this_val: JsValue, argv: &[JsValue]) -> JsValue {
ic_cdk::api::instruction_counter().into()
context
.new_string(&ic_cdk::api::instruction_counter().to_string())
.into()
}
}
7 changes: 6 additions & 1 deletion src/compiler/rust/canister/src/ic/performance_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ impl JsFn for NativeFunction {
panic!("conversion from JsValue to JsString failed")
};

ic_cdk::api::call::performance_counter(counter_type_string.parse().unwrap()).into()
context
.new_string(
&ic_cdk::api::call::performance_counter(counter_type_string.parse().unwrap())
.to_string(),
)
.into()
}
}
2 changes: 1 addition & 1 deletion src/compiler/rust/canister/src/ic/reject_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ impl JsFn for NativeFunction {
ic_cdk::api::call::RejectionCode::Unknown => 6,
};

reject_code_number.into()
context.new_string(&reject_code_number.to_string()).into()
}
}
8 changes: 6 additions & 2 deletions src/compiler/rust/canister/src/ic/stable64_grow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ impl JsFn for NativeFunction {
panic!("conversion from JsValue to JsString failed")
};

ic_cdk::api::stable::stable64_grow(new_pages_string.parse().unwrap())
.unwrap()
context
.new_string(
&ic_cdk::api::stable::stable64_grow(new_pages_string.parse().unwrap())
.unwrap()
.to_string(),
)
.into()
}
}
4 changes: 3 additions & 1 deletion src/compiler/rust/canister/src/ic/stable64_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use wasmedge_quickjs::{Context, JsFn, JsValue};
pub struct NativeFunction;
impl JsFn for NativeFunction {
fn call(context: &mut Context, this_val: JsValue, argv: &[JsValue]) -> JsValue {
ic_cdk::api::stable::stable64_size().into()
context
.new_string(&ic_cdk::api::stable::stable64_size().to_string())
.into()
}
}
2 changes: 1 addition & 1 deletion src/compiler/rust/canister/src/ic/stable_b_tree_map_len.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ impl JsFn for NativeFunction {
stable_b_tree_maps[&memory_id].len()
});

len.into()
context.new_string(&len.to_string()).into()
}
}
2 changes: 1 addition & 1 deletion src/compiler/rust/canister/src/ic/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ use wasmedge_quickjs::{Context, JsFn, JsValue};
pub struct NativeFunction;
impl JsFn for NativeFunction {
fn call(context: &mut Context, this_val: JsValue, argv: &[JsValue]) -> JsValue {
ic_cdk::api::time().into()
context.new_string(&ic_cdk::api::time().to_string()).into()
}
}
2 changes: 1 addition & 1 deletion src/lib/ic/arg_data_raw_size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import { nat32 } from '../candid/types/primitive/nats/nat32';
*/
export function argDataRawSize(): nat32 {
return globalThis._azleIc
? globalThis._azleIc.argDataRawSize()
? Number(globalThis._azleIc.argDataRawSize())
: (undefined as any);
}
2 changes: 1 addition & 1 deletion src/lib/ic/canister_balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export function canisterBalance(): nat64 {
return undefined as any;
}

return globalThis._azleIc.canisterBalance();
return BigInt(globalThis._azleIc.canisterBalance());
}
2 changes: 1 addition & 1 deletion src/lib/ic/canister_version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export function canisterVersion(): nat64 {
return undefined as any;
}

return globalThis._azleIc.canisterVersion();
return BigInt(globalThis._azleIc.canisterVersion());
}
2 changes: 1 addition & 1 deletion src/lib/ic/instruction_counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export function instructionCounter(): nat64 {
return undefined as any;
}

return globalThis._azleIc.instructionCounter();
return BigInt(globalThis._azleIc.instructionCounter());
}
4 changes: 3 additions & 1 deletion src/lib/ic/performance_counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ export function performanceCounter(counterType: nat32): nat64 {
return undefined as any;
}

return globalThis._azleIc.performanceCounter(counterType.toString());
return BigInt(
globalThis._azleIc.performanceCounter(counterType.toString())
);
}
2 changes: 1 addition & 1 deletion src/lib/ic/reject_code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function rejectCode(): RejectionCode {
return undefined as any;
}

const rejectCodeNumber = globalThis._azleIc.rejectCode();
const rejectCodeNumber = Number(globalThis._azleIc.rejectCode());

switch (rejectCodeNumber) {
case 0:
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ic/stable_64_grow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export function stable64Grow(newPages: nat64): nat64 {
return undefined as any;
}

return globalThis._azleIc.stable64Grow(newPages.toString());
return BigInt(globalThis._azleIc.stable64Grow(newPages.toString()));
}
2 changes: 1 addition & 1 deletion src/lib/ic/stable_64_size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export function stable64Size(): nat64 {
return undefined as any;
}

return globalThis._azleIc.stable64Size();
return BigInt(globalThis._azleIc.stable64Size());
}
2 changes: 1 addition & 1 deletion src/lib/ic/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export function time(): nat64 {
return undefined as any;
}

return globalThis._azleIc.time();
return BigInt(globalThis._azleIc.time());
}
22 changes: 11 additions & 11 deletions src/lib/ic/types/azle_ic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
export type AzleIc = {
argDataRaw: () => ArrayBufferLike;
argDataRawSize: () => number;
argDataRawSize: () => string;
callRaw: (
promiseId: string,
canisterIdBytes: ArrayBufferLike,
Expand All @@ -22,28 +22,28 @@ export type AzleIc = {
caller: () => ArrayBufferLike;
candidDecode: (candidBytes: ArrayBufferLike) => string;
candidEncode: (candidString: string) => ArrayBufferLike;
canisterBalance: () => bigint;
canisterBalance: () => string;
canisterBalance128: () => string;
canisterVersion: () => bigint;
canisterVersion: () => string;
clearTimer: (timerIdString: string) => void;
dataCertificate: () => ArrayBufferLike | undefined;
id: () => string;
instructionCounter: () => bigint;
instructionCounter: () => string;
isController: (principalBytes: ArrayBufferLike) => boolean;
msgCyclesAccept: (maxAmountString: string) => string;
msgCyclesAccept128: (maxAmountString: string) => string;
msgCyclesAvailable: () => string;
msgCyclesAvailable128: () => string;
msgCyclesRefunded: () => bigint;
msgCyclesRefunded: () => string;
msgCyclesRefunded128: () => string;
notifyRaw: (
canisterIdBytes: ArrayBufferLike,
method: string,
argsRawBuffer: ArrayBufferLike,
paymentString: string
) => void;
performanceCounter: (counterType: string) => bigint;
rejectCode: () => number;
performanceCounter: (counterType: string) => string;
rejectCode: () => string;
replyRaw: (bytes: ArrayBufferLike) => void;
setCertifiedData: (dataBytes: ArrayBufferLike) => void;
setTimer: (delayString: string, timerCallbackId: string) => string;
Expand All @@ -56,11 +56,11 @@ export type AzleIc = {
stableRead: (offset: string, length: string) => ArrayBufferLike;
stableSize: () => string;
stableWrite: (offset: string, buf: ArrayBufferLike) => void;
stable64Grow: (newPages: string) => bigint;
stable64Grow: (newPages: string) => string;
stable64Read: (offset: string, length: string) => ArrayBufferLike;
stable64Size: () => bigint;
stable64Size: () => string;
stable64Write: (offset: string, buf: ArrayBufferLike) => void;
time: () => bigint;
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
Expand Down Expand Up @@ -104,7 +104,7 @@ export type AzleIc = {
startIndex: string,
length: string
) => ArrayBuffer[];
stableBTreeMapLen: (memoryId: string) => bigint;
stableBTreeMapLen: (memoryId: string) => string;
stableBTreeMapRemove(
memoryId: string,
encodedKey: ArrayBufferLike
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stable_structures/stable_b_tree_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export function StableBTreeMap<Key = any, Value = any>(
return undefined as any;
}

return globalThis._azleIc.stableBTreeMapLen(memoryId);
return BigInt(globalThis._azleIc.stableBTreeMapLen(memoryId));
},
/**
* Removes a key from the map.
Expand Down

0 comments on commit 0b28751

Please sign in to comment.