From bfc48cab8fb1932e0d835fa9093bfaf0fb7c1599 Mon Sep 17 00:00:00 2001 From: Michael Goldbegrer Date: Thu, 19 Dec 2019 11:28:07 -0500 Subject: [PATCH] allow create_account and send_kin (and their underlying builder methods) to accept a new parameter 'raw_memo' (default: False, so the original behavior remains the default behavior) which if true, passes the supplied memo text verbatim to the transaction builder instead of using the MEMO_TEMPLATE --- kin/account.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/kin/account.py b/kin/account.py index 9a1d5df..78cffd1 100644 --- a/kin/account.py +++ b/kin/account.py @@ -127,12 +127,13 @@ def get_transaction_builder(self, fee: int) -> Builder: secret=self.keypair.secret_seed) async def create_account(self, address: str, starting_balance: Union[float, str], fee: int, - memo_text: Optional[str] = None) -> str: + memo_text: Optional[str] = None, raw_memo: bool = False) -> str: """Create an account identified by the provided address. :param address: the address of the account to create. :param starting_balance: the starting KIN balance of the account. :param memo_text: (optional) a text to put into transaction memo, up to MEMO_CAP chars. + :param raw_memo: (optional) if False, the transaction's memo will be built from the MEMO_TEMPLATE :param fee: fee to be deducted for the tx :return: the hash of the transaction @@ -143,7 +144,7 @@ async def create_account(self, address: str, starting_balance: Union[float, str] :raises: KinErrors.NotValidParamError: if the amount is too precise :raises: KinErrors.NotValidParamError: if the fee is not valid """ - builder = self.build_create_account(address, starting_balance, fee, memo_text) + builder = self.build_create_account(address, starting_balance, fee, memo_text, raw_memo) async with self.channel_manager.get_channel() as channel: await builder.set_channel(channel) @@ -154,12 +155,13 @@ async def create_account(self, address: str, starting_balance: Union[float, str] return await self.submit_transaction(builder) async def send_kin(self, address: str, amount: Union[float, str], fee: int, - memo_text: Optional[str] = None) -> str: + memo_text: Optional[str] = None, raw_memo: bool = False) -> str: """Send KIN to the account identified by the provided address. :param address: the account to send KIN to. :param amount: the amount of KIN to send. :param memo_text: (optional) a text to put into transaction memo. + :param raw_memo: (optional) if False, the transaction's memo will be built from the MEMO_TEMPLATE :param fee: fee to be deducted :return: the hash of the transaction @@ -172,7 +174,7 @@ async def send_kin(self, address: str, amount: Union[float, str], fee: int, :raises: KinErrors.NotValidParamError if the memo is longer than MEMO_CAP characters :raises: KinErrors.NotValidParamError: if the fee is not valid """ - builder = self.build_send_kin(address, amount, fee, memo_text) + builder = self.build_send_kin(address, amount, fee, memo_text, raw_memo) async with self.channel_manager.get_channel() as channel: await builder.set_channel(channel) builder.sign(channel) @@ -182,12 +184,13 @@ async def send_kin(self, address: str, amount: Union[float, str], fee: int, return await self.submit_transaction(builder) def build_create_account(self, address: str, starting_balance: Union[float, str], fee: int, - memo_text: Optional[str] = None) -> Builder: + memo_text: Optional[str] = None, raw_memo: bool = False) -> Builder: """Build a tx that will create an account identified by the provided address. - + :param address: the address of the account to create. :param starting_balance: the starting XLM balance of the account. :param memo_text: (optional) a text to put into transaction memo, up to MEMO_CAP chars. + :param raw_memo: (optional) if False, the transaction's memo will be built from the MEMO_TEMPLATE :param fee: fee to be deducted for the tx :return: a transaction builder object @@ -202,17 +205,22 @@ def build_create_account(self, address: str, starting_balance: Union[float, str] # Build the transaction. builder = self.get_transaction_builder(fee) - builder.add_text_memo(build_memo(self.app_id, memo_text)) + + if raw_memo == False: + memo_text = build_memo(self.app_id, memo_text) + + builder.add_text_memo(memo_text) builder.append_create_account_op(address, str(starting_balance), source=self.keypair.public_address) return builder def build_send_kin(self, address: str, amount: Union[float, str], fee: int, - memo_text: Optional[str] = None) -> Builder: + memo_text: Optional[str] = None, raw_memo: bool = False) -> Builder: """Build a tx to send KIN to the account identified by the provided address. :param address: the account to send asset to. :param amount: the KIN amount to send. :param memo_text: (optional) a text to put into transaction memo. + :param raw_memo: (optional) if False, the transaction's memo will be built from the MEMO_TEMPLATE :param fee: fee to be deducted for the tx :return: a transaction builder @@ -228,7 +236,11 @@ def build_send_kin(self, address: str, amount: Union[float, str], fee: int, raise ValueError('Amount : {} must be positive'.format(amount)) builder = self.get_transaction_builder(fee) - builder.add_text_memo(build_memo(self.app_id, memo_text)) + + if raw_memo == False: + memo_text = build_memo(self.app_id, memo_text) + + builder.add_text_memo(memo_text) builder.append_payment_op(address, str(amount), source=self.keypair.public_address) return builder