Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ members = [
]

[patch.crates-io.ic-agent]
version = "0.2.0"
version = "0.3.0"
git = "https://github.com/dfinity/agent-rs.git"
branch = "next"
rev = "5472fb610faa6cc1f0c12c82a745e435603fae08"
rev = "d0a17fcb64d658b782fd5e5158e748047403964a"

[patch.crates-io.ic-identity-hsm]
version = "0.2.0"
version = "0.2.1"
git = "https://github.com/dfinity/agent-rs.git"
branch = "next"
rev = "5472fb610faa6cc1f0c12c82a745e435603fae08"
rev = "d0a17fcb64d658b782fd5e5158e748047403964a"

[patch.crates-io.ic-types]
version = "0.1.2"
git = "https://github.com/dfinity/agent-rs.git"
branch = "next"
rev = "5472fb610faa6cc1f0c12c82a745e435603fae08"
rev = "d0a17fcb64d658b782fd5e5158e748047403964a"

[patch.crates-io.ic-utils]
version = "0.2.0"
version = "0.2.1"
git = "https://github.com/dfinity/agent-rs.git"
branch = "next"
rev = "5472fb610faa6cc1f0c12c82a745e435603fae08"
rev = "d0a17fcb64d658b782fd5e5158e748047403964a"
2 changes: 1 addition & 1 deletion e2e/tests-dfx/assetscanister.bash
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ CHERRIES" "$stdout"
dfx_start
dfx canister --no-wallet create --all
dfx build
dfx canister --no-wallet install --memory-allocation 15mb e2e_project_assets
dfx canister --no-wallet install e2e_project_assets

# retrieve() refuses to serve just part of an asset
assert_command_fail dfx canister call --query e2e_project_assets retrieve '("/large-asset.bin")'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ teardown() {
ID=$(dfx canister id hello)

# Set controller using canister name and identity name
assert_command dfx canister set-controller hello "${BOB_WALLET}"
assert_match "Set \"${BOB_WALLET}\" as controller of \"hello\"."
assert_command dfx canister update-settings hello --controller "${BOB_WALLET}"
assert_match "Updated \"${BOB_WALLET}\" as controller of \"hello\"."

# Juana is controller, Jose cannot reinstall
assert_command_fail dfx canister install hello -m reinstall
Expand All @@ -47,22 +47,22 @@ teardown() {

assert_command dfx identity use bob
# Set controller using canister id and principal
assert_command dfx canister set-controller "${ID}" "${ALICE_WALLET}"
assert_match "Set \"${ALICE_WALLET}\" as controller of \"${ID}\"."
assert_command dfx canister update-settings "${ID}" --controller "${ALICE_WALLET}"
assert_match "Updated \"${ALICE_WALLET}\" as controller of \"${ID}\"."
assert_command_fail dfx canister install hello -m reinstall

# Set controller using combination of name/id and identity/principal
assert_command dfx --identity alice canister set-controller hello "${BOB_WALLET}"
assert_match "Set \"${BOB_WALLET}\" as controller of \"hello\"."
assert_command dfx --identity alice canister update-settings hello --controller "${BOB_WALLET}"
assert_match "Updated \"${BOB_WALLET}\" as controller of \"hello\"."

assert_command dfx --identity bob canister set-controller "${ID}" alice
assert_match "Set \"alice\" as controller of \"${ID}\"."
assert_command dfx --identity bob canister update-settings "${ID}" --controller alice
assert_match "Updated \"alice\" as controller of \"${ID}\"."

# Set controller using invalid principal/identity fails
assert_command_fail dfx --identity alice canister set-controller hello charlie
assert_command_fail dfx --identity alice canister --no-wallet update-settings hello --controller charlie
assert_match "Identity charlie does not exist"

# Set controller using invalid canister name/id fails
assert_command_fail dfx --identity alice canister set-controller hello_assets bob
assert_command_fail dfx --identity alice canister --no-wallet update-settings hello_assets --controller bob
assert_match "Cannot find canister id. Please issue 'dfx canister create hello_assets'."
}
}
14 changes: 7 additions & 7 deletions e2e/tests-dfx/wallet.bash
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ teardown() {
setup_actuallylocal_network

# get Canister IDs to install the wasm onto
dfx canister --network actuallylocal create dummy_canister1
ID=$(dfx canister --network actuallylocal id dummy_canister1)
dfx canister --network actuallylocal create dummy_canister2
ID_TWO=$(dfx canister --network actuallylocal id dummy_canister2)
dfx canister --network actuallylocal create hello
ID=$(dfx canister --network actuallylocal id hello)
dfx canister --network actuallylocal create hello_assets
ID_TWO=$(dfx canister --network actuallylocal id hello_assets)

# set controller to user
dfx canister --network actuallylocal set-controller dummy_canister1 "$(dfx identity get-principal)"
dfx canister --network actuallylocal set-controller dummy_canister2 "$(dfx identity get-principal)"
dfx canister --network actuallylocal update-settings hello --controller "$(dfx identity get-principal)"
dfx canister --network actuallylocal update-settings hello_assets --controller "$(dfx identity get-principal)"

# We're testing on a local network so the create command actually creates a wallet
# Delete this file to force associate wallet created by deploy-wallet to identity
Expand All @@ -49,7 +49,7 @@ teardown() {
dfx_new
dfx_start
WALLET_ID=$(dfx identity get-wallet)
CREATE_RES=$(dfx canister --no-wallet call "${WALLET_ID}" wallet_create_wallet "(record { cycles = (2000000000000:nat64); controller = opt principal \"$(dfx identity get-principal)\";})")
CREATE_RES=$(dfx canister --no-wallet call "${WALLET_ID}" wallet_create_wallet "(record { cycles = (2000000000000:nat64); settings = record {controller = opt principal \"$(dfx identity get-principal)\";};})")
CHILD_ID=$(echo "${CREATE_RES}" | tr '\n' ' ' | cut -d'"' -f 2)
assert_command dfx canister --no-wallet call "${CHILD_ID}" wallet_balance '()'
}
Expand Down
6 changes: 3 additions & 3 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
"dfinity": {
"branch": "master",
"repo": "ssh://git@github.com/dfinity-lab/dfinity",
"rev": "8967aa9f7435ea7eab47f4d9e1c5098ae4cc974c",
"rev": "6c7e2dd6f85b655809947b618c7d343429c34438",
"type": "git"
},
"ic-ref": {
"repo": "ssh://git@github.com/dfinity-lab/ic-ref",
"rev": "215641629ace2d590013f89bb3f3fe3b0a0d3c3b",
"tag": "0.16.0",
"rev": "a858395300d67685545e945dd4afd4b6af26c1a6",
"tag": "0.17.0",
"type": "git"
},
"motoko": {
Expand Down
14 changes: 7 additions & 7 deletions src/dfx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,29 @@ wasmparser = "0.45.0"
webpki-roots = "0.21.0"

[dependencies.ic-agent]
version = "0.2.0"
version = "0.3.0"
git = "https://github.com/dfinity/agent-rs.git"
branch = "next"
rev = "5472fb610faa6cc1f0c12c82a745e435603fae08"
rev = "d0a17fcb64d658b782fd5e5158e748047403964a"
features = ["reqwest"]

[dependencies.ic-identity-hsm]
version = "0.2.0"
version = "0.2.1"
git = "https://github.com/dfinity/agent-rs.git"
branch = "next"
rev = "5472fb610faa6cc1f0c12c82a745e435603fae08"
rev = "d0a17fcb64d658b782fd5e5158e748047403964a"

[dependencies.ic-types]
version = "0.1.2"
git = "https://github.com/dfinity/agent-rs.git"
branch = "next"
rev = "5472fb610faa6cc1f0c12c82a745e435603fae08"
rev = "d0a17fcb64d658b782fd5e5158e748047403964a"

[dependencies.ic-utils]
version = "0.2.0"
version = "0.2.1"
git = "https://github.com/dfinity/agent-rs.git"
branch = "next"
rev = "5472fb610faa6cc1f0c12c82a745e435603fae08"
rev = "d0a17fcb64d658b782fd5e5158e748047403964a"

[dev-dependencies]
env_logger = "0.6"
Expand Down
8 changes: 5 additions & 3 deletions src/dfx/src/commands/canister/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use candid::{CandidType, Decode, Deserialize};
use clap::{ArgSettings, Clap};
use ic_types::principal::Principal as CanisterId;
use ic_utils::canister::{Argument, Canister};
use ic_utils::interfaces::management_canister::{CanisterInstall, MgmtMethod};
use ic_utils::interfaces::management_canister::builders::{CanisterInstall, CanisterSettings};
use ic_utils::interfaces::management_canister::MgmtMethod;
use ic_utils::interfaces::wallet::{CallForwarder, CallResult};
use ic_utils::interfaces::Wallet;
use std::option::Option;
Expand Down Expand Up @@ -123,11 +124,11 @@ pub fn get_effective_canister_id(
let install_args = candid::Decode!(arg_value, CanisterInstall)?;
Ok(install_args.canister_id)
}
MgmtMethod::SetController => {
MgmtMethod::UpdateSettings => {
#[derive(CandidType, Deserialize)]
struct In {
canister_id: CanisterId,
new_controller: CanisterId,
settings: CanisterSettings,
}
let in_args = candid::Decode!(arg_value, In)?;
Ok(in_args.canister_id)
Expand All @@ -137,6 +138,7 @@ pub fn get_effective_canister_id(
| MgmtMethod::CanisterStatus
| MgmtMethod::DeleteCanister
| MgmtMethod::DepositCycles
| MgmtMethod::UninstallCode
| MgmtMethod::ProvisionalTopUpCanister => {
#[derive(CandidType, Deserialize)]
struct In {
Expand Down
109 changes: 103 additions & 6 deletions src/dfx/src/commands/canister/create.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
use crate::lib::environment::Environment;
use crate::lib::error::DfxResult;
use crate::lib::ic_attributes::{
get_compute_allocation, get_freezing_threshold, get_memory_allocation, CanisterSettings,
};
use crate::lib::identity::identity_manager::IdentityManager;
use crate::lib::identity::identity_utils::CallSender;
use crate::lib::operations::canister::create_canister;
use crate::lib::root_key::fetch_root_key_if_needed;
use crate::util::clap::validators::cycle_amount_validator;
use crate::util::clap::validators::{
compute_allocation_validator, freezing_threshold_validator, memory_allocation_validator,
};
use crate::util::expiry_duration;

use anyhow::bail;
use clap::Clap;
use anyhow::{anyhow, bail};
use clap::{ArgSettings, Clap};
use ic_agent::identity::Identity;
use ic_types::principal::Principal as CanisterId;

/// Creates an empty canister on the Internet Computer and
/// associates the Internet Computer assigned Canister ID to the canister name.
Expand All @@ -25,6 +34,21 @@ pub struct CanisterCreateOpts {
/// This amount is deducted from the wallet's cycle balance.
#[clap(long, validator(cycle_amount_validator))]
with_cycles: Option<String>,

/// Specifies the identity name or the principal of the new controller.
controller: Option<String>,

/// Specifies the canister's compute allocation. This should be a percent in the range [0..100]
#[clap(long, short('c'), validator(compute_allocation_validator))]
compute_allocation: Option<String>,

/// Specifies how much memory the canister is allowed to use in total.
/// This should be a value in the range [0..256 TB]
#[clap(long, validator(memory_allocation_validator))]
memory_allocation: Option<String>,

#[clap(long, validator(freezing_threshold_validator), setting = ArgSettings::Hidden)]
freezing_threshold: Option<String>,
}

pub async fn exec(
Expand All @@ -36,21 +60,94 @@ pub async fn exec(
let timeout = expiry_duration();

fetch_root_key_if_needed(env).await?;

let with_cycles = opts.with_cycles.as_deref();
if let Some(canister_name) = opts.canister_name.clone() {

let config_interface = config.get_config();

let controller = if let Some(controller) = opts.controller.clone() {
match CanisterId::from_text(controller.clone()) {
Ok(principal) => Some(principal),
Err(_) => {
let current_id = env.get_selected_identity().unwrap();
if current_id == &controller {
Some(env.get_selected_identity_principal().unwrap())
} else {
let identity_name = &controller;
let sender = IdentityManager::new(env)?
.instantiate_identity_from_name(&identity_name.clone())?;
Some(sender.sender().map_err(|err| anyhow!(err))?)
}
}
}
} else {
None
};

if let Some(canister_name) = opts.canister_name.as_deref() {
let compute_allocation = get_compute_allocation(
opts.compute_allocation.clone(),
config_interface,
canister_name,
)?;
let memory_allocation = get_memory_allocation(
opts.memory_allocation.clone(),
config_interface,
canister_name,
)?;
let freezing_threshold = get_freezing_threshold(
opts.freezing_threshold.clone(),
config_interface,
canister_name,
)?;
create_canister(
env,
canister_name.as_str(),
canister_name,
timeout,
with_cycles,
call_sender,
CanisterSettings {
controller,
compute_allocation,
memory_allocation,
freezing_threshold,
},
)
.await
.await?;
Ok(())
} else if opts.all {
// Create all canisters.
if let Some(canisters) = &config.get_config().canisters {
for canister_name in canisters.keys() {
create_canister(env, canister_name, timeout, with_cycles, call_sender).await?;
let compute_allocation = get_compute_allocation(
opts.compute_allocation.clone(),
config_interface,
canister_name,
)?;
let memory_allocation = get_memory_allocation(
opts.memory_allocation.clone(),
config_interface,
canister_name,
)?;
let freezing_threshold = get_freezing_threshold(
opts.freezing_threshold.clone(),
config_interface,
canister_name,
)?;
create_canister(
env,
canister_name,
timeout,
with_cycles,
call_sender,
CanisterSettings {
controller: controller.clone(),
compute_allocation,
memory_allocation,
freezing_threshold,
},
)
.await?;
}
}
Ok(())
Expand Down
Loading