substrate_stellar_sdk/xdr/impls/
account_id.rs

1use crate::{AccountId, MuxedAccount, StellarSdkError};
2use sp_std::vec::Vec;
3
4pub trait IntoAccountId: Sized {
5    fn into_account_id(self) -> Result<AccountId, StellarSdkError>;
6
7    // this function is for efficiency, if the only reason to convert
8    // self into an account id is to get the encoding in the next step
9    // in that case it would be a waste to first decode and then encode again
10    fn into_encoding(self) -> Vec<u8>;
11}
12
13impl IntoAccountId for AccountId {
14    fn into_account_id(self) -> Result<AccountId, StellarSdkError> {
15        Ok(self)
16    }
17
18    fn into_encoding(self) -> Vec<u8> {
19        self.to_encoding()
20    }
21}
22
23impl<T: AsRef<[u8]>> IntoAccountId for T {
24    fn into_account_id(self) -> Result<AccountId, StellarSdkError> {
25        Ok(AccountId::from_encoding(self)?)
26    }
27
28    fn into_encoding(self) -> Vec<u8> {
29        self.as_ref().to_vec()
30    }
31}
32
33impl From<AccountId> for MuxedAccount {
34    fn from(account_id: AccountId) -> Self {
35        MuxedAccount::KeyTypeEd25519(account_id.into_binary())
36    }
37}