Description

A memo is a field that can be included in a transaction to attach additional information to it. It is similar to adding a note or comment to a transaction for reference purposes.

// Define the possible types for the Memo
enum MemoType {
    MemoNone,
    MemoID,
    MemoText,
    MemoHash,
    MemoReturn,
}

// Define the Memo struct
struct Memo {
    memo_type: MemoType,
    value: Option<Vec<u8>>,
}

Interface Code

trait MemoTrait {
		// Creates a new Memo object	
		fn new(memo_type: MemoType, value: Option<Vec<u8>>) -> Self;
		
		// Getters
		fn memo_type(&self) -> &MemoType;
    fn value(&self) -> Option<&Vec<u8>>;

    // Methods to create different types of Memo
    fn none() -> Self;
    fn text(text: &str) -> Self;
    fn id(id: &str) -> Result<Self, Box<dyn std::error::Error>>;
    fn hash(hash: &[u8]) -> Result<Self, Box<dyn std::error::Error>>;
    fn r#return(hash: &[u8]) -> Result<Self, Box<dyn std::error::Error>>;

    // Conversion methods
    fn to_xdr_object(&self) -> stellar_xdr::Memo;
    fn from_xdr_object(object: stellar_xdr::Memo) -> Result<Self, Box<dyn std::error::Error>>;

}

Interface Code Link

https://github.com/rahul-soshte/rs-stellar-base/blob/main/src/memo.rs