soroban_cli/commands/ledger/entry/fetch/
liquidity_pool.rs1use super::args::Args;
2use crate::xdr::{Hash, LedgerKey, LedgerKeyLiquidityPool, PoolId};
3use clap::{command, Parser};
4use hex::FromHexError;
5use soroban_spec_tools::utils::padded_hex_from_str;
6use std::fmt::Debug;
7
8#[derive(Parser, Debug, Clone)]
9#[group(skip)]
10pub struct Cmd {
11 #[arg(long)]
13 pub id: Vec<String>,
14
15 #[command(flatten)]
16 pub args: Args,
17}
18
19#[derive(thiserror::Error, Debug)]
20pub enum Error {
21 #[error(transparent)]
22 FromHexError(#[from] FromHexError),
23 #[error("provided hash value is invalid: {0}")]
24 InvalidHash(String),
25 #[error(transparent)]
26 Run(#[from] super::args::Error),
27}
28
29impl Cmd {
30 pub async fn run(&self) -> Result<(), Error> {
31 let mut ledger_keys = vec![];
32 self.insert_keys(&mut ledger_keys)?;
33 Ok(self.args.run(ledger_keys).await?)
34 }
35
36 fn insert_keys(&self, ledger_keys: &mut Vec<LedgerKey>) -> Result<(), Error> {
37 for x in &self.id {
38 let padded_hex = padded_hex_from_str(x, 32)?;
39 let hash_bytes: [u8; 32] = padded_hex
40 .try_into()
41 .map_err(|_| Error::InvalidHash(x.clone()))?;
42 let hash = Hash(hash_bytes);
43 let key = LedgerKey::LiquidityPool(LedgerKeyLiquidityPool {
44 liquidity_pool_id: PoolId(hash),
45 });
46 ledger_keys.push(key);
47 }
48
49 Ok(())
50 }
51}