-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
133 additions
and
126 deletions.
There are no files selected for viewing
Binary file not shown.
10 changes: 5 additions & 5 deletions
10
...le/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/msg_cycles_accept.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
use rquickjs::{Ctx, Function}; | ||
use ic_cdk::api::call::msg_cycles_accept128; | ||
use rquickjs::{Ctx, Function, Result}; | ||
|
||
pub fn get_function(context: Ctx) -> Function { | ||
Function::new(context, |max_amount_string: String| { | ||
pub fn get_function(ctx: Ctx) -> Result<Function> { | ||
Function::new(ctx, |max_amount_string: String| { | ||
let max_amount: u128 = max_amount_string.parse().unwrap(); | ||
|
||
ic_cdk::api::call::msg_cycles_accept128(max_amount).to_string() | ||
msg_cycles_accept128(max_amount).to_string() | ||
}) | ||
.unwrap() | ||
} |
10 changes: 4 additions & 6 deletions
10
...commands/compile/wasm_binary/rust/stable_canister_template/src/ic/msg_cycles_available.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
use rquickjs::{Ctx, Function}; | ||
use ic_cdk::api::call::msg_cycles_available128; | ||
use rquickjs::{Ctx, Function, Result}; | ||
|
||
pub fn get_function(context: Ctx) -> Function { | ||
Function::new(context, || { | ||
ic_cdk::api::call::msg_cycles_available128().to_string() | ||
}) | ||
.unwrap() | ||
pub fn get_function(ctx: Ctx) -> Result<Function> { | ||
Function::new(ctx, || msg_cycles_available128().to_string()) | ||
} |
10 changes: 4 additions & 6 deletions
10
.../commands/compile/wasm_binary/rust/stable_canister_template/src/ic/msg_cycles_refunded.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
use rquickjs::{Ctx, Function}; | ||
use ic_cdk::api::call::msg_cycles_refunded128; | ||
use rquickjs::{Ctx, Function, Result}; | ||
|
||
pub fn get_function(context: Ctx) -> Function { | ||
Function::new(context, || { | ||
ic_cdk::api::call::msg_cycles_refunded128().to_string() | ||
}) | ||
.unwrap() | ||
pub fn get_function(ctx: Ctx) -> Result<Function> { | ||
Function::new(ctx, || msg_cycles_refunded128().to_string()) | ||
} |
7 changes: 3 additions & 4 deletions
7
.../commands/compile/wasm_binary/rust/stable_canister_template/src/ic/performance_counter.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
use rquickjs::{Ctx, Function}; | ||
use rquickjs::{Ctx, Function, Result}; | ||
|
||
pub fn get_function(context: Ctx) -> Function { | ||
Function::new(context, |counter_type: u32| { | ||
pub fn get_function(ctx: Ctx) -> Result<Function> { | ||
Function::new(ctx, |counter_type: u32| -> u64 { | ||
ic_cdk::api::performance_counter(counter_type) | ||
}) | ||
.unwrap() | ||
} |
7 changes: 3 additions & 4 deletions
7
src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/print.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
use rquickjs::{Ctx, Function}; | ||
use rquickjs::{Ctx, Function, Result}; | ||
|
||
pub fn get_function(context: Ctx) -> rquickjs::Function { | ||
Function::new(context, |message: String| { | ||
pub fn get_function(ctx: Ctx) -> Result<Function> { | ||
Function::new(ctx, |message: String| { | ||
ic_cdk::print(message); | ||
}) | ||
.unwrap() | ||
} |
10 changes: 4 additions & 6 deletions
10
src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/reject.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
use rquickjs::{Ctx, Function}; | ||
use ic_cdk::api::call::reject; | ||
use rquickjs::{Ctx, Function, Result}; | ||
|
||
pub fn get_function(context: Ctx) -> Function { | ||
Function::new(context, |message: String| { | ||
ic_cdk::api::call::reject(&message); | ||
}) | ||
.unwrap() | ||
pub fn get_function(ctx: Ctx) -> Result<Function> { | ||
Function::new(ctx, |message: String| reject(&message)) | ||
} |
16 changes: 7 additions & 9 deletions
16
...d/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/reject_code.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
use rquickjs::{Ctx, Function}; | ||
use ic_cdk::api::call::reject_code; | ||
use rquickjs::{Ctx, Function, Result}; | ||
|
||
pub fn get_function(context: Ctx) -> Function { | ||
Function::new(context, || { | ||
let reject_code = ic_cdk::api::call::reject_code(); | ||
pub fn get_function(ctx: Ctx) -> Result<Function> { | ||
Function::new(ctx, || { | ||
let reject_code = reject_code(); | ||
|
||
let reject_code_number = match reject_code { | ||
match reject_code { | ||
ic_cdk::api::call::RejectionCode::NoError => 0, | ||
ic_cdk::api::call::RejectionCode::SysFatal => 1, | ||
ic_cdk::api::call::RejectionCode::SysTransient => 2, | ||
ic_cdk::api::call::RejectionCode::DestinationInvalid => 3, | ||
ic_cdk::api::call::RejectionCode::CanisterReject => 4, | ||
ic_cdk::api::call::RejectionCode::CanisterError => 5, | ||
ic_cdk::api::call::RejectionCode::Unknown => 6, | ||
}; | ||
|
||
reject_code_number | ||
} | ||
}) | ||
.unwrap() | ||
} |
7 changes: 4 additions & 3 deletions
7
...table/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/reject_message.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
use rquickjs::{Ctx, Function}; | ||
use ic_cdk::api::call::reject_message; | ||
use rquickjs::{Ctx, Function, Result}; | ||
|
||
pub fn get_function(context: Ctx) -> Function { | ||
Function::new(context, || ic_cdk::api::call::reject_message()).unwrap() | ||
pub fn get_function(ctx: Ctx) -> Result<Function> { | ||
Function::new(ctx, || reject_message()) | ||
} |
10 changes: 4 additions & 6 deletions
10
...ild/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/reply_raw.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
use rquickjs::{Ctx, Function}; | ||
use ic_cdk::api::call::reply_raw; | ||
use rquickjs::{Ctx, Function, Result, TypedArray}; | ||
|
||
pub fn get_function(context: Ctx) -> rquickjs::Function { | ||
Function::new(context, |bytes: rquickjs::TypedArray<u8>| { | ||
ic_cdk::api::call::reply_raw(bytes.as_ref()); | ||
}) | ||
.unwrap() | ||
pub fn get_function(ctx: Ctx) -> Result<Function> { | ||
Function::new(ctx, |bytes: TypedArray<u8>| reply_raw(bytes.as_ref())) | ||
} |
10 changes: 5 additions & 5 deletions
10
...e/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/set_certified_data.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
use rquickjs::{Ctx, Function}; | ||
use ic_cdk::api::set_certified_data; | ||
use rquickjs::{Ctx, Function, Result, TypedArray}; | ||
|
||
pub fn get_function(context: Ctx) -> Function { | ||
Function::new(context, |bytes: rquickjs::TypedArray<u8>| { | ||
ic_cdk::api::set_certified_data(bytes.as_ref()); | ||
pub fn get_function(ctx: Ctx) -> Result<Function> { | ||
Function::new(ctx, |bytes: TypedArray<u8>| { | ||
set_certified_data(bytes.as_ref()) | ||
}) | ||
.unwrap() | ||
} |
72 changes: 41 additions & 31 deletions
72
...ild/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/set_timer.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,47 @@ | ||
use rquickjs::{Ctx, Function}; | ||
use slotmap::Key; | ||
|
||
use crate::{error::quickjs_call_with_error_handling, quickjs_with_ctx}; | ||
|
||
pub fn get_function(ctx: Ctx) -> Function { | ||
Function::new(ctx, |delay: String, callback_id: String| { | ||
let delay: u64 = delay.parse().unwrap(); | ||
let delay_duration = core::time::Duration::new(delay, 0); | ||
use core::time::Duration; | ||
|
||
let closure = move || { | ||
quickjs_with_ctx(|ctx| { | ||
let global = ctx.globals(); | ||
let timer_callbacks = global | ||
.get::<_, rquickjs::Object>("_azleTimerCallbacks") | ||
.unwrap(); | ||
let timer_callback: Function = timer_callbacks.get(callback_id.as_str()).unwrap(); | ||
|
||
let result = | ||
quickjs_call_with_error_handling(ctx.clone(), timer_callback, ()).unwrap(); | ||
use ic_cdk_timers::{set_timer, TimerId}; | ||
use rquickjs::{Ctx, Function, Object, Result}; | ||
use slotmap::Key; | ||
|
||
if result.is_exception() { | ||
panic!("Timer callback threw an exception"); | ||
use crate::{error::quickjs_call_with_error_handling, ic::throw_error, quickjs_with_ctx}; | ||
|
||
pub fn get_function(ctx: Ctx) -> Result<Function> { | ||
Function::new( | ||
ctx.clone(), | ||
move |delay: String, callback_id: String| -> Result<u64> { | ||
let delay: u64 = delay.parse().map_err(|e| throw_error(ctx.clone(), e))?; | ||
let delay_duration = Duration::new(delay, 0); | ||
|
||
let closure = move || { | ||
let result = quickjs_with_ctx(|ctx| { | ||
let globals = ctx.globals(); | ||
|
||
let timer_callbacks: Object = | ||
globals.get("_azleTimerCallbacks").map_err(|e| { | ||
format!("Failed to get globalThis._azleTimerCallbacks: {e}") | ||
})?; | ||
let timer_callback: Function = | ||
timer_callbacks.get(callback_id.as_str()).map_err(|e| { | ||
format!( | ||
"Failed to get globalThis._azleTimerCallbacks[{callback_id}]: {e}" | ||
) | ||
})?; | ||
|
||
quickjs_call_with_error_handling(ctx, timer_callback, ())?; | ||
|
||
Ok(()) | ||
}); | ||
|
||
if let Err(e) = result { | ||
ic_cdk::trap(&format!("Azle TimerError: {e}")); | ||
} | ||
}; | ||
|
||
Ok(()) | ||
}) | ||
.unwrap(); | ||
}; | ||
|
||
let timer_id: ic_cdk_timers::TimerId = ic_cdk_timers::set_timer(delay_duration, closure); | ||
let timer_id_u64: u64 = timer_id.data().as_ffi(); | ||
let timer_id: TimerId = set_timer(delay_duration, closure); | ||
let timer_id_u64: u64 = timer_id.data().as_ffi(); | ||
|
||
timer_id_u64 | ||
}) | ||
.unwrap() | ||
Ok(timer_id_u64) | ||
}, | ||
) | ||
} |
73 changes: 41 additions & 32 deletions
73
...e/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/set_timer_interval.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,47 @@ | ||
use rquickjs::{Ctx, Function}; | ||
use slotmap::Key; | ||
|
||
use crate::{error::quickjs_call_with_error_handling, quickjs_with_ctx}; | ||
|
||
pub fn get_function(ctx: Ctx) -> Function { | ||
Function::new(ctx, |interval: String, callback_id: String| { | ||
let interval: u64 = interval.parse().unwrap(); | ||
let interval_duration = core::time::Duration::new(interval, 0); | ||
use core::time::Duration; | ||
|
||
let closure = move || { | ||
quickjs_with_ctx(|ctx| { | ||
let global = ctx.globals(); | ||
let timer_callbacks = global | ||
.get::<_, rquickjs::Object>("_azleTimerCallbacks") | ||
.unwrap(); | ||
let timer_callback: Function = timer_callbacks.get(callback_id.as_str()).unwrap(); | ||
|
||
let result = | ||
quickjs_call_with_error_handling(ctx.clone(), timer_callback, ()).unwrap(); | ||
use ic_cdk_timers::{set_timer_interval, TimerId}; | ||
use rquickjs::{Ctx, Function, Object, Result}; | ||
use slotmap::Key; | ||
|
||
if result.is_exception() { | ||
panic!("Timer interval callback threw an exception"); | ||
use crate::{error::quickjs_call_with_error_handling, ic::throw_error, quickjs_with_ctx}; | ||
|
||
pub fn get_function(ctx: Ctx) -> Result<Function> { | ||
Function::new( | ||
ctx.clone(), | ||
move |interval: String, callback_id: String| -> Result<u64> { | ||
let interval: u64 = interval.parse().map_err(|e| throw_error(ctx.clone(), e))?; | ||
let interval_duration = Duration::new(interval, 0); | ||
|
||
let closure = move || { | ||
let result = quickjs_with_ctx(|ctx| { | ||
let globals = ctx.globals(); | ||
|
||
let timer_callbacks: Object = | ||
globals.get("_azleTimerCallbacks").map_err(|e| { | ||
format!("Failed to get globalThis._azleTimerCallbacks: {e}") | ||
})?; | ||
let timer_callback: Function = | ||
timer_callbacks.get(callback_id.as_str()).map_err(|e| { | ||
format!( | ||
"Failed to get globalThis._azleTimerCallbacks[{callback_id}]: {e}" | ||
) | ||
})?; | ||
|
||
quickjs_call_with_error_handling(ctx, timer_callback, ())?; | ||
|
||
Ok(()) | ||
}); | ||
|
||
if let Err(e) = result { | ||
ic_cdk::trap(&format!("Azle TimerIntervalError: {e}")); | ||
} | ||
}; | ||
|
||
Ok(()) | ||
}) | ||
.unwrap(); | ||
}; | ||
|
||
let timer_id: ic_cdk_timers::TimerId = | ||
ic_cdk_timers::set_timer_interval(interval_duration, closure); | ||
let timer_id_u64: u64 = timer_id.data().as_ffi(); | ||
let timer_id: TimerId = set_timer_interval(interval_duration, closure); | ||
let timer_id_u64: u64 = timer_id.data().as_ffi(); | ||
|
||
timer_id_u64 | ||
}) | ||
.unwrap() | ||
Ok(timer_id_u64) | ||
}, | ||
) | ||
} |
7 changes: 4 additions & 3 deletions
7
src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/time.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
use rquickjs::{Ctx, Function}; | ||
use ic_cdk::api::time; | ||
use rquickjs::{Ctx, Function, Result}; | ||
|
||
pub fn get_function(context: Ctx) -> Function { | ||
Function::new(context, || ic_cdk::api::time()).unwrap() | ||
pub fn get_function(ctx: Ctx) -> Result<Function> { | ||
Function::new(ctx, || time()) | ||
} |
10 changes: 4 additions & 6 deletions
10
src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/trap.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
use rquickjs::{Ctx, Function}; | ||
use ic_cdk::api::trap; | ||
use rquickjs::{Ctx, Function, Result}; | ||
|
||
pub fn get_function(context: Ctx) -> Function { | ||
Function::new(context, |message: String| { | ||
ic_cdk::api::trap(&message); | ||
}) | ||
.unwrap() | ||
pub fn get_function(ctx: Ctx) -> Result<Function> { | ||
Function::new(ctx, |message: String| trap(&message)) | ||
} |