diff --git a/Cargo.lock b/Cargo.lock index 0a57aa5be0..1838e814b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -762,7 +762,7 @@ dependencies = [ "logos 0.12.1", "num-bigint 0.4.4", "num-traits", - "num_enum 0.5.11", + "num_enum", "paste", "pretty 0.10.0", "serde", @@ -773,35 +773,23 @@ dependencies = [ [[package]] name = "candid" -version = "0.9.11" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "465c1ce01d8089ee5b49ba20d3a9da15a28bba64c35cdff2aa256d37e319625d" +checksum = "39be580be172631a35cac2fc6c765f365709de459edb88121b3e7a80cce6c1ec" dependencies = [ "anyhow", - "arbitrary", "binread", "byteorder", - "candid_derive 0.6.4", - "codespan-reporting", - "convert_case 0.6.0", - "crc32fast", - "data-encoding", - "fake", + "candid_derive 0.6.5", "hex", - "lalrpop 0.20.0", - "lalrpop-util 0.20.0", + "ic_principal", "leb128", - "logos 0.13.0", "num-bigint 0.4.4", "num-traits", - "num_enum 0.6.1", "paste", "pretty 0.12.3", - "rand", "serde", "serde_bytes", - "serde_dhall", - "sha2 0.10.8", "stacker", "thiserror", ] @@ -820,9 +808,9 @@ dependencies = [ [[package]] name = "candid_derive" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201ea498d901add0822653ac94cb0f8a92f9b1758a5273f4dafbb6673c9a5020" +checksum = "970c220da8aa2fa6f7ef5dbbf3ea5b620a59eb3ac107cfb95ae8c6eebdfb7a08" dependencies = [ "lazy_static", "proc-macro2", @@ -830,6 +818,34 @@ dependencies = [ "syn 2.0.38", ] +[[package]] +name = "candid_parser" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36381de3ba8a312deb028552c0d63f7c7fe6e204f44bae4c58a3643308cfa9d5" +dependencies = [ + "anyhow", + "arbitrary", + "candid 0.10.2", + "codespan-reporting", + "console", + "convert_case 0.6.0", + "ctrlc", + "dialoguer", + "fake", + "hex", + "lalrpop 0.20.0", + "lalrpop-util 0.20.0", + "logos 0.13.0", + "num-bigint 0.4.4", + "num-traits", + "pretty 0.12.3", + "rand", + "serde", + "serde_dhall", + "thiserror", +] + [[package]] name = "cc" version = "1.0.83" @@ -1378,9 +1394,9 @@ dependencies = [ [[package]] name = "deunicode" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a1abaf4d861455be59f64fd2b55606cb151fce304ede7165f410243ce96bde6" +checksum = "3ae2a35373c5c74340b79ae6780b498b2b183915ec5dacf263aac5a099bf485a" [[package]] name = "dfx" @@ -1397,7 +1413,8 @@ dependencies = [ "base64 0.13.1", "byte-unit", "bytes", - "candid 0.9.11", + "candid 0.10.2", + "candid_parser", "ci_info", "clap", "console", @@ -1420,7 +1437,7 @@ dependencies = [ "ic-asset", "ic-cdk", "ic-identity-hsm", - "ic-utils 0.30.2", + "ic-utils 0.31.0", "ic-wasm", "icrc-ledger-types", "indicatif", @@ -1481,7 +1498,7 @@ dependencies = [ "bip32", "byte-unit", "bytes", - "candid 0.9.11", + "candid 0.10.2", "clap", "dialoguer", "directories-next", @@ -1490,7 +1507,7 @@ dependencies = [ "humantime-serde", "ic-agent", "ic-identity-hsm", - "ic-utils 0.30.2", + "ic-utils 0.31.0", "k256 0.11.6", "keyring", "lazy_static", @@ -1549,13 +1566,14 @@ dependencies = [ [[package]] name = "dialoguer" -version = "0.10.4" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59c6f2989294b9a498d3ad5491a79c6deb604617378e1cdc4bfc1c1361fe2f87" +checksum = "658bce805d770f407bc62102fca7c2c64ceef2fbcb2b8bd19d2765ce093980de" dependencies = [ "console", "shell-words", "tempfile", + "thiserror", "zeroize", ] @@ -1725,9 +1743,9 @@ dependencies = [ [[package]] name = "elsa" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "714f766f3556b44e7e4776ad133fcc3445a489517c25c704ace411bb14790194" +checksum = "d98e71ae4df57d214182a2e5cb90230c0192c6ddfcaa05c36453d46a54713e10" dependencies = [ "stable_deref_trait", ] @@ -1833,9 +1851,9 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "fake" -version = "2.9.1" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26221445034074d46b276e13eb97a265ebdb8ed8da705c4dddd3dd20b66b45d2" +checksum = "1c25829bde82205da46e1823b2259db6273379f626fc211f126f65654a2669be" dependencies = [ "deunicode", "rand", @@ -2459,18 +2477,18 @@ dependencies = [ [[package]] name = "ic-agent" -version = "0.30.2" -source = "git+https://github.com/dfinity/agent-rs.git?rev=ed0862a45d5973ff123cbabc4ac40a89821b18c6#ed0862a45d5973ff123cbabc4ac40a89821b18c6" +version = "0.31.0" +source = "git+https://github.com/dfinity/agent-rs.git?rev=a7f44ad05e77fc89b8447dd65b345e7a62fd1042#a7f44ad05e77fc89b8447dd65b345e7a62fd1042" dependencies = [ "backoff", "cached 0.46.1", - "candid 0.9.11", + "candid 0.10.2", "ed25519-consensus", "futures-util", "hex", "http", "http-body", - "ic-certification 1.3.0", + "ic-certification 2.2.0", "ic-transport-types", "ic-verify-bls-signature", "k256 0.13.1", @@ -2500,7 +2518,7 @@ name = "ic-asset" version = "0.20.0" dependencies = [ "backoff", - "candid 0.9.11", + "candid 0.10.2", "derivative", "dfx-core", "flate2", @@ -2509,7 +2527,7 @@ dependencies = [ "globset", "hex", "ic-agent", - "ic-utils 0.30.2", + "ic-utils 0.31.0", "itertools 0.10.5", "json5", "mime", @@ -2571,11 +2589,11 @@ dependencies = [ [[package]] name = "ic-cdk" -version = "0.10.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d4c0b932bf454d5d60e61e13c3c944972fcfd74dc82b9ed5c8b0a75979cf50" +checksum = "e4ec8231f413b8a4d74b99d7df26d6e917d6528a6245abde27f251210dcf9b72" dependencies = [ - "candid 0.9.11", + "candid 0.10.2", "ic-cdk-macros", "ic0", "serde", @@ -2584,11 +2602,11 @@ dependencies = [ [[package]] name = "ic-cdk-macros" -version = "0.7.1" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "411c0dd4c149132b68e679274d397053332ee29996c6a541075895881916333b" +checksum = "ff30a6ddb3b50f1b7df689d203d2135b037706678368b1d73a9a98e17f87a9b4" dependencies = [ - "candid 0.9.11", + "candid 0.10.2", "proc-macro2", "quote", "serde", @@ -2618,12 +2636,24 @@ dependencies = [ "sha2 0.10.8", ] +[[package]] +name = "ic-certification" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bb2219eb25be014287ff2e355b762c93952028401a4444031ef904535dc776e" +dependencies = [ + "hex", + "serde", + "serde_bytes", + "sha2 0.10.8", +] + [[package]] name = "ic-certified-assets" version = "0.2.5" dependencies = [ "base64 0.13.1", - "candid 0.9.11", + "candid 0.10.2", "hex", "ic-cdk", "ic-certification 1.3.0", @@ -2828,8 +2858,8 @@ dependencies = [ [[package]] name = "ic-identity-hsm" -version = "0.30.2" -source = "git+https://github.com/dfinity/agent-rs.git?rev=ed0862a45d5973ff123cbabc4ac40a89821b18c6#ed0862a45d5973ff123cbabc4ac40a89821b18c6" +version = "0.31.0" +source = "git+https://github.com/dfinity/agent-rs.git?rev=a7f44ad05e77fc89b8447dd65b345e7a62fd1042#a7f44ad05e77fc89b8447dd65b345e7a62fd1042" dependencies = [ "hex", "ic-agent", @@ -2924,12 +2954,12 @@ dependencies = [ [[package]] name = "ic-transport-types" -version = "0.30.2" -source = "git+https://github.com/dfinity/agent-rs.git?rev=ed0862a45d5973ff123cbabc4ac40a89821b18c6#ed0862a45d5973ff123cbabc4ac40a89821b18c6" +version = "0.31.0" +source = "git+https://github.com/dfinity/agent-rs.git?rev=a7f44ad05e77fc89b8447dd65b345e7a62fd1042#a7f44ad05e77fc89b8447dd65b345e7a62fd1042" dependencies = [ - "candid 0.9.11", + "candid 0.10.2", "hex", - "ic-certification 1.3.0", + "ic-certification 2.2.0", "leb128", "serde", "serde_bytes", @@ -2999,11 +3029,11 @@ dependencies = [ [[package]] name = "ic-utils" -version = "0.30.2" -source = "git+https://github.com/dfinity/agent-rs.git?rev=ed0862a45d5973ff123cbabc4ac40a89821b18c6#ed0862a45d5973ff123cbabc4ac40a89821b18c6" +version = "0.31.0" +source = "git+https://github.com/dfinity/agent-rs.git?rev=a7f44ad05e77fc89b8447dd65b345e7a62fd1042#a7f44ad05e77fc89b8447dd65b345e7a62fd1042" dependencies = [ "async-trait", - "candid 0.9.11", + "candid 0.10.2", "ic-agent", "once_cell", "semver", @@ -3029,14 +3059,16 @@ dependencies = [ [[package]] name = "ic-wasm" -version = "0.4.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e360e45c2bf406a867c35ec5daee433f2c3bbbaf013469e6a386a322a9713885" +checksum = "9d2aa0d7deeb38f18fcec6e4c25c5004422e2e9f8c3fbad15bb795ebac37aca6" dependencies = [ "anyhow", - "candid 0.9.11", + "candid 0.10.2", "clap", "rustc-demangle", + "serde", + "serde_json", "tempfile", "thiserror", "walrus", @@ -3045,9 +3077,9 @@ dependencies = [ [[package]] name = "ic0" -version = "0.18.11" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576c539151d4769fb4d1a0c25c4108dd18facd04c5695b02cf2d226ab4e43aa5" +checksum = "a54b5297861c651551676e8c43df805dad175cc33bc97dbd992edbbb85dcbcdf" [[package]] name = "ic_bls12_381" @@ -3065,13 +3097,26 @@ dependencies = [ ] [[package]] -name = "icrc-ledger-types" -version = "0.1.3" +name = "ic_principal" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ad46da2124f4d7bf5c079eca568786b87bd60fc962bef404ff44207077961c" +checksum = "1762deb6f7c8d8c2bdee4b6c5a47b60195b74e9b5280faa5ba29692f8e17429c" +dependencies = [ + "arbitrary", + "crc32fast", + "data-encoding", + "serde", + "sha2 0.10.8", + "thiserror", +] + +[[package]] +name = "icrc-ledger-types" +version = "0.1.4" +source = "git+https://github.com/dfinity/ic.git?rev=1290256484f59c3d950c5e9a098e97383b248ad6#1290256484f59c3d950c5e9a098e97383b248ad6" dependencies = [ "base32", - "candid 0.9.11", + "candid 0.10.2", "crc32fast", "hex", "num-bigint 0.4.4", @@ -3087,13 +3132,13 @@ version = "0.20.0" dependencies = [ "anstyle", "anyhow", - "candid 0.9.11", + "candid 0.10.2", "clap", "delay", "humantime", "ic-agent", "ic-asset", - "ic-utils 0.30.2", + "ic-utils 0.31.0", "libflate", "num-traits", "pem 1.1.1", @@ -3861,16 +3906,7 @@ version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9" dependencies = [ - "num_enum_derive 0.5.11", -] - -[[package]] -name = "num_enum" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1" -dependencies = [ - "num_enum_derive 0.6.1", + "num_enum_derive", ] [[package]] @@ -3885,18 +3921,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "num_enum_derive" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" -dependencies = [ - "proc-macro-crate 1.3.1", - "proc-macro2", - "quote", - "syn 2.0.38", -] - [[package]] name = "num_threads" version = "0.1.6" diff --git a/Cargo.toml b/Cargo.toml index 8a42a64df0..b60644528b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -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" @@ -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' diff --git a/src/canisters/frontend/ic-asset/src/sync.rs b/src/canisters/frontend/ic-asset/src/sync.rs index 2962c2f75d..51ed0281b4 100644 --- a/src/canisters/frontend/ic-asset/src/sync.rs +++ b/src/canisters/frontend/ic-asset/src/sync.rs @@ -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(), }, ) @@ -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(), }, ) diff --git a/src/canisters/frontend/ic-certified-assets/src/lib.rs b/src/canisters/frontend/ic-certified-assets/src/lib.rs index 336a0106a9..fd927de80f 100644 --- a/src/canisters/frontend/ic-certified-assets/src/lib.rs +++ b/src/canisters/frontend/ic-certified-assets/src/lib.rs @@ -415,7 +415,9 @@ fn is_controller() -> Result<(), String> { pub fn init(args: Option) { 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(); diff --git a/src/dfx-core/Cargo.toml b/src/dfx-core/Cargo.toml index f1b9fef3f3..d9b64bc314 100644 --- a/src/dfx-core/Cargo.toml +++ b/src/dfx-core/Cargo.toml @@ -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"] } diff --git a/src/dfx-core/src/config/model/dfinity.rs b/src/dfx-core/src/config/model/dfinity.rs index f4ffd78cc6..6841792b95 100644 --- a/src/dfx-core/src/config/model/dfinity.rs +++ b/src/dfx-core/src/config/model/dfinity.rs @@ -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) diff --git a/src/dfx-core/src/error/encryption.rs b/src/dfx-core/src/error/encryption.rs index fff651a7f3..d7cf2bee0d 100644 --- a/src/dfx-core/src/error/encryption.rs +++ b/src/dfx-core/src/error/encryption.rs @@ -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), diff --git a/src/dfx/Cargo.toml b/src/dfx/Cargo.toml index 9626792d0d..17cb31ba54 100644 --- a/src/dfx/Cargo.toml +++ b/src/dfx/Cargo.toml @@ -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", @@ -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" diff --git a/src/dfx/src/commands/deps/init.rs b/src/dfx/src/commands/deps/init.rs index 0de294a203..988ef5b839 100644 --- a/src/dfx/src/commands/deps/init.rs +++ b/src/dfx/src/commands/deps/init.rs @@ -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}; @@ -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(); diff --git a/src/dfx/src/commands/remote/generate_binding.rs b/src/dfx/src/commands/remote/generate_binding.rs index 6cc835c9a7..947b5b852a 100644 --- a/src/dfx/src/commands/remote/generate_binding.rs +++ b/src/dfx/src/commands/remote/generate_binding.rs @@ -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, diff --git a/src/dfx/src/lib/builders/mod.rs b/src/dfx/src/lib/builders/mod.rs index 231192b513..f2eae5ce14 100644 --- a/src/dfx/src/lib/builders/mod.rs +++ b/src/dfx/src/lib/builders/mod.rs @@ -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 {}.", @@ -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 {}.", @@ -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()) })?; diff --git a/src/dfx/src/lib/canister_info.rs b/src/dfx/src/lib/canister_info.rs index 628a6a7e59..ece83fb847 100644 --- a/src/dfx/src/lib/canister_info.rs +++ b/src/dfx/src/lib/canister_info.rs @@ -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; @@ -236,12 +237,18 @@ impl CanisterInfo { self.shrink } - pub fn get_optimize(&self) -> Option { + pub fn get_optimize(&self) -> Option { // 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, }) } diff --git a/src/dfx/src/lib/models/canister.rs b/src/dfx/src/lib/models/canister.rs index 3903adf513..c7f5d3de7d 100644 --- a/src/dfx/src/lib/models/canister.rs +++ b/src/dfx/src/lib/models/canister.rs @@ -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) @@ -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 = @@ -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(()) } @@ -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 {}.", diff --git a/src/dfx/src/lib/operations/canister/motoko_playground.rs b/src/dfx/src/lib/operations/canister/motoko_playground.rs index e9f4d33dd4..e780763b8a 100644 --- a/src/dfx/src/lib/operations/canister/motoko_playground.rs +++ b/src/dfx/src/lib/operations/canister/motoko_playground.rs @@ -196,7 +196,7 @@ 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::()); + let mut nonce = candid::Nat::from(rng.gen::()); let prefix = format!("{}{}", POW_DOMAIN, timestamp); loop { let to_hash = format!("{}{}", prefix, nonce).replace('_', ""); @@ -204,7 +204,7 @@ fn create_nonce() -> (candid::Int, candid::Nat) { if (hash & 0xc0000000) == 0 { return (timestamp, nonce); } - nonce += 1; + nonce += 1u8; } } diff --git a/src/dfx/src/util/mod.rs b/src/dfx/src/util/mod.rs index 98787ea76e..a48cabc27f 100644 --- a/src/dfx/src/util/mod.rs +++ b/src/dfx/src/util/mod.rs @@ -4,9 +4,9 @@ use anyhow::{bail, Context}; use backoff::backoff::Backoff; use backoff::ExponentialBackoff; use bytes::Bytes; -use candid::parser::typing::pretty_check_file; use candid::types::{value::IDLValue, Function, Type, TypeEnv, TypeInner}; use candid::IDLArgs; +use candid_parser::typing::pretty_check_file; use dfx_core::fs::create_dir_all; use fn_error_context::context; #[cfg(unix)] @@ -178,8 +178,13 @@ pub fn blob_from_arguments( let typed_args = match method_type { None => { let arguments = arguments.unwrap_or("()"); - candid::pretty_parse::("Candid argument", arguments) - .map_err(|e| error_invalid_argument!("Invalid Candid values: {}", e))? + candid_parser::parse_idl_args(arguments) + .or_else(|e| { + candid_parser::error::pretty_diagnose("Candid argument", arguments, &e) + .unwrap(); + //error_invalid_argument!("Invalid Candid values: {}", e) + Err(e) + })? .to_bytes() } Some((env, func)) => { @@ -208,9 +213,9 @@ pub fn blob_from_arguments( use rand::Rng; let mut rng = rand::thread_rng(); let seed: Vec = (0..2048).map(|_| rng.gen::()).collect(); - let config = candid::parser::configs::Configs::from_dhall(random) + let config = candid_parser::configs::Configs::from_dhall(random) .context("Failed to create candid parser config.")?; - let args = IDLArgs::any(&seed, &config, env, &func.args) + let args = candid_parser::random::any(&seed, &config, env, &func.args) .context("Failed to create idl args.")?; eprintln!("Sending the following random argument:\n{}\n", args); args.to_bytes_with_types(env, &func.args) @@ -235,17 +240,18 @@ pub fn fuzzy_parse_argument( let is_candid_format = first_char.map_or(false, |c| c == '('); // If parsing fails and method expects a single value, try parsing as IDLValue. // If it still fails, and method expects a text type, send arguments as text. - let args = arg_str.parse::().or_else(|_| { + let args = candid_parser::parse_idl_args(arg_str).or_else(|_| { if types.len() == 1 && !is_candid_format { let is_quote = first_char.map_or(false, |c| c == '"'); if &TypeInner::Text == types[0].as_ref() && !is_quote { Ok(IDLValue::Text(arg_str.to_string())) } else { - candid::pretty_parse::("Candid argument", arg_str) + candid_parser::parse_idl_value(arg_str) } .map(|v| IDLArgs::new(&[v])) } else { - candid::pretty_parse::("Candid argument", arg_str) + //candid::pretty_parse::("Candid argument", arg_str) + candid_parser::parse_idl_args(arg_str) } }); let bytes = args