54 lines
1.5 KiB
Rust
Raw Normal View History

2025-10-14 15:29:18 +03:00
use anyhow::Result;
use clap::Subcommand;
use common::HashType;
use sequencer_service_rpc::RpcClient as _;
2025-10-14 15:29:18 +03:00
use crate::{
WalletCore,
cli::{SubcommandReturnValue, WalletSubcommand},
};
2025-10-14 15:29:18 +03:00
2026-03-10 00:17:43 +03:00
/// Represents generic chain CLI subcommand.
2025-10-14 15:29:18 +03:00
#[derive(Subcommand, Debug, Clone)]
pub enum ChainSubcommand {
2026-03-10 00:17:43 +03:00
/// Get current block id from sequencer.
2026-03-04 18:42:33 +03:00
CurrentBlockId,
2026-03-10 00:17:43 +03:00
/// Get block at id from sequencer.
2025-10-23 17:33:25 +03:00
Block {
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
},
2026-03-10 00:17:43 +03:00
/// Get transaction at hash from sequencer.
2025-10-23 17:33:25 +03:00
Transaction {
2026-03-10 00:17:43 +03:00
/// hash - valid 32 byte hex string.
#[arg(short = 't', long)]
hash: HashType,
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 {
2026-03-09 18:27:56 +03:00
Self::CurrentBlockId => {
let latest_block_id = wallet_core.sequencer_client.get_last_block_id().await?;
2025-10-14 15:29:18 +03:00
println!("Last block id is {latest_block_id}");
2025-10-14 15:29:18 +03:00
}
2026-03-09 18:27:56 +03:00
Self::Block { id } => {
let block = wallet_core.sequencer_client.get_block(id).await?;
2025-10-14 15:29:18 +03:00
println!("Last block id is {block:#?}");
2025-10-14 15:29:18 +03:00
}
2026-03-09 18:27:56 +03:00
Self::Transaction { hash } => {
let tx = wallet_core.sequencer_client.get_transaction(hash).await?;
2025-10-14 15:29:18 +03:00
println!("Transaction is {tx:#?}");
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
}
}