Skip to content

Commit

Permalink
chore: bump candid
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity committed Jan 13, 2024
1 parent 6423784 commit 0c36cb1
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 155 deletions.
196 changes: 110 additions & 86 deletions Cargo.lock

Large diffs are not rendered by default.

29 changes: 17 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ rust-version = "1.71.1"
license = "Apache-2.0"

[workspace.dependencies]
candid = { version = "0.9.0", features = ["parser"] }
ic-agent = "0.30.2"
candid = "0.10"
candid_parser = "0.1"
ic-agent = "0.31.0"
ic-asset = { path = "src/canisters/frontend/ic-asset" }
ic-cdk = "0.10.0"
ic-identity-hsm = "0.30.2"
ic-utils = "0.30.2"
ic-cdk = "0.12.0"
ic-identity-hsm = "0.31.0"
ic-utils = "0.31.0"

aes-gcm = "0.9.4"
anyhow = "1.0.56"
Expand All @@ -34,7 +35,7 @@ base64 = "0.13.0"
byte-unit = "4.0.14"
bytes = "1.2.1"
clap = "4.2.0"
dialoguer = "0.10.0"
dialoguer = "0.11.0"
directories-next = "2.0.0"
flate2 = { version = "1.0.11", default-features = false }
futures = "0.3.21"
Expand Down Expand Up @@ -69,19 +70,23 @@ url = "2.1.0"
walkdir = "2.3.2"

[patch.crates-io.ic-agent]
version = "0.30.2"
version = "0.31.0"
git = "https://github.com/dfinity/agent-rs.git"
rev = "ed0862a45d5973ff123cbabc4ac40a89821b18c6"
rev = "a7f44ad05e77fc89b8447dd65b345e7a62fd1042"

[patch.crates-io.ic-identity-hsm]
version = "0.30.2"
version = "0.31.0"
git = "https://github.com/dfinity/agent-rs.git"
rev = "ed0862a45d5973ff123cbabc4ac40a89821b18c6"
rev = "a7f44ad05e77fc89b8447dd65b345e7a62fd1042"

[patch.crates-io.ic-utils]
version = "0.30.2"
version = "0.31.0"
git = "https://github.com/dfinity/agent-rs.git"
rev = "ed0862a45d5973ff123cbabc4ac40a89821b18c6"
rev = "a7f44ad05e77fc89b8447dd65b345e7a62fd1042"

[patch.crates-io.icrc-ledger-types]
git = "https://github.com/dfinity/ic.git"
rev = "1290256484f59c3d950c5e9a098e97383b248ad6"

[profile.release]
panic = 'abort'
Expand Down
4 changes: 2 additions & 2 deletions src/canisters/frontend/ic-asset/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async fn commit_in_stages(
commit_batch(
canister,
CommitBatchArguments {
batch_id: Nat::from(0),
batch_id: Nat::from(0u8),
operations: operations.into(),
},
)
Expand All @@ -156,7 +156,7 @@ async fn commit_in_stages(
commit_batch(
canister,
CommitBatchArguments {
batch_id: Nat::from(0),
batch_id: Nat::from(0u8),
operations: operations.into(),
},
)
Expand Down
4 changes: 3 additions & 1 deletion src/canisters/frontend/ic-certified-assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,9 @@ fn is_controller() -> Result<(), String> {

pub fn init(args: Option<AssetCanisterArgs>) {
if let Some(upgrade_arg) = args {
let AssetCanisterArgs::Init(InitArgs {}) = upgrade_arg else { ic_cdk::trap("Cannot initialize the canister with an Upgrade argument. Please provide an Init argument.")};
let AssetCanisterArgs::Init(InitArgs {}) = upgrade_arg else {
ic_cdk::trap("Cannot initialize the canister with an Upgrade argument. Please provide an Init argument.")
};
}
STATE.with(|s| {
let mut s = s.borrow_mut();
Expand Down
4 changes: 2 additions & 2 deletions src/dfx-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ argon2.workspace = true
bip32 = "0.4.0"
byte-unit = { workspace = true, features = ["serde"] }
bytes.workspace = true
candid = { workspace = true, features = ["random"] }
candid = { workspace = true }
clap = { workspace = true, features = ["string"] }
dialoguer = "0.10.0"
dialoguer = { workspace = true }
directories-next.workspace = true
flate2 = { workspace = true, default-features = false, features = ["zlib-ng"] }
hex = { workspace = true, features = ["serde"] }
Expand Down
1 change: 0 additions & 1 deletion src/dfx-core/src/config/model/dfinity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ pub enum WasmOptLevel {
Oz,
Os,
}

impl std::fmt::Display for WasmOptLevel {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
std::fmt::Debug::fmt(self, f)
Expand Down
2 changes: 1 addition & 1 deletion src/dfx-core/src/error/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum EncryptionError {
NonceGenerationFailed(ring::error::Unspecified),

#[error("Failed to read user input: {0}")]
ReadUserPasswordFailed(std::io::Error),
ReadUserPasswordFailed(dialoguer::Error),

#[error("Failed to generate salt: {0}")]
SaltGenerationFailed(ring::error::Unspecified),
Expand Down
7 changes: 4 additions & 3 deletions src/dfx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ backoff.workspace = true
base64.workspace = true
byte-unit = { workspace = true, features = ["serde"] }
bytes.workspace = true
candid = { workspace = true, features = ["random"] }
candid = { workspace = true }
candid_parser = { workspace = true, features = ["all"] }
clap = { workspace = true, features = [
"derive",
"env",
Expand All @@ -66,8 +67,8 @@ ic-asset.workspace = true
ic-cdk.workspace = true
ic-identity-hsm = { workspace = true }
ic-utils = { workspace = true }
ic-wasm = "0.4.0"
icrc-ledger-types = "0.1.1"
ic-wasm = "0.7.0"
icrc-ledger-types = "0.1"
indicatif = "0.16.0"
itertools.workspace = true
json-patch = "1.0.0"
Expand Down
4 changes: 2 additions & 2 deletions src/dfx/src/commands/deps/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::lib::environment::Environment;
use crate::lib::error::DfxResult;
use crate::util::{check_candid_file, fuzzy_parse_argument};
use anyhow::{anyhow, bail};
use candid::parser::types::IDLTypes;
use candid::Principal;
use candid_parser::types::IDLTypes;
use clap::Parser;
use slog::{info, warn, Logger};

Expand Down Expand Up @@ -73,7 +73,7 @@ fn set_init(
let candid_args_idl_types: IDLTypes = candid_args.parse()?;
let mut types = vec![];
for ty in candid_args_idl_types.args.iter() {
types.push(env.ast_to_type(ty)?);
types.push(candid_parser::typing::ast_to_type(&env, ty)?);
}

let arguments = opts.argument.as_deref();
Expand Down
16 changes: 11 additions & 5 deletions src/dfx/src/commands/remote/generate_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,22 @@ pub fn exec(env: &dyn Environment, opts: GenerateBindingOpts) -> DfxResult {
let (type_env, did_types) = check_candid_file(&candid)?;
let extension = main.extension().unwrap_or_default();
let bindings = if extension == "mo" {
Some(candid::bindings::motoko::compile(&type_env, &did_types))
Some(candid_parser::bindings::motoko::compile(
&type_env, &did_types,
))
} else if extension == "rs" {
let config = candid::bindings::rust::Config::new();
Some(candid::bindings::rust::compile(
let config = candid_parser::bindings::rust::Config::new();
Some(candid_parser::bindings::rust::compile(
&config, &type_env, &did_types,
))
} else if extension == "js" {
Some(candid::bindings::javascript::compile(&type_env, &did_types))
Some(candid_parser::bindings::javascript::compile(
&type_env, &did_types,
))
} else if extension == "ts" {
Some(candid::bindings::typescript::compile(&type_env, &did_types))
Some(candid_parser::bindings::typescript::compile(
&type_env, &did_types,
))
} else {
info!(
log,
Expand Down
9 changes: 6 additions & 3 deletions src/dfx/src/lib/builders/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ pub trait CanisterBuilder {
let output_did_ts_path = generate_output_dir
.join(info.get_name())
.with_extension("did.d.ts");
let content = ensure_trailing_newline(candid::bindings::typescript::compile(&env, &ty));
let content =
ensure_trailing_newline(candid_parser::bindings::typescript::compile(&env, &ty));
std::fs::write(&output_did_ts_path, content).with_context(|| {
format!(
"Failed to write to {}.",
Expand All @@ -174,7 +175,8 @@ pub trait CanisterBuilder {
let output_did_js_path = generate_output_dir
.join(info.get_name())
.with_extension("did.js");
let content = ensure_trailing_newline(candid::bindings::javascript::compile(&env, &ty));
let content =
ensure_trailing_newline(candid_parser::bindings::javascript::compile(&env, &ty));
std::fs::write(&output_did_js_path, content).with_context(|| {
format!(
"Failed to write to {}.",
Expand All @@ -191,7 +193,8 @@ pub trait CanisterBuilder {
let output_mo_path = generate_output_dir
.join(info.get_name())
.with_extension("mo");
let content = ensure_trailing_newline(candid::bindings::motoko::compile(&env, &ty));
let content =
ensure_trailing_newline(candid_parser::bindings::motoko::compile(&env, &ty));
std::fs::write(&output_mo_path, content).with_context(|| {
format!("Failed to write to {}.", output_mo_path.to_string_lossy())
})?;
Expand Down
15 changes: 11 additions & 4 deletions src/dfx/src/lib/canister_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use dfx_core::config::model::dfinity::{
use dfx_core::network::provider::get_network_context;
use dfx_core::util;
use fn_error_context::context;
use ic_wasm::optimize::OptLevel;
use std::path::{Path, PathBuf};

pub mod assets;
Expand Down Expand Up @@ -236,12 +237,18 @@ impl CanisterInfo {
self.shrink
}

pub fn get_optimize(&self) -> Option<WasmOptLevel> {
pub fn get_optimize(&self) -> Option<OptLevel> {
// Cycles defaults to O3, Size defaults to Oz
self.optimize.map(|level| match level {
WasmOptLevel::Cycles => WasmOptLevel::O3,
WasmOptLevel::Size => WasmOptLevel::Oz,
other => other,
WasmOptLevel::Cycles => OptLevel::O3,
WasmOptLevel::Size => OptLevel::Oz,
WasmOptLevel::O4 => OptLevel::O4,
WasmOptLevel::O3 => OptLevel::O3,
WasmOptLevel::O2 => OptLevel::O2,
WasmOptLevel::O1 => OptLevel::O1,
WasmOptLevel::O0 => OptLevel::O0,
WasmOptLevel::Oz => OptLevel::Oz,
WasmOptLevel::Os => OptLevel::Os,
})
}

Expand Down
43 changes: 20 additions & 23 deletions src/dfx/src/lib/models/canister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ impl Canister {

// optimize or shrink
if let Some(level) = info.get_optimize() {
trace!(logger, "Optimizing WASM at level {}", level);
ic_wasm::shrink::shrink_with_wasm_opt(&mut m, &level.to_string(), false)
//trace!(logger, "Optimizing WASM at level {}", level);
ic_wasm::optimize::optimize(&mut m, &level, false, &None, false)
.context("Failed to optimize the WASM module.")?;
modified = true;
} else if info.get_shrink() == Some(true)
Expand Down Expand Up @@ -312,28 +312,19 @@ impl Canister {
}

fn separate_candid(path: &Path) -> DfxResult<(String, String)> {
let (env, actor) = check_candid_file(path)?;
let actor = actor.ok_or_else(|| anyhow!("provided candid file contains no main service"))?;
if let candid::types::internal::TypeInner::Class(args, ty) = actor.as_ref() {
use candid::bindings::candid::pp_ty;
use candid::pretty::{concat, enclose};

let actor = Some(ty.clone());
let service_did = candid::bindings::candid::compile(&env, &actor);
let doc = concat(args.iter().map(pp_ty), ",");
let init_args = enclose("(", doc, ")").pretty(80).to_string();
Ok((service_did, init_args))
} else {
// The original candid from builder output doesn't contain init_args
// Use it directly to avoid items reordering
let service_did = dfx_core::fs::read_to_string(path)?;
let init_args = String::from("()");
Ok((service_did, init_args))
}
use candid_parser::utils::{instantiate_candid, CandidSource};
// TODO: comments are omitted in the output
let (init_args, (env, actor)) = instantiate_candid(CandidSource::File(path))?;
let init_args = candid::pretty::candid::pp_args(&init_args)
.pretty(80)
.to_string();
let service_did = candid::pretty::candid::compile(&env, &Some(actor));
Ok((service_did, init_args))
}

#[context("{} is not a valid subtype of {}", specified_idl_path.display(), compiled_idl_path.display())]
fn check_valid_subtype(compiled_idl_path: &Path, specified_idl_path: &Path) -> DfxResult {
use candid::types::subtype::{subtype_with_config, OptReport};
let (mut env, opt_specified) =
check_candid_file(specified_idl_path).context("Checking specified candid file.")?;
let specified_type =
Expand All @@ -344,7 +335,13 @@ fn check_valid_subtype(compiled_idl_path: &Path, specified_idl_path: &Path) -> D
opt_compiled.expect("Compiled did file should contain some service interface");
let mut gamma = HashSet::new();
let specified_type = env.merge_type(env2, specified_type);
candid::types::subtype::subtype(&mut gamma, &env, &compiled_type, &specified_type)?;
subtype_with_config(
OptReport::Error,
&mut gamma,
&env,
&compiled_type,
&specified_type,
)?;
Ok(())
}

Expand Down Expand Up @@ -785,14 +782,14 @@ fn build_canister_js(canister_id: &CanisterId, canister_info: &CanisterInfo) ->
.with_extension("did.d.ts");

let (env, ty) = check_candid_file(&canister_info.get_service_idl_path())?;
let content = ensure_trailing_newline(candid::bindings::javascript::compile(&env, &ty));
let content = ensure_trailing_newline(candid_parser::bindings::javascript::compile(&env, &ty));
std::fs::write(&output_did_js_path, content).with_context(|| {
format!(
"Failed to write to {}.",
output_did_js_path.to_string_lossy()
)
})?;
let content = ensure_trailing_newline(candid::bindings::typescript::compile(&env, &ty));
let content = ensure_trailing_newline(candid_parser::bindings::typescript::compile(&env, &ty));
std::fs::write(&output_did_ts_path, content).with_context(|| {
format!(
"Failed to write to {}.",
Expand Down
4 changes: 2 additions & 2 deletions src/dfx/src/lib/operations/canister/motoko_playground.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ fn create_nonce() -> (candid::Int, candid::Nat) {
.as_nanos();
let timestamp = candid::Int::from(now);
let mut rng = rand::thread_rng();
let mut nonce = candid::Nat::from(rng.gen::<i32>());
let mut nonce = candid::Nat::from(rng.gen::<u32>());
let prefix = format!("{}{}", POW_DOMAIN, timestamp);
loop {
let to_hash = format!("{}{}", prefix, nonce).replace('_', "");
let hash = motoko_hash(&to_hash);
if (hash & 0xc0000000) == 0 {
return (timestamp, nonce);
}
nonce += 1;
nonce += 1u8;
}
}

Expand Down
Loading

0 comments on commit 0c36cb1

Please sign in to comment.