Skip to content

Commit bd9e7ec

Browse files
Akhilesh SinghaniaEric Swanson
andauthored
feat: Update to ic-ref-0.14 (#36)
Co-authored-by: Eric Swanson <[email protected]>
1 parent 9809f51 commit bd9e7ec

File tree

6 files changed

+44
-76
lines changed

6 files changed

+44
-76
lines changed

.github/workflows/examples.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- build: linux-stable
1414
os: ubuntu-latest
1515
rust: 1.45.1
16-
dfx: 0.6.10
16+
dfx: 0.6.15
1717

1818
steps:
1919
- uses: actions/checkout@v2
@@ -39,7 +39,7 @@ jobs:
3939
yes | sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)"
4040
4141
- name: Setup BATS
42-
uses: mig4/[email protected].1
42+
uses: mig4/[email protected].2
4343
with:
4444
bats-version: 1.2.1
4545

examples/asset_storage/tests/basic.bats

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
setup() {
33
cd examples/asset_storage
44
# Make sure the directory is clean.
5-
dfx start --clean --background
5+
dfx start --clean --background --host "127.0.0.1:0"
6+
local webserver_port=$(cat .dfx/webserver-port)
7+
cat <<<$(jq .networks.local.bind=\"127.0.0.1:${webserver_port}\" dfx.json) >dfx.json
68

79
run dfx identity new alice
810
run dfx identity new bob

examples/counter/tests/basic.bats

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
setup() {
33
cd examples/counter
44
# Make sure the directory is clean.
5-
dfx start --clean --background
5+
dfx start --clean --background --host "127.0.0.1:0"
6+
local webserver_port=$(cat .dfx/webserver-port)
7+
cat <<<$(jq .networks.local.bind=\"127.0.0.1:${webserver_port}\" dfx.json) >dfx.json
68
}
79

810
# executed after each test

src/ic-cdk/src/api.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pub fn id() -> Principal {
4848
}
4949

5050
/// Get the amount of funds available in the canister.
51-
pub fn canister_balance(unit: call::funds::Unit) -> i64 {
52-
let bytes = unit.to_bytes();
53-
unsafe { ic0::canister_balance(bytes.as_ptr() as i32, bytes.len() as i32) }
51+
pub fn canister_balance() -> i64 {
52+
unsafe { ic0::canister_cycle_balance() }
5453
}

src/ic-cdk/src/api/call.rs

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,9 @@ pub fn call_raw(
119119
);
120120

121121
ic0::call_data_append(args_raw.as_ptr() as i32, args_raw.len() as i32);
122-
123122
if payment > 0 {
124-
let bytes = vec![0u8];
125-
ic0::call_funds_add(bytes.as_ptr() as i32, bytes.len() as i32, payment as i64);
123+
ic0::call_cycles_add(payment as i64);
126124
}
127-
128125
ic0::call_perform()
129126
};
130127

@@ -204,42 +201,16 @@ pub fn reply<T: ArgumentEncoder>(reply: T) {
204201
}
205202
}
206203

207-
/// Economics.
208-
///
209-
/// # Warning
210-
/// This section will be moved and breaking changes significantly before Mercury.
211-
/// The APIs behind it will stay the same, so deployed canisters will keep working.
212-
pub mod funds {
213-
use super::ic0;
214-
215-
pub enum Unit {
216-
Cycle,
217-
IcpToken,
218-
}
219-
220-
impl Unit {
221-
pub fn to_bytes(&self) -> Vec<u8> {
222-
match self {
223-
Unit::Cycle => vec![0],
224-
Unit::IcpToken => vec![1],
225-
}
226-
}
227-
}
228-
229-
pub fn available(unit: Unit) -> i64 {
230-
let bytes = unit.to_bytes();
231-
unsafe { ic0::msg_funds_available(bytes.as_ptr() as i32, bytes.len() as i32) }
232-
}
204+
pub fn msg_cycles_available() -> i64 {
205+
unsafe { ic0::msg_cycles_available() }
206+
}
233207

234-
pub fn refunded(unit: Unit) -> i64 {
235-
let bytes = unit.to_bytes();
236-
unsafe { ic0::msg_funds_refunded(bytes.as_ptr() as i32, bytes.len() as i32) }
237-
}
208+
pub fn msg_cycles_refunded() -> i64 {
209+
unsafe { ic0::msg_cycles_refunded() }
210+
}
238211

239-
pub fn accept(unit: Unit, amount: i64) {
240-
let bytes = unit.to_bytes();
241-
unsafe { ic0::msg_funds_accept(bytes.as_ptr() as i32, bytes.len() as i32, amount) }
242-
}
212+
pub fn msg_cycles_accept(max_amount: i64) -> i64 {
213+
unsafe { ic0::msg_cycles_accept(max_amount) }
243214
}
244215

245216
pub(crate) unsafe fn arg_data_raw() -> Vec<u8> {

src/ic-cdk/src/api/ic0.rs

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ macro_rules! ic0_module {
5858
// This is a private module that can only be used internally in this file.
5959
// Copy-paste the spec section of the API here.
6060
ic0_module! {
61-
ic0.msg_arg_data_size : () -> i32; // I U Q Ry Lb
62-
ic0.msg_arg_data_copy : (dst : i32, offset : i32, size : i32) -> (); // I U Q Ry Lb
63-
ic0.msg_caller_size : () -> (i32); // I G U Q Lb
64-
ic0.msg_caller_copy : (dst : i32, offset: i32, size : i32) -> (); // I G U Q Lb
61+
ic0.msg_arg_data_size : () -> i32; // I U Q Ry
62+
ic0.msg_arg_data_copy : (dst : i32, offset : i32, size : i32) -> (); // I U Q Ry
63+
ic0.msg_caller_size : () -> i32; // I G U Q
64+
ic0.msg_caller_copy : (dst : i32, offset: i32, size : i32) -> (); // I G U Q
6565
ic0.msg_reject_code : () -> i32; // Ry Rt
6666
ic0.msg_reject_msg_size : () -> i32; // Rt
6767
ic0.msg_reject_msg_copy : (dst : i32, offset : i32, size : i32) -> (); // Rt
@@ -70,45 +70,39 @@ ic0_module! {
7070
ic0.msg_reply : () -> (); // U Q Ry Rt
7171
ic0.msg_reject : (src : i32, size : i32) -> (); // U Q Ry Rt
7272

73-
ic0.msg_funds_available : ( unit_src : i32, unit_size : i32 ) -> i64; // U Rt Ry Lb
74-
ic0.msg_funds_refunded : ( unit_src : i32, unit_size : i32 ) -> i64; // Rt Ry
75-
ic0.msg_funds_accept : // U Rt Ry
76-
( unit_src : i32, unit_size : i32, amount : i64 ) -> ();
73+
ic0.msg_cycles_available : () -> i64; // U Rt Ry
74+
ic0.msg_cycles_refunded : () -> i64; // Rt Ry
75+
ic0.msg_cycles_accept : ( max_amount : i64 ) -> ( amount : i64 ); // U Rt Ry
7776

78-
ic0.canister_self_size : () -> (i32); // *
77+
ic0.canister_self_size : () -> i32; // *
7978
ic0.canister_self_copy : (dst : i32, offset : i32, size : i32) -> (); // *
80-
ic0.canister_balance : ( unit_src : i32, unit_size : i32 ) -> i64; // *
81-
82-
ic0.ingress_rate_bucket_size : () -> i32; // Ll
83-
ic0.ingress_rate_bucket_copy : (dst : i32, offset : i32, size : i32) -> (); // Ll
84-
ic0.return_ingress_bucket :
85-
( bucket_src : i32,
86-
bucket_size : i32,
87-
cost : i64
88-
) -> (); // Lb
89-
ic0.return_ingress_limit_per_second : (limit : i64) -> (); // Ll
79+
ic0.canister_cycle_balance : () -> i64; // *
80+
ic0.canister_status : () -> i32; // *
9081

9182
ic0.call_new : // U Ry Rt
92-
( callee_src : i32,
93-
callee_size : i32,
94-
name_src : i32,
95-
name_size : i32,
96-
reply_fun : i32,
97-
reply_env : i32,
98-
reject_fun : i32,
99-
reject_env : i32
100-
) -> ();
101-
ic0.call_on_cleanup : (fun : i32, env : i32) -> (); // U Ry Rt
83+
( callee_src : i32,
84+
callee_size : i32,
85+
name_src : i32,
86+
name_size : i32,
87+
reply_fun : i32,
88+
reply_env : i32,
89+
reject_fun : i32,
90+
reject_env : i32
91+
) -> ();
10292
ic0.call_data_append : (src : i32, size : i32) -> (); // U Ry Rt
103-
ic0.call_funds_add : // U Ry Rt
104-
(unit_src : i32, unit_size : i32, amount : i64) -> ();
93+
ic0.call_cycles_add : ( amount : i64 ) -> (); // U Ry Rt
10594
ic0.call_perform : () -> ( err_code : i32 ); // U Ry Rt
10695

10796
ic0.stable_size : () -> (page_count : i32); // *
10897
ic0.stable_grow : (new_pages : i32) -> (old_page_count : i32); // *
10998
ic0.stable_write : (offset : i32, src : i32, size : i32) -> (); // *
11099
ic0.stable_read : (dst : i32, offset : i32, size : i32) -> (); // *
111100

101+
ic0.certified_data_set : (src: i32, size: i32) -> (); // I G U Ry Rt
102+
ic0.data_certificate_present : () -> i32; // Q
103+
ic0.data_certificate_size : () -> i32; // Q
104+
ic0.data_certificate_copy : (dst: i32, offset: i32, size: i32) -> (); // Q
105+
112106
ic0.time : () -> (timestamp : i64); // *
113107

114108
ic0.debug_print : (src : i32, size : i32) -> (); // * s

0 commit comments

Comments
 (0)