Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: add congestion command #1819

Merged
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
1 change: 1 addition & 0 deletions cli/src/wallet_cli/completer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const WALLET_COMMANDS: &[&str] = &[
"claim",
"claimable-outputs",
"clear",
"congestion",
"consolidate",
"create-alias-output",
"create-native-token",
Expand Down
34 changes: 32 additions & 2 deletions cli/src/wallet_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use iota_sdk::{
},
utils::ConvertTo,
wallet::{
types::OutputData, ConsolidationParams, CreateNativeTokenParams, MintNftParams, OutputsToClaim,
SendNativeTokenParams, SendNftParams, SendParams, SyncOptions, TransactionOptions, Wallet,
types::OutputData, ConsolidationParams, CreateNativeTokenParams, Error as WalletError, MintNftParams,
OutputsToClaim, SendNativeTokenParams, SendNftParams, SendParams, SyncOptions, TransactionOptions, Wallet,
},
U256,
};
Expand Down Expand Up @@ -81,6 +81,8 @@ pub enum WalletCommand {
},
/// Print details about claimable outputs - if there are any.
ClaimableOutputs,
/// Checks if an account is ready to issue a block.
Congestion { account_id: Option<AccountId> },
/// Consolidate all basic outputs into one address.
Consolidate,
/// Create a new account output.
Expand Down Expand Up @@ -478,6 +480,33 @@ pub async fn claimable_outputs_command(wallet: &Wallet) -> Result<(), Error> {
Ok(())
}

// `congestion` command
pub async fn congestion_command(wallet: &Wallet, account_id: Option<AccountId>) -> Result<(), Error> {
let account_id = {
let wallet_data = wallet.data().await;
account_id
.or_else(|| {
wallet_data
.accounts()
.next()
.map(|o| o.output.as_account().account_id_non_null(&o.output_id))
})
.or_else(|| {
wallet_data
.implicit_accounts()
.next()
.map(|o| AccountId::from(&o.output_id))
})
.ok_or(WalletError::NoAccountToIssueBlock)?
};

let congestion = wallet.client().get_account_congestion(&account_id).await?;

println_log_info!("{congestion:#?}");

Ok(())
}

// `consolidate` command
pub async fn consolidate_command(wallet: &Wallet) -> Result<(), Error> {
println_log_info!("Consolidating outputs.");
Expand Down Expand Up @@ -1151,6 +1180,7 @@ pub async fn prompt_internal(
WalletCommand::BurnNft { nft_id } => burn_nft_command(wallet, nft_id).await,
WalletCommand::Claim { output_id } => claim_command(wallet, output_id).await,
WalletCommand::ClaimableOutputs => claimable_outputs_command(wallet).await,
WalletCommand::Congestion { account_id } => congestion_command(wallet, account_id).await,
WalletCommand::Consolidate => consolidate_command(wallet).await,
WalletCommand::CreateAccountOutput => create_account_output_command(wallet).await,
WalletCommand::CreateNativeToken {
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/api/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ pub struct CongestionResponse {
pub reference_mana_cost: u64,
/// The Block Issuance Credits of the requested account.
#[serde(with = "string")]
pub block_issuance_credits: u64,
pub block_issuance_credits: i128,
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
}

/// Response of POST /api/core/v3/blocks.
Expand Down