soroban_cli/commands/ledger/entry/fetch/
account.rs1use std::array::TryFromSliceError;
2use std::fmt::Debug;
3
4use super::args::Args;
5use crate::{
6 commands::config::{self, locator},
7 xdr::{LedgerKey, LedgerKeyAccount, MuxedAccount},
8};
9use clap::{command, Parser};
10
11#[derive(Parser, Debug, Clone)]
12#[group(skip)]
13pub struct Cmd {
14 #[arg(long)]
16 pub account: String,
17
18 #[command(flatten)]
19 pub args: Args,
20
21 #[arg(long)]
23 pub hd_path: Option<usize>,
24}
25
26#[derive(thiserror::Error, Debug)]
27pub enum Error {
28 #[error(transparent)]
29 Config(#[from] config::key::Error),
30 #[error("provided asset is invalid: {0}")]
31 InvalidAsset(String),
32 #[error("provided data name is invalid: {0}")]
33 InvalidDataName(String),
34 #[error(transparent)]
35 Locator(#[from] locator::Error),
36 #[error(transparent)]
37 TryFromSliceError(#[from] TryFromSliceError),
38 #[error(transparent)]
39 Run(#[from] super::args::Error),
40}
41
42impl Cmd {
43 pub async fn run(&self) -> Result<(), Error> {
44 let mut ledger_keys = vec![];
45 self.insert_account_keys(&mut ledger_keys)?;
46 Ok(self.args.run(ledger_keys).await?)
47 }
48
49 fn insert_account_keys(&self, ledger_keys: &mut Vec<LedgerKey>) -> Result<(), Error> {
50 let acc = self.muxed_account(&self.account)?;
51 let key = LedgerKey::Account(LedgerKeyAccount {
52 account_id: acc.account_id(),
53 });
54
55 ledger_keys.push(key);
56
57 Ok(())
58 }
59
60 fn muxed_account(&self, account: &str) -> Result<MuxedAccount, Error> {
61 Ok(self
62 .args
63 .locator
64 .read_key(account)?
65 .muxed_account(self.hd_path)?)
66 }
67}