-
Notifications
You must be signed in to change notification settings - Fork 0
chore(rust): Bump ic cdk #129
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes here are from the formatter.
| @@ -21,15 +21,15 @@ The following cryptocurrencies are currently supported: | |||
| | ICP Cycles | XDR | The native utility token of the Internet Computer, tied in price to the IMF XDR basket of currencies. | | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes here are from the formatter.
|
|
||
| [didc.rust] | ||
| target = "custom" | ||
| template = "didc.hbs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didc still generates bindings for the old ic_cdk API. We need our own template to generate bindings for the new API.
| "package": "example_paid_service", | ||
| "type": "rust", | ||
| "optimize": "cycles", | ||
| "gzip": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The formatter at work.
| @@ -1,15 +1,13 @@ | |||
| { | |||
| "dfx": "0.25.0", | |||
| "dfx": "0.29.1", | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This updates dfx so that it provides the new runtime.
| "method": "curl", | ||
| "version": "0.5.1", | ||
| "url": "https://github.com/dfinity/candid/releases/download/2025-08-04/didc-linux64" | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This installs the latest didc, used to generate bindings.
| @@ -112,7 +112,6 @@ jobs: | |||
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |||
| with: | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just the formatter at work.
| } | ||
|
|
||
| pub type TokenAmount = u64; | ||
| pub type TokenAmount = u128; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the new cdk, cycle amounts are u128 instead of u64.
| target="$HOME/.local/bin/$tool" | ||
| mkdir -p "$(dirname "$target")" | ||
| curl -Lf "$url" | "$pipe" | install -m 755 /dev/stdin "$target" | ||
| ;; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the install mechanism for didc, used to generate the updated code.
| .await | ||
| .unwrap(); | ||
| ans | ||
| Call::unbounded_wait(canister_id, &method) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I picked unbounded_wait to minimize changes, but we should think hard about switching to bounded_wait almost immediately. E.g. in the very next PR.
|
|
||
| use candid::{self, CandidType, Deserialize, Principal}; | ||
| use ic_cdk::api::call::CallResult as Result; | ||
| use ic_cdk::call::{Call, CallResult as Result}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ic_cdk::api::call::CallResult is now deprecated.
| /// The ID of this canister. | ||
| fn canister_id(&self) -> Principal { | ||
| self.canister_id.clone() | ||
| self.canister_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clippy: Principal implements the Copy trait.
| use ic_cdk::api::call::CallResult; | ||
| use pocket_ic::{PocketIc, WasmResult}; | ||
| use ic_cdk::call::{Call, CallResult}; | ||
| use pocket_ic::PocketIc; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stop using deprecated types & methods.
| Blob(serde_bytes::ByteBuf), | ||
| Text(String), | ||
| Array(Vec<Box<Value>>), | ||
| Array(Vec<Value>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clippy: The Vec is already on the heap, so the box is pointless.
| Ok(Call::unbounded_wait(self.0, "create_canister") | ||
| .with_args(&(arg0,)) | ||
| .await? | ||
| .candid()?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New bindings generated with didc.
| .candid()?) | ||
| } | ||
| pub async fn icrc_2_transfer_from( | ||
| pub async fn icrc2_transfer_from( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: The canister method is icrc2_transfer_from but the old autogenerated bindings inserted an underscore before numbers.
| format!( | ||
| "Update call error. RejectionCode: {:?}, Error: {}", | ||
| e.code, e.description | ||
| e.reject_code, e.reject_message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cdk has a new error type, so we have to update to use the equivalent fields in the new type.
| self.wasm_path | ||
| )) | ||
| fs::read(self.wasm_path.clone()) | ||
| .unwrap_or_else(|_| panic!("Could not find the backend wasm: {}", self.wasm_path)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clippy complained about a function in expect().
| .expect("Failed to approve the paid service to spend the user's ICRC-2 tokens"); | ||
| } | ||
| /// Calls a paid service. | ||
| #[allow(clippy::result_large_err)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error type is 144 bytes. I'm not sure there is much we can do about that. It is an enum of all the different error types that can occur in the payment process, such as the canister call to the ledger failing.
| fn inter_canister_call_succeeds_with_sufficient_cycles_only() { | ||
| let setup = AttachedCyclesTestSetup::default(); | ||
| for cycles in 995u64..1005 { | ||
| for cycles in 995u128..1005 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cycles are u128 in the new runtime.
| caller.to_string(), | ||
| patron.to_string(), | ||
| caller, | ||
| patron, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clippy
| @@ -1,5 +1,5 @@ | |||
| use super::{PaymentError, PaymentGuardTrait}; | |||
| use ic_cdk::api::call::{msg_cycles_accept, msg_cycles_available}; | |||
| use ic_cdk::api::{msg_cycles_accept, msg_cycles_available}; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the new methods, not the deprecated ones.
| [dependencies] | ||
| candid = { workspace = true } | ||
| ic-cdk = "0.17.2" | ||
| ic-cdk = { workspace = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sure that the ic-cdk version here stays in sync with that used elsewhere in this workspace.
| edition = "2021" | ||
| publish = true | ||
| version = "0.1.1" | ||
| version = "0.2.0-alpha.1.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bump version, as this code is definitely not compatible with version 0.1.1
DecentAgeCoder
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks
Motivation
A newer ICP runtime is available. A new
ic_cdki needed to use the updated canister API, and the runtimes (pocketic and dfx) need to be updated to provide that new API.This necessarily requires some fairly deep incisions, so thorough testing is advised.
Changes
Call::unbounded_waitbuilder instead of the deprecatedic_cdk::call.Tests
Functionality should not have changed, so existing tests should suffice.