soroban_cli/commands/ledger/entry/fetch/
args.rs1use crate::{
2 config::{
3 locator,
4 network::{self, Network},
5 },
6 rpc,
7 xdr::LedgerKey,
8};
9
10#[derive(Debug, clap::Args, Clone)]
11#[group(skip)]
12pub struct Args {
13 #[command(flatten)]
14 pub network: network::Args,
15
16 #[command(flatten)]
17 pub locator: locator::Args,
18
19 #[arg(long, default_value = "json")]
21 pub output: OutputFormat,
22}
23
24#[derive(thiserror::Error, Debug)]
25pub enum Error {
26 #[error(transparent)]
27 Network(#[from] network::Error),
28 #[error(transparent)]
29 Serde(#[from] serde_json::Error),
30 #[error(transparent)]
31 Rpc(#[from] rpc::Error),
32}
33
34#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, clap::ValueEnum, Default)]
35pub enum OutputFormat {
36 #[default]
38 Json,
39 JsonFormatted,
41 Xdr,
43}
44
45impl Args {
46 pub fn network(&self) -> Result<Network, Error> {
47 Ok(self.network.get(&self.locator)?)
48 }
49
50 pub async fn run(&self, ledger_keys: Vec<LedgerKey>) -> Result<(), Error> {
51 let network = self.network.get(&self.locator)?;
52 let client = network.rpc_client()?;
53 match self.output {
54 OutputFormat::Json => {
55 let resp = client.get_full_ledger_entries(&ledger_keys).await?;
56 println!("{}", serde_json::to_string(&resp)?);
57 }
58 OutputFormat::Xdr => {
59 let resp = client.get_ledger_entries(&ledger_keys).await?;
60 println!("{}", serde_json::to_string(&resp)?);
61 }
62 OutputFormat::JsonFormatted => {
63 let resp = client.get_full_ledger_entries(&ledger_keys).await?;
64 println!("{}", serde_json::to_string_pretty(&resp)?);
65 }
66 }
67
68 Ok(())
69 }
70}