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

feat!: next generation of Rust CDK #521

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
279de07
feat: struct Call to support best effort responses (#496)
lwshang Jun 18, 2024
36c837b
Merge branch 'main' into next
lwshang Sep 3, 2024
107fa7d
feat!: ic0 handles 32/64-bit system API (#514)
lwshang Sep 3, 2024
1d99280
Merge branch 'main' into next
lwshang Sep 18, 2024
b10be57
Merge branch 'main' into next
lwshang Oct 4, 2024
3d06c9e
non-beta dfx in examples.yml
lwshang Oct 4, 2024
7a64c21
refactor!: crates architecture (#522)
lwshang Oct 9, 2024
69a459d
bump crates to alpha.1 (#524)
lwshang Oct 11, 2024
69d98b0
fix: update/query macro could not handle function arguments with the …
lwshang Oct 11, 2024
907b7d9
Merge branch 'main' into next
lwshang Nov 12, 2024
a061429
move back management_canister mod (#533)
lwshang Dec 4, 2024
605abca
Merge branch 'main' into next
lwshang Dec 4, 2024
9f9c0f7
feat: root call mod with new CallError (#535)
lwshang Dec 11, 2024
d98a6ff
feat: no more tuples in Call (#539)
lwshang Dec 16, 2024
0ab2864
feat: root management canister mod with new bindings (#538)
lwshang Dec 18, 2024
65443f9
refactor: api module overhaul (#540)
lwshang Dec 19, 2024
921c858
Merge branch 'main' into next
lwshang Dec 19, 2024
e2bbc39
chore: e2e wasm64 (#534)
lwshang Dec 20, 2024
c2ba198
chore: deprecate old call API (#542)
lwshang Dec 20, 2024
14e10db
chore: deprecate other APIs in api/call.rs (#543)
lwshang Jan 3, 2025
3184c9c
feat: macros that decoding arguments can set custom decoder using dec…
lwshang Jan 10, 2025
5fb07f5
feat: safe binding for msg_deadline (#545)
lwshang Jan 13, 2025
710fc59
chore: deprecate remaining items in api/call.rs (#546)
lwshang Jan 15, 2025
68f98ce
feat: CallError redesign (#548)
lwshang Jan 16, 2025
4e287ce
chore: call module followup (#549)
lwshang Jan 17, 2025
7349253
refactor: type crates (#550)
lwshang Jan 22, 2025
d823cb5
feat: simplify Call implementation and enable retry logic (#551)
lwshang Jan 24, 2025
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
4 changes: 4 additions & 0 deletions e2e-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ path = "canisters/management_caller.rs"
name = "chunk"
path = "canisters/chunk.rs"

[[bin]]
name = "call_struct"
path = "canisters/call_struct.rs"

[dev-dependencies]
hex.workspace = true
pocket-ic = "4"
17 changes: 17 additions & 0 deletions e2e-tests/canisters/call_struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use candid::Principal;
use ic_cdk::api::management_canister::main::{CanisterIdRecord, CreateCanisterArgument};
use ic_cdk::prelude::*;

#[update]
async fn create_canister_via_struct() -> Principal {
let res: (CanisterIdRecord,) = Call::new(Principal::management_canister(), "create_canister")
.with_args((CreateCanisterArgument::default(),))
.with_cycles(200_000_000_000)
.with_guaranteed_response()
.call()
.await
.unwrap();
res.0.canister_id
}

fn main() {}
11 changes: 11 additions & 0 deletions e2e-tests/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,3 +642,14 @@ fn test_chunk() {
)
.expect("Error calling call_install_chunked_code");
}

#[test]
fn call_struct() {
let pic = PocketIc::new();
let wasm = cargo_build_canister("call_struct");
let canister_id = pic.create_canister();
pic.add_cycles(canister_id, 100_000_000_000_000);
pic.install_canister(canister_id, wasm, vec![], None);
let _: (Principal,) = call_candid(&pic, canister_id, "create_canister_via_struct", ())
.expect("Error calling execute_main_methods");
}
1 change: 1 addition & 0 deletions examples/counter/tests/basic.bats
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load ../../bats/bats-support/load.bash
load ../../bats/bats-assert/load.bash

# Executed before each test.
Expand Down
1 change: 1 addition & 0 deletions examples/profile/tests/basic.bats
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load ../../bats/bats-support/load.bash
load ../../bats/bats-assert/load.bash

# Executed before each test.
Expand Down
126 changes: 55 additions & 71 deletions ic0.txt
Original file line number Diff line number Diff line change
@@ -1,71 +1,55 @@
ic0.msg_arg_data_size : () -> i32; // I U Q CQ Ry CRy F
ic0.msg_arg_data_copy : (dst : i32, offset : i32, size : i32) -> (); // I U Q CQ Ry CRy F
ic0.msg_caller_size : () -> i32; // *
ic0.msg_caller_copy : (dst : i32, offset: i32, size : i32) -> (); // *
ic0.msg_reject_code : () -> i32; // Ry Rt CRy CRt
ic0.msg_reject_msg_size : () -> i32; // Rt CRt
ic0.msg_reject_msg_copy : (dst : i32, offset : i32, size : i32) -> (); // Rt CRt

ic0.msg_reply_data_append : (src : i32, size : i32) -> (); // U Q CQ Ry Rt CRy CRt
ic0.msg_reply : () -> (); // U Q CQ Ry Rt CRy CRt
ic0.msg_reject : (src : i32, size : i32) -> (); // U Q CQ Ry Rt CRy CRt

ic0.msg_cycles_available : () -> i64; // U Rt Ry
ic0.msg_cycles_available128 : (dst : i32) -> (); // U Rt Ry
ic0.msg_cycles_refunded : () -> i64; // Rt Ry
ic0.msg_cycles_refunded128 : (dst : i32) -> (); // Rt Ry
ic0.msg_cycles_accept : (max_amount : i64) -> (amount : i64); // U Rt Ry
ic0.msg_cycles_accept128 : (max_amount_high : i64, max_amount_low: i64, dst : i32)
-> (); // U Rt Ry

ic0.cycles_burn128 : (amount_high : i64, amount_low : i64, dst : i32) -> (); // I G U Ry Rt C T

ic0.canister_self_size : () -> i32; // *
ic0.canister_self_copy : (dst : i32, offset : i32, size : i32) -> (); // *
ic0.canister_cycle_balance : () -> i64; // *
ic0.canister_cycle_balance128 : (dst : i32) -> (); // *
ic0.canister_status : () -> i32; // *
ic0.canister_version : () -> i64; // *

ic0.msg_method_name_size : () -> i32; // F
ic0.msg_method_name_copy : (dst : i32, offset : i32, size : i32) -> (); // F
ic0.accept_message : () -> (); // F

ic0.call_new : // U CQ Ry Rt CRy CRt T
( callee_src : i32,
callee_size : i32,
name_src : i32,
name_size : i32,
reply_fun : i32,
reply_env : i32,
reject_fun : i32,
reject_env : i32
) -> ();
ic0.call_on_cleanup : (fun : i32, env : i32) -> (); // U CQ Ry Rt CRy CRt T
ic0.call_data_append : (src : i32, size : i32) -> (); // U CQ Ry Rt CRy CRt T
ic0.call_cycles_add : (amount : i64) -> (); // U Ry Rt T
ic0.call_cycles_add128 : (amount_high : i64, amount_low: i64) -> (); // U Ry Rt T
ic0.call_perform : () -> ( err_code : i32 ); // U CQ Ry Rt CRy CRt T

ic0.stable_size : () -> (page_count : i32); // * s
ic0.stable_grow : (new_pages : i32) -> (old_page_count : i32); // * s
ic0.stable_write : (offset : i32, src : i32, size : i32) -> (); // * s
ic0.stable_read : (dst : i32, offset : i32, size : i32) -> (); // * s
ic0.stable64_size : () -> (page_count : i64); // * s
ic0.stable64_grow : (new_pages : i64) -> (old_page_count : i64); // * s
ic0.stable64_write : (offset : i64, src : i64, size : i64) -> (); // * s
ic0.stable64_read : (dst : i64, offset : i64, size : i64) -> (); // * s

ic0.certified_data_set : (src: i32, size: i32) -> (); // I G U Ry Rt T
ic0.data_certificate_present : () -> i32; // *
ic0.data_certificate_size : () -> i32; // Q CQ
ic0.data_certificate_copy : (dst: i32, offset: i32, size: i32) -> (); // Q CQ

ic0.time : () -> (timestamp : i64); // *
ic0.global_timer_set : (timestamp : i64) -> i64; // I G U Ry Rt C T
ic0.performance_counter : (counter_type : i32) -> (counter : i64); // * s
ic0.is_controller: (src: i32, size: i32) -> ( result: i32); // * s
ic0.in_replicated_execution: () -> (result: i32); // * s

ic0.debug_print : (src : i32, size : i32) -> (); // * s
ic0.trap : (src : i32, size : i32) -> (); // * s
ic0.msg_arg_data_size : () -> I; // I U RQ NRQ CQ Ry CRy F
ic0.msg_arg_data_copy : (dst : I, offset : I, size : I) -> (); // I U RQ NRQ CQ Ry CRy F
ic0.msg_caller_size : () -> I; // *
ic0.msg_caller_copy : (dst : I, offset : I, size : I) -> (); // *
ic0.msg_reject_code : () -> i32; // Ry Rt CRy CRt
ic0.msg_reject_msg_size : () -> I ; // Rt CRt
ic0.msg_reject_msg_copy : (dst : I, offset : I, size : I) -> (); // Rt CRt
ic0.msg_deadline : () -> i64; // U Q CQ Ry Rt CRy CRt
ic0.msg_reply_data_append : (src : I, size : I) -> (); // U RQ NRQ CQ Ry Rt CRy CRt
ic0.msg_reply : () -> (); // U RQ NRQ CQ Ry Rt CRy CRt
ic0.msg_reject : (src : I, size : I) -> (); // U RQ NRQ CQ Ry Rt CRy CRt
ic0.msg_cycles_available128 : (dst : I) -> (); // U Rt Ry
ic0.msg_cycles_refunded128 : (dst : I) -> (); // Rt Ry
ic0.msg_cycles_accept128 : (max_amount_high : i64, max_amount_low: i64, dst : I)
-> (); // U Rt Ry
ic0.cycles_burn128 : (amount_high : i64, amount_low : i64, dst : I)
-> (); // I G U Ry Rt C T
ic0.canister_self_size : () -> I; // *
ic0.canister_self_copy : (dst : I, offset : I, size : I) -> (); // *
ic0.canister_cycle_balance128 : (dst : I) -> (); // *
ic0.canister_status : () -> i32; // *
ic0.canister_version : () -> i64; // *
ic0.msg_method_name_size : () -> I; // F
ic0.msg_method_name_copy : (dst : I, offset : I, size : I) -> (); // F
ic0.accept_message : () -> (); // F
ic0.call_new :
( callee_src : I,
callee_size : I,
name_src : I,
name_size : I,
reply_fun : I,
reply_env : I,
reject_fun : I,
reject_env : I
) -> (); // U CQ Ry Rt CRy CRt T
ic0.call_on_cleanup : (fun : I, env : I) -> (); // U CQ Ry Rt CRy CRt T
ic0.call_data_append : (src : I, size : I) -> (); // U CQ Ry Rt CRy CRt T
ic0.call_with_best_effort_response : (timeout_seconds : i32) -> (); // U CQ Ry Rt CRy CRt T
ic0.call_cycles_add128 : (amount_high : i64, amount_low: i64) -> (); // U Ry Rt T
ic0.call_perform : () -> ( err_code : i32 ); // U CQ Ry Rt CRy CRt T
ic0.stable64_size : () -> (page_count : i64); // * s
ic0.stable64_grow : (new_pages : i64) -> (old_page_count : i64); // * s
ic0.stable64_write : (offset : i64, src : i64, size : i64) -> (); // * s
ic0.stable64_read : (dst : i64, offset : i64, size : i64) -> (); // * s
ic0.certified_data_set : (src : I, size : I) -> (); // I G U Ry Rt T
ic0.data_certificate_present : () -> i32; // *
ic0.data_certificate_size : () -> I; // NRQ CQ
ic0.data_certificate_copy : (dst : I, offset : I, size : I) -> (); // NRQ CQ
ic0.time : () -> (timestamp : i64); // *
ic0.global_timer_set : (timestamp : i64) -> i64; // I G U Ry Rt C T
ic0.performance_counter : (counter_type : i32) -> (counter : i64); // * s
ic0.is_controller: (src : I, size : I) -> ( result: i32); // * s
ic0.in_replicated_execution: () -> (result: i32); // * s
ic0.debug_print : (src : I, size : I) -> (); // * s
ic0.trap : (src : I, size : I) -> (); // * s
2 changes: 2 additions & 0 deletions src/candid-extractor/ic_mock.wat
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
(func (export "msg_reject_code") (result i32) i32.const 0)
(func (export "msg_reject_msg_size") (result i32) i32.const 0)
(func (export "msg_reject_msg_copy") (param i32 i32 i32) )
(func (export "msg_deadline") (result i64) i64.const 0)
(func (export "msg_reply_data_append") (param i32 i32) )
(func (export "msg_reply") )
(func (export "msg_reject") (param i32 i32) )
Expand All @@ -30,6 +31,7 @@
(func (export "call_new") (param i32 i32 i32 i32 i32 i32 i32 i32) )
(func (export "call_on_cleanup") (param i32 i32) )
(func (export "call_data_append") (param i32 i32) )
(func (export "call_with_best_effort_response") (param i32) )
(func (export "call_cycles_add") (param i64) )
(func (export "call_cycles_add128") (param i64 i64) )
(func (export "call_perform") (result i32) i32.const 0)
Expand Down
3 changes: 2 additions & 1 deletion src/ic-cdk-timers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ extern "C" fn global_timer() {
| RejectionCode::DestinationInvalid
| RejectionCode::CanisterReject
| RejectionCode::CanisterError
| RejectionCode::SysUnknown
| RejectionCode::Unknown => {}
}
}
Expand Down Expand Up @@ -254,7 +255,7 @@ fn update_ic0_timer() {
};
if should_change {
// SAFETY: ic0::global_timer_set is always a safe call
unsafe { ic0::global_timer_set(soonest_timer.unwrap() as i64) };
unsafe { ic0::global_timer_set(soonest_timer.unwrap()) };
MOST_RECENT.with(|recent| recent.set(soonest_timer));
}
});
Expand Down
Loading
Loading