def make_memo(memo: str, memo_type: str) -> Optional[Memo]: if not memo: return None if memo_type == Transaction.MEMO_TYPES.id: return IdMemo(int(memo)) elif memo_type == Transaction.MEMO_TYPES.hash: return HashMemo(memo_base64_to_hex(memo)) elif memo_type == Transaction.MEMO_TYPES.text: return TextMemo(memo) else: raise ValueError()
def generate_uri(self, address: str, memo: str): """ Returns Transaction as envelope """ return stellar_uri.PayStellarUri(destination=address, memo=TextMemo(text=memo), asset=Asset.native(), network_passphrase=self.network_phrase, message='Deposit to Discord', ).to_uri()
def check_memo(memo): try: TextMemo(text=memo) return True except MemoInvalidException: return False
def test_memo_str_text_memo(): assert utils.memo_str(TextMemo("test")) == ("test", Transaction.MEMO_TYPES.text)