diff --git a/beem/account.py b/beem/account.py index d6dfddb7c9e2de5ae4770c23a92c6cfd0ec4f46f..912e46b89ab89dcddd70d02e9d412dc332fdcd3b 100644 --- a/beem/account.py +++ b/beem/account.py @@ -2937,6 +2937,69 @@ class Account(BlockchainObject): }) return self.blockchain.finalizeOp(op, account, "active", **kwargs) + #------------------------------------------------------------------------------- + # Recurring Transfer added in hf25 + #------------------------------------------------------------------------------- + def recurring_transfer(self, to, amount, asset, recurrence, executions, memo="", skip_account_check=False, account=None, **kwargs): + """ Transfer an asset to another account. + + :param str to: Recipient + :param float amount: Amount to transfer in each occurence, must have 3 decimal points + :param str asset: Asset to transfer + :param int recurrence: How often in hours to execute transfer + :param int executions: Number of times to recur before stopping execution + :param str memo: (optional) Memo, may begin with `#` for encrypted + messaging + :param bool skip_account_check: (optional) When True, the receiver + account name is not checked to speed up sending multiple transfers in a row + :param str account: (optional) the source account for the transfer + if not ``default_account`` + + + Transfer example: + + .. code-block:: python + + from beem.account import Account + from beem import Hive + active_wif = "5xxxx" + stm = Hive(keys=[active_wif]) + acc = Account("test", blockchain_instance=stm) + acc.transfer("test1", 1, "HIVE", 48, 5, "test") + + """ + + if account is None: + account = self + elif not skip_account_check: + account = Account(account, blockchain_instance=self.blockchain) + amount = Amount(amount, asset, blockchain_instance=self.blockchain) + if not skip_account_check: + to = Account(to, blockchain_instance=self.blockchain) + + to_name = extract_account_name(to) + account_name = extract_account_name(account) + if memo and memo[0] == "#": + from .memo import Memo + memoObj = Memo( + from_account=account, + to_account=to, + blockchain_instance=self.blockchain + ) + memo = memoObj.encrypt(memo[1:])["message"] + + op = operations.Recurring_transfer(**{ + "amount": amount, + "to": to_name, + "memo": memo, + "from": account_name, + "recurrence": recurrence, + "executions": executions, + "prefix": self.blockchain.prefix, + "json_str": not bool(self.blockchain.config["use_condenser"]), + }) + return self.blockchain.finalizeOp(op, account, "active", **kwargs) + def transfer_to_vesting(self, amount, to=None, account=None, skip_account_check=False, **kwargs): """ Vest STEEM diff --git a/beembase/operationids.py b/beembase/operationids.py index 36ae82da761d256438e65781a75c851e3452e7b5..4b4db9adfef59135ec1209a4c18ecc8cfbcd9eaf 100644 --- a/beembase/operationids.py +++ b/beembase/operationids.py @@ -4,6 +4,7 @@ ops = [ 'vote', 'comment', 'transfer', + 'recurring_transfer', 'transfer_to_vesting', 'withdraw_vesting', 'limit_order_create', diff --git a/beembase/operations.py b/beembase/operations.py index aca68bce5c18b6c1b189df6a5d8909893aed72c4..25c1fca45d91211045f520773ab813faacd8d768 100644 --- a/beembase/operations.py +++ b/beembase/operations.py @@ -66,6 +66,35 @@ class Transfer(GrapheneObject): ('memo', memo), ])) +#Added recurring transfer support for HF25 +class Recurring_transfer(GrapheneObject): + def __init__(self, *args, **kwargs): + # Allow for overwrite of prefix + if check_for_class(self, args): + return + if len(args) == 1 and len(kwargs) == 0: + kwargs = args[0] + prefix = kwargs.get("prefix", default_prefix) + json_str = kwargs.get("json_str", False) + if "memo" not in kwargs: + kwargs["memo"] = "" + if isinstance(kwargs["memo"], dict): + kwargs["memo"]["prefix"] = prefix + memo = Optional(Memo(**kwargs["memo"])) + elif isinstance(kwargs["memo"], string_types): + memo = (String(kwargs["memo"])) + else: + memo = Optional(Memo(kwargs["memo"])) + + super(Recurring_transfer, self).__init__(OrderedDict([ + ('from', String(kwargs["from"])), + ('to', String(kwargs["to"])), + ('amount', Amount(kwargs["amount"], prefix=prefix, json_str=json_str)), + ('memo', memo), + ('recurrence', Int16(kwargs["recurrence"])), + ('executions', Int16(kwargs["executions"])), + ])) + class Vote(GrapheneObject): def __init__(self, *args, **kwargs):