substrate_stellar_sdk/xdr/impls/
ledger_key.rs1use crate::{
2 compound_types::LimitedString,
3 types::{
4 LedgerKeyAccount, LedgerKeyClaimableBalance, LedgerKeyData, LedgerKeyLiquidityPool, LedgerKeyOffer,
5 LedgerKeyTrustLine, TrustLineAsset,
6 },
7 IntoAccountId, IntoClaimbleBalanceId, IntoHash, LedgerKey, StellarSdkError,
8};
9
10impl LedgerKey {
11 pub fn from_account_id<T: IntoAccountId>(account_id: T) -> Result<Self, StellarSdkError> {
12 let account_id = account_id.into_account_id()?;
13 Ok(Self::Account(LedgerKeyAccount { account_id }))
14 }
15
16 pub fn from_trustline<T: IntoAccountId>(account_id: T, asset: TrustLineAsset) -> Result<Self, StellarSdkError> {
17 let account_id = account_id.into_account_id()?;
18 Ok(Self::Trustline(LedgerKeyTrustLine { account_id, asset }))
19 }
20
21 pub fn from_offer<T: IntoAccountId>(seller_id: T, offer_id: i64) -> Result<Self, StellarSdkError> {
22 let seller_id = seller_id.into_account_id()?;
23 Ok(Self::Offer(LedgerKeyOffer { seller_id, offer_id }))
24 }
25
26 pub fn from_data<T: IntoAccountId, S: AsRef<[u8]>>(account_id: T, data_name: S) -> Result<Self, StellarSdkError> {
27 let account_id = account_id.into_account_id()?;
28 let data_name = LimitedString::new(data_name.as_ref().to_vec())?;
29 Ok(Self::Data(LedgerKeyData { account_id, data_name }))
30 }
31
32 pub fn from_claimable_balance_id<T: IntoClaimbleBalanceId>(balance_id: T) -> Result<Self, StellarSdkError> {
33 let balance_id = balance_id.into_claimable_balance_id()?;
34 Ok(Self::ClaimableBalance(LedgerKeyClaimableBalance { balance_id }))
35 }
36
37 pub fn from_liquidity_pool_id<T: IntoHash>(liquidity_pool_id: T) -> Result<Self, StellarSdkError> {
38 let liquidity_pool_id = liquidity_pool_id.into_hash()?;
39 Ok(Self::LiquidityPool(LedgerKeyLiquidityPool { liquidity_pool_id }))
40 }
41}