Skip to content

Commit

Permalink
Update to latest candid and ic-cdk
Browse files Browse the repository at this point in the history
  • Loading branch information
dfinity-ryancroote committed Jul 25, 2023
1 parent e9a7891 commit 2c8ae26
Show file tree
Hide file tree
Showing 18 changed files with 275 additions and 214 deletions.
401 changes: 231 additions & 170 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ members = [
"src/monitor-canister",
]

[workspace.dependencies]
candid = "0.9.1"
ic-cdk = "0.10.0"
ic-cdk-macros = "0.7.0"

[profile.release]
lto = true
opt-level = 'z'
4 changes: 2 additions & 2 deletions src/ic-xrc-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ic-xrc-types"
authors = ["DFINITY Stiftung <[email protected]>"]
version = "1.0.0"
version = "1.1.0"
edition = "2021"
description = "Rust support for the exchange rate canister."
documentation = "https://docs.rs/ic-xrc-types"
Expand All @@ -13,5 +13,5 @@ keywords = ["internet-computer", "dfinity"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
candid = "0.8.0"
candid.workspace = true
serde = "1.0.110"
6 changes: 3 additions & 3 deletions src/monitor-canister/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ edition = "2021"

[dependencies]
async-trait = "0.1.58"
candid = "0.8.0"
ic-cdk = "0.6.5"
ic-cdk-macros = "0.6.0"
candid.workspace = true
ic-cdk.worksapce = true
ic-cdk-macros.workspace = true
ic-stable-structures = "0.1.0"
ic-xrc-types = { path = "../ic-xrc-types" }
futures = "0.3.23"
Expand Down
3 changes: 1 addition & 2 deletions src/monitor-canister/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use candid::Nat;
use ic_cdk::export::candid::decode_one;
use candid::{decode_one, Nat};

use crate::{
environment::Environment,
Expand Down
2 changes: 1 addition & 1 deletion src/monitor-canister/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ic_cdk::export::candid::candid_method;
use candid::candid_method;
use ic_cdk_macros::{heartbeat, init, post_upgrade, query};
use monitor_canister::{
types::{Config, GetEntriesRequest, GetEntriesResponse},
Expand Down
6 changes: 3 additions & 3 deletions src/monitor-canister/src/periodic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use async_trait::async_trait;
use candid::encode_one;
use ic_cdk::export::Principal;
use candid::{encode_one, Principal};
use ic_xrc_types::{Asset, AssetClass, GetExchangeRateRequest, GetExchangeRateResult};
use std::cell::Cell;
use xrc::XRC_REQUEST_CYCLES_COST;
Expand Down Expand Up @@ -198,8 +197,9 @@ mod test {

use std::sync::{Arc, RwLock};

use candid::Nat;
use futures::FutureExt;
use ic_cdk::{api::call::RejectionCode, export::candid::Nat};
use ic_cdk::api::call::RejectionCode;
use ic_xrc_types::{ExchangeRate, ExchangeRateError, ExchangeRateMetadata};

use crate::{api, environment::test::TestEnvironment, types::GetEntriesRequest};
Expand Down
7 changes: 2 additions & 5 deletions src/monitor-canister/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::borrow::Cow;

use candid::{decode_one, encode_one};
use ic_cdk::{
api::call::RejectionCode,
export::candid::{CandidType, Deserialize, Nat, Principal},
};
use candid::{decode_one, encode_one, CandidType, Deserialize, Nat, Principal};
use ic_cdk::api::call::RejectionCode;
use ic_stable_structures::Storable;
use ic_xrc_types::{ExchangeRate, ExchangeRateError, GetExchangeRateRequest};
use num_traits::ToPrimitive;
Expand Down
4 changes: 2 additions & 2 deletions src/xrc-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ version = "0.8.0"
edition = "2021"

[dependencies]
candid = "0.8.0"
candid.workspace = true
hex = "0.4.3"
ic-cdk = "0.6.5"
ic-cdk.worksapce = true
ic-xrc-types = { path = "../ic-xrc-types" }
maplit = "1.0.2"
serde = "1.0.110"
Expand Down
9 changes: 5 additions & 4 deletions src/xrc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ doctest = false

[dependencies]
async-trait = "0.1.58"
candid = "0.8.0"
ic-cdk = "0.6.5"
ic-cdk-macros = "0.6.0"
candid.workspace = true
ic-cdk.worksapce = true
ic-cdk-macros.workspace = true
ic-xrc-types = { path = "../ic-xrc-types" }
futures = "0.3.23"
lru = "0.9.0"
Expand All @@ -21,9 +21,10 @@ serde_json = "1.0.74"
chrono = "=0.4.19"
serde_derive = "1.0"
serde_bytes = "0.11"
serde-xml-rs = "0.3.1"
serde-xml-rs = "0.6.0"

[dev-dependencies]
candid = { workspace = true, features = ["parser"] }
hex = "0.4"
maplit = "1.0.2"
rand = "0.8.5"
Expand Down
2 changes: 1 addition & 1 deletion src/xrc/src/environment.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use candid::Principal;
use ic_cdk::{
api::call::{msg_cycles_accept, msg_cycles_available},
caller,
export::Principal,
};
use ic_xrc_types::ExchangeRateError;

Expand Down
6 changes: 2 additions & 4 deletions src/xrc/src/exchanges.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use ic_cdk::export::{
candid::{decode_args, encode_args, Error as CandidError},
serde::Deserialize,
};
use candid::{decode_args, encode_args, Deserialize, Error as CandidError};

use ic_xrc_types::Asset;
use serde::de::DeserializeOwned;

Expand Down
2 changes: 1 addition & 1 deletion src/xrc/src/forex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod singapore;
mod switzerland;
mod uzbekistan;

use ic_cdk::export::candid::{
use candid::{
decode_args, decode_one, encode_args, encode_one, CandidType, Deserialize, Error as CandidError,
};
use ic_xrc_types::{Asset, AssetClass, ExchangeRateError};
Expand Down
5 changes: 3 additions & 2 deletions src/xrc/src/http.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use candid::Func;

use ic_cdk::{
api::management_canister::http_request::{
http_request, CanisterHttpRequestArgument, HttpHeader, HttpMethod, HttpResponse,
TransformContext, TransformFunc,
},
export::candid::Func,
id,
};

Expand Down Expand Up @@ -86,7 +87,7 @@ impl CanisterHttpRequest {

/// Wraps around `http_request` to issue a request to the `http_request` endpoint.
pub async fn send(self) -> Result<HttpResponse, String> {
http_request(self.args)
http_request(self.args, 0)
.await
.map(|(response,)| response)
.map_err(|(_rejection_code, message)| message)
Expand Down
7 changes: 2 additions & 5 deletions src/xrc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ mod request_log;
pub mod types;
mod utils;

use ::candid::{CandidType, Deserialize};
use ic_cdk::{
api::management_canister::http_request::{HttpResponse, TransformArgs},
export::candid::Principal,
};
use ::candid::{CandidType, Deserialize, Principal};
use ic_cdk::api::management_canister::http_request::{HttpResponse, TransformArgs};
use ic_xrc_types::{Asset, ExchangeRate, ExchangeRateError, ExchangeRateMetadata, OtherError};
use request_log::RequestLog;
use serde_bytes::ByteBuf;
Expand Down
13 changes: 7 additions & 6 deletions src/xrc/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use candid::candid_method;
use ic_cdk::api::management_canister::http_request::{HttpResponse, TransformArgs};
use ic_cdk::export::candid::candid_method;

#[ic_cdk_macros::update]
#[candid_method(update)]
Expand Down Expand Up @@ -52,19 +52,20 @@ fn main() {}
mod test {
use std::path::PathBuf;

use ic_cdk::export::candid as cdk_candid;
use candid;

Check failure on line 55 in src/xrc/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

this import is redundant

error: this import is redundant --> src/xrc/src/main.rs:55:5 | 55 | use candid; | ^^^^^^^^^^^ help: remove it entirely | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports = note: `-D clippy::single-component-path-imports` implied by `-D warnings`

#[test]
fn check_candid_compatibility() {
cdk_candid::export_service!();
candid::export_service!();

// Pull in the rust-generated interface and candid file interface.
let new_interface = __export_service();
let old_interface =
PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("xrc.did");

cdk_candid::utils::service_compatible(
cdk_candid::utils::CandidSource::Text(&new_interface),
cdk_candid::utils::CandidSource::File(old_interface.as_path()),
candid::utils::service_compatible(
candid::utils::CandidSource::Text(&new_interface),
candid::utils::CandidSource::File(old_interface.as_path()),
)
.expect("Service incompatibility found");
}
Expand Down
2 changes: 1 addition & 1 deletion src/xrc/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ic_cdk::export::candid::{CandidType, Deserialize};
use candid::{CandidType, Deserialize};
use serde_bytes::ByteBuf;

type HeaderField = (String, String);
Expand Down
5 changes: 3 additions & 2 deletions src/xrc/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{environment::Environment, PRIVILEGED_CANISTER_IDS};
use ic_cdk::export::Principal;
use candid::Principal;
use ic_xrc_types::{Asset, GetExchangeRateRequest};

use crate::{environment::Environment, PRIVILEGED_CANISTER_IDS};

const NANOS_PER_SEC: u64 = 1_000_000_000;

/// Gets the current time in seconds.
Expand Down

0 comments on commit 2c8ae26

Please sign in to comment.