substrate_stellar_sdk/xdr/impls/
memo.rs1use core::convert::AsRef;
2
3use crate::{xdr::compound_types::LimitedString, IntoHash, Memo, StellarSdkError};
4
5impl Memo {
6 pub fn from_text_memo<T: AsRef<[u8]>>(text: T) -> Result<Self, StellarSdkError> {
7 let text = text.as_ref();
8 let string = LimitedString::new(text.to_vec())?;
9 Ok(Self::MemoText(string))
10 }
11
12 pub fn from_id_memo(id: u64) -> Self {
13 Self::MemoId(id)
14 }
15
16 pub fn from_hash_memo<T: IntoHash>(hash: T) -> Result<Self, StellarSdkError> {
17 let hash = hash.into_hash()?;
18 Ok(Self::MemoHash(hash))
19 }
20
21 pub fn from_return_hash_memo<T: IntoHash>(return_hash: T) -> Result<Self, StellarSdkError> {
22 let return_hash = return_hash.into_hash()?;
23 Ok(Self::MemoReturn(return_hash))
24 }
25}