2025-10-14 15:29:18 +03:00
|
|
|
use anyhow::Result;
|
|
|
|
|
use clap::Subcommand;
|
|
|
|
|
|
2025-11-27 22:07:53 +03:00
|
|
|
use crate::{
|
|
|
|
|
WalletCore,
|
|
|
|
|
cli::{SubcommandReturnValue, WalletSubcommand},
|
|
|
|
|
};
|
2025-10-14 15:29:18 +03:00
|
|
|
|
2025-11-26 00:27:20 +03:00
|
|
|
/// Represents generic chain CLI subcommand
|
2025-10-14 15:29:18 +03:00
|
|
|
#[derive(Subcommand, Debug, Clone)]
|
|
|
|
|
pub enum ChainSubcommand {
|
2025-11-26 00:27:20 +03:00
|
|
|
/// Get current block id from sequencer
|
2025-10-23 17:33:25 +03:00
|
|
|
CurrentBlockId {},
|
2025-11-26 00:27:20 +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
|
|
|
},
|
2025-11-26 00:27:20 +03:00
|
|
|
/// Get transaction at hash from sequencer
|
2025-10-23 17:33:25 +03:00
|
|
|
Transaction {
|
2025-11-26 00:27:20 +03:00
|
|
|
/// hash - valid 32 byte hex string
|
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-23 17:33:25 +03:00
|
|
|
ChainSubcommand::CurrentBlockId {} => {
|
2025-10-20 10:01:54 +03:00
|
|
|
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-23 17:33:25 +03:00
|
|
|
ChainSubcommand::Block { id } => {
|
2025-10-20 10:01:54 +03:00
|
|
|
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-23 17:33:25 +03:00
|
|
|
ChainSubcommand::Transaction { hash } => {
|
2025-10-20 10:01:54 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|