lssa/wallet/src/cli/chain.rs

48 lines
1.4 KiB
Rust
Raw Normal View History

2025-10-14 15:29:18 +03:00
use anyhow::Result;
use clap::Subcommand;
2025-10-20 10:01:54 +03:00
use crate::{SubcommandReturnValue, WalletCore, cli::WalletSubcommand};
2025-10-14 15:29:18 +03:00
///Represents generic chain CLI subcommand
#[derive(Subcommand, Debug, Clone)]
pub enum ChainSubcommand {
2025-10-20 10:01:54 +03:00
GetLatestBlockId {},
GetBlockAtId {
2025-10-14 15:29:18 +03:00
#[arg(short, long)]
2025-10-20 10:01:54 +03:00
id: u64,
2025-10-14 15:29:18 +03:00
},
2025-10-20 10:01:54 +03:00
GetTransactionAtHash {
2025-10-14 15:29:18 +03:00
#[arg(short, long)]
2025-10-20 10:01:54 +03:00
hash: String,
2025-10-14 15:29:18 +03:00
},
}
2025-10-20 10:01:54 +03:00
impl WalletSubcommand for ChainSubcommand {
2025-10-14 15:29:18 +03:00
async fn handle_subcommand(
self,
wallet_core: &mut WalletCore,
) -> Result<SubcommandReturnValue> {
match self {
2025-10-20 10:01:54 +03:00
ChainSubcommand::GetLatestBlockId {} => {
let latest_block_res = wallet_core.sequencer_client.get_last_block().await?;
2025-10-14 15:29:18 +03:00
2025-10-20 10:01:54 +03:00
println!("Last block id is {}", latest_block_res.last_block);
2025-10-14 15:29:18 +03:00
}
2025-10-20 10:01:54 +03:00
ChainSubcommand::GetBlockAtId { id } => {
let block_res = wallet_core.sequencer_client.get_block(id).await?;
2025-10-14 15:29:18 +03:00
2025-10-20 10:01:54 +03:00
println!("Last block id is {:#?}", block_res.block);
2025-10-14 15:29:18 +03:00
}
2025-10-20 10:01:54 +03:00
ChainSubcommand::GetTransactionAtHash { hash } => {
let tx_res = wallet_core
2025-10-14 15:29:18 +03:00
.sequencer_client
2025-10-20 10:01:54 +03:00
.get_transaction_by_hash(hash)
2025-10-14 15:29:18 +03:00
.await?;
2025-10-20 10:01:54 +03:00
println!("Last block id is {:#?}", tx_res.transaction);
2025-10-14 15:29:18 +03:00
}
}
2025-10-20 10:01:54 +03:00
Ok(SubcommandReturnValue::Empty)
2025-10-14 15:29:18 +03:00
}
}