Skip to content

Commit

Permalink
CLI: add congestion command (#1819)
Browse files Browse the repository at this point in the history
* CLI: add congestion command

* Update cli/src/wallet_cli/mod.rs

Co-authored-by: DaughterOfMars <[email protected]>

* fmt

---------

Co-authored-by: DaughterOfMars <[email protected]>
  • Loading branch information
thibault-martinez and DaughterOfMars authored Jan 9, 2024
1 parent 0e2c8ed commit 4030148
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
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,
}

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

0 comments on commit 4030148

Please sign in to comment.