Skip to content
This repository was archived by the owner on May 14, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions kin/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down