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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
* feat: Recipes and prebuilt canisters are now cached locally
* feat: `icp settings autocontainerize true`, always use a docker container for all networks
* feat: `icp canister migrate-id` - initiate canister ID migration across subnets
* feat: install proxy canister when starting managed networks with all identities as controllers (or anonymous + default if more than 10 identities)
* feat: Install proxy canister when starting managed networks with all identities as controllers (or anonymous + default if more than 10 identities)
* `icp network status` displays the proxy canister principal
* feat: `icp network status` display more information about networks
* feat: `icp canister logs` to display the current canister logs
* use `--follow` to continuously poll for new logs. `--interval <n>` to poll every `n` seconds
* feat: Support `k`, `m`, `b`, `t` suffixes in `.yaml` files when specifying cycles amounts

# v0.1.0

Expand Down
3 changes: 3 additions & 0 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions crates/icp-cli/src/commands/canister/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use clap::Args;
use dialoguer::console::Term;
use ic_agent::Agent;
use icp::context::Context;
use icp::parsers::CyclesAmount;
use icp::prelude::*;
use icp_canister_interfaces::proxy::{ProxyArgs, ProxyResult};
use std::io::{self, Write};
use tracing::warn;

use crate::{
commands::args,
commands::parsers::parse_cycles_amount,
operations::misc::{ParsedArguments, fetch_canister_metadata, parse_args},
};

Expand Down Expand Up @@ -50,8 +50,8 @@ pub(crate) struct CallArgs {
/// Cycles to forward with the proxied call.
///
/// Only used when --proxy is specified. Defaults to 0.
#[arg(long, requires = "proxy", value_parser = parse_cycles_amount, default_value = "0")]
pub(crate) cycles: u128,
#[arg(long, requires = "proxy", default_value = "0")]
pub(crate) cycles: CyclesAmount,

/// Sends a query request to a canister instead of an update request.
///
Expand Down Expand Up @@ -136,7 +136,7 @@ pub(crate) async fn exec(ctx: &Context, args: &CallArgs) -> Result<(), anyhow::E
canister_id: cid,
method: args.method.clone(),
args: arg_bytes,
cycles: Nat::from(args.cycles),
cycles: Nat::from(args.cycles.get()),
};
let proxy_arg_bytes =
Encode!(&proxy_args).context("failed to encode proxy call arguments")?;
Expand Down
17 changes: 9 additions & 8 deletions crates/icp-cli/src/commands/canister/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use anyhow::anyhow;
use candid::{Nat, Principal};
use clap::Args;
use icp::context::Context;
use icp::parsers::CyclesAmount;
use icp::{Canister, context::CanisterSelection, prelude::*};
use icp_canister_interfaces::cycles_ledger::CanisterSettingsArg;

use crate::{
commands::args,
commands::parsers::parse_cycles_amount,
operations::create::CreateOperation,
progress::{ProgressManager, ProgressManagerSettings},
};
Expand All @@ -31,8 +31,8 @@ pub(crate) struct CanisterSettings {
/// Optional upper limit on cycles reserved for future resource payments.
/// Memory allocations that would push the reserved balance above this limit will fail.
/// Supports suffixes: k (thousand), m (million), b (billion), t (trillion).
#[arg(long, value_parser = parse_cycles_amount)]
pub(crate) reserved_cycles_limit: Option<u128>,
#[arg(long)]
pub(crate) reserved_cycles_limit: Option<CyclesAmount>,
}

/// Create a canister on a network
Expand All @@ -55,8 +55,8 @@ pub(crate) struct CreateArgs {

/// Cycles to fund canister creation.
/// Supports suffixes: k (thousand), m (million), b (billion), t (trillion).
#[arg(long, default_value_t = DEFAULT_CANISTER_CYCLES, value_parser = parse_cycles_amount)]
pub(crate) cycles: u128,
#[arg(long, default_value_t = CyclesAmount::from(DEFAULT_CANISTER_CYCLES))]
pub(crate) cycles: CyclesAmount,

/// The subnet to create canisters on.
#[arg(long)]
Expand All @@ -79,8 +79,9 @@ impl CreateArgs {
reserved_cycles_limit: self
.settings
.reserved_cycles_limit
.or(default.settings.reserved_cycles_limit.map(u128::from))
.map(Nat::from),
.clone()
.or(default.settings.reserved_cycles_limit.clone())
.map(|c| Nat::from(c.get())),
log_visibility: default.settings.log_visibility.clone().map(Into::into),
memory_allocation: self
.settings
Expand Down Expand Up @@ -134,7 +135,7 @@ pub(crate) async fn exec(ctx: &Context, args: &CreateArgs) -> Result<(), anyhow:
.collect();
let progress_manager = ProgressManager::new(ProgressManagerSettings { hidden: ctx.debug });
let create_operation =
CreateOperation::new(agent, args.subnet, args.cycles, existing_canisters);
CreateOperation::new(agent, args.subnet, args.cycles.get(), existing_canisters);

let canister_settings = args.canister_settings_with_default(&canister_info);
let pb = progress_manager.create_progress_bar(&canister);
Expand Down
10 changes: 5 additions & 5 deletions crates/icp-cli/src/commands/canister/settings/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use ic_agent::export::Principal;
use ic_management_canister_types::{CanisterStatusResult, EnvironmentVariable, LogVisibility};
use icp::ProjectLoadError;
use icp::context::{CanisterSelection, Context, TermWriter};
use icp::parsers::CyclesAmount;
use std::collections::{HashMap, HashSet};
use std::io::Write;

use crate::commands::args;
use crate::commands::parsers::parse_cycles_amount;

#[derive(Clone, Debug, Default, Args)]
pub(crate) struct ControllerOpt {
Expand Down Expand Up @@ -106,8 +106,8 @@ pub(crate) struct UpdateArgs {
/// Upper limit on cycles reserved for future resource payments.
/// Memory allocations that would push the reserved balance above this limit will fail.
/// Supports suffixes: k (thousand), m (million), b (billion), t (trillion).
#[arg(long, value_parser = parse_cycles_amount)]
reserved_cycles_limit: Option<u128>,
#[arg(long)]
reserved_cycles_limit: Option<CyclesAmount>,

#[arg(long, value_parser = memory_parser)]
wasm_memory_limit: Option<Byte>,
Expand Down Expand Up @@ -237,13 +237,13 @@ pub(crate) async fn exec(ctx: &Context, args: &UpdateArgs) -> Result<(), anyhow:
}
update = update.with_freezing_threshold(freezing_threshold);
}
if let Some(reserved_cycles_limit) = args.reserved_cycles_limit {
if let Some(reserved_cycles_limit) = &args.reserved_cycles_limit {
if configured_settings.reserved_cycles_limit.is_some() {
ctx.term.write_line(
"Warning: Reserved cycles limit is already set in icp.yaml; this new value will be overridden on next settings sync"
)?
}
update = update.with_reserved_cycles_limit(reserved_cycles_limit);
update = update.with_reserved_cycles_limit(reserved_cycles_limit.get());
}
if let Some(wasm_memory_limit) = args.wasm_memory_limit {
if configured_settings.wasm_memory_limit.is_some() {
Expand Down
12 changes: 6 additions & 6 deletions crates/icp-cli/src/commands/canister/top_up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ use bigdecimal::BigDecimal;
use candid::{Decode, Encode, Nat};
use clap::Args;
use icp::context::Context;
use icp::parsers::CyclesAmount;
use icp_canister_interfaces::cycles_ledger::{
CYCLES_LEDGER_PRINCIPAL, WithdrawArgs, WithdrawResponse,
};

use crate::commands::args;
use crate::commands::parsers::parse_cycles_amount;
use crate::operations::token::TokenAmount;

/// Top up a canister with cycles
#[derive(Debug, Args)]
pub(crate) struct TopUpArgs {
/// Amount of cycles to top up.
/// Supports suffixes: k (thousand), m (million), b (billion), t (trillion).
#[arg(long, value_parser = parse_cycles_amount)]
pub(crate) amount: u128,
#[arg(long)]
pub(crate) amount: CyclesAmount,

#[command(flatten)]
pub(crate) cmd_args: args::CanisterCommandArgs,
Expand All @@ -41,7 +41,7 @@ pub(crate) async fn exec(ctx: &Context, args: &TopUpArgs) -> Result<(), anyhow::
.await?;

let cargs = WithdrawArgs {
amount: Nat::from(args.amount),
amount: Nat::from(args.amount.get()),
from_subaccount: None,
to: cid,
created_at_time: None,
Expand All @@ -55,11 +55,11 @@ pub(crate) async fn exec(ctx: &Context, args: &TopUpArgs) -> Result<(), anyhow::

let response = Decode!(&bs, WithdrawResponse).context("failed to decode withdraw response")?;
if let Err(err) = response {
bail!("failed to top up: {}", err.format_error(args.amount));
bail!("failed to top up: {}", err.format_error(args.amount.get()));
}

let amount = TokenAmount {
amount: BigDecimal::new(args.amount.into(), 0),
amount: BigDecimal::new(args.amount.get().into(), 0),
symbol: "cycles".to_string(),
};

Expand Down
9 changes: 5 additions & 4 deletions crates/icp-cli/src/commands/cycles/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use anyhow::bail;
use bigdecimal::BigDecimal;
use clap::Args;
use icp::context::Context;
use icp::parsers::{CyclesAmount, parse_token_amount};

use crate::commands::args::TokenCommandArgs;
use crate::commands::parsers::{parse_cycles_amount, parse_subaccount, parse_token_amount};
use crate::commands::parsers::parse_subaccount;
use crate::operations::token::mint::mint_cycles;

/// Convert icp to cycles
Expand All @@ -17,8 +18,8 @@ pub(crate) struct MintArgs {

/// Amount of cycles to mint. Automatically determines the amount of ICP needed.
/// Supports suffixes: k (thousand), m (million), b (billion), t (trillion).
#[arg(long, conflicts_with = "icp", value_parser = parse_cycles_amount)]
pub(crate) cycles: Option<u128>,
#[arg(long, conflicts_with = "icp")]
pub(crate) cycles: Option<CyclesAmount>,

/// Subaccount to withdraw the ICP from.
#[arg(long, value_parser = parse_subaccount)]
Expand Down Expand Up @@ -53,7 +54,7 @@ pub(crate) async fn exec(ctx: &Context, args: &MintArgs) -> Result<(), anyhow::E
let mint_info = mint_cycles(
&agent,
args.icp.as_ref(),
args.cycles,
args.cycles.as_ref().map(|c| c.get()),
args.from_subaccount,
args.to_subaccount,
)
Expand Down
8 changes: 4 additions & 4 deletions crates/icp-cli/src/commands/cycles/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use anyhow::ensure;
use clap::Args;
use icp::context::Context;
use icp::parsers::CyclesAmount;
use icp_canister_interfaces::cycles_ledger::{CYCLES_LEDGER_BLOCK_FEE, CYCLES_LEDGER_PRINCIPAL};
use icrc_ledger_types::icrc1::account::Account;

use crate::commands::args::TokenCommandArgs;
use crate::commands::parsers::{parse_cycles_amount, parse_subaccount};
use crate::commands::parsers::parse_subaccount;
use crate::operations::token::transfer::icrc1_transfer;

/// Transfer cycles to another principal
#[derive(Debug, Args)]
pub(crate) struct TransferArgs {
/// Cycles amount to transfer.
/// Supports suffixes: k (thousand), m (million), b (billion), t (trillion).
#[arg(value_parser = parse_cycles_amount)]
pub(crate) amount: u128,
pub(crate) amount: CyclesAmount,

/// The receiver of the cycles transfer
pub(crate) receiver: Account,
Expand Down Expand Up @@ -56,7 +56,7 @@ pub(crate) async fn exec(ctx: &Context, args: &TransferArgs) -> Result<(), anyho
&agent,
args.from_subaccount,
CYCLES_LEDGER_PRINCIPAL,
args.amount.into(),
args.amount.get().into(),
receiver,
CYCLES_LEDGER_BLOCK_FEE.into(),
0,
Expand Down
9 changes: 5 additions & 4 deletions crates/icp-cli/src/commands/deploy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use candid::{CandidType, Principal};
use clap::Args;
use futures::{StreamExt, future::try_join_all, stream::FuturesOrdered};
use ic_agent::Agent;
use icp::parsers::CyclesAmount;
use icp::{
context::{CanisterSelection, Context, EnvironmentSelection},
identity::IdentitySelection,
Expand All @@ -13,7 +14,7 @@ use serde::Serialize;
use std::sync::Arc;

use crate::{
commands::{canister::create, parsers::parse_cycles_amount},
commands::canister::create,
operations::{
binding_env_vars::set_binding_env_vars_many,
build::build_many_with_progress_bar,
Expand Down Expand Up @@ -47,8 +48,8 @@ pub(crate) struct DeployArgs {

/// Cycles to fund canister creation.
/// Supports suffixes: k (thousand), m (million), b (billion), t (trillion).
#[arg(long, default_value_t = create::DEFAULT_CANISTER_CYCLES, value_parser = parse_cycles_amount)]
pub(crate) cycles: u128,
#[arg(long, default_value_t = CyclesAmount::from(create::DEFAULT_CANISTER_CYCLES))]
pub(crate) cycles: CyclesAmount,

#[command(flatten)]
pub(crate) identity: IdentityOpt,
Expand Down Expand Up @@ -122,7 +123,7 @@ pub(crate) async fn exec(ctx: &Context, args: &DeployArgs) -> Result<(), anyhow:
let create_operation = CreateOperation::new(
agent.clone(),
args.subnet,
args.cycles,
args.cycles.get(),
existing_canisters.into_values().collect(),
);
let mut futs = FuturesOrdered::new();
Expand Down
Loading
Loading