From b26eb7edd49a1799eefc9f877c5a74c96838b8f7 Mon Sep 17 00:00:00 2001 From: mtrela Date: Wed, 5 May 2021 13:20:25 +0200 Subject: [PATCH 1/6] Extension in 'update_proposal' is internally created --- beembase/objects.py | 2 +- beembase/operations.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/beembase/objects.py b/beembase/objects.py index 2131fef8..586eeb3f 100644 --- a/beembase/objects.py +++ b/beembase/objects.py @@ -363,7 +363,7 @@ def __init__(self, o): else: type_id = ~0 else: - type_id, data = o + type_id, data = o if type_id == 1: data = (UpdateProposalEndDate(o['value'])) diff --git a/beembase/operations.py b/beembase/operations.py index 41e40ab0..126024a9 100644 --- a/beembase/operations.py +++ b/beembase/operations.py @@ -402,8 +402,9 @@ def __init__(self, *args, **kwargs): prefix = kwargs.get("prefix", default_prefix) extensions = Array([]) - if "extensions" in kwargs and kwargs["extensions"]: - extensions = Array([UpdateProposalExtensions(o) for o in kwargs["extensions"]]) + if "end_date" in kwargs and kwargs["end_date"]: + extension = { 'type': 'update_proposal_end_date', 'value': {'end_date': kwargs["end_date"]} } + extensions = Array([UpdateProposalExtensions(extension)]) super(Update_proposal, self).__init__( From d050873f1df75f3efa35653be177d81e63c3394a Mon Sep 17 00:00:00 2001 From: sicarius97 <73046273+sicarius97@users.noreply.github.com> Date: Sat, 12 Jun 2021 13:18:18 -0500 Subject: [PATCH 2/6] added ide section and vscode to git ignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 41fdc26b..a1a561f9 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,6 @@ target/ *.swp .ropeproject/ */.ropeproject/ + +# IDEs +.vscode From d9697b752bf41975527e437574ce38a3302021f7 Mon Sep 17 00:00:00 2001 From: sicarius97 <73046273+sicarius97@users.noreply.github.com> Date: Sat, 12 Jun 2021 20:37:46 -0500 Subject: [PATCH 3/6] added collateralized_convert operation and commented out unused modules --- beem/cli.py | 2 +- beem/transactionbuilder.py | 4 ++-- beembase/operationids.py | 2 +- beembase/operations.py | 18 ++++++++++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/beem/cli.py b/beem/cli.py index cf81d075..3bf57a8a 100644 --- a/beem/cli.py +++ b/beem/cli.py @@ -9,7 +9,7 @@ import pytz import time import hashlib -import math +#import math currently unused module import random import logging import click diff --git a/beem/transactionbuilder.py b/beem/transactionbuilder.py index ca76a1b3..b6ceb846 100644 --- a/beem/transactionbuilder.py +++ b/beem/transactionbuilder.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import logging import struct -import time +#import time (not currently used) from datetime import timedelta from binascii import unhexlify from beemgraphenebase.py23 import bytes_types, integer_types, string_types, text_type @@ -11,7 +11,7 @@ from beemgraphenebase.account import PrivateKey, PublicKey from beembase.signedtransactions import Signed_Transaction from beembase.ledgertransactions import Ledger_Transaction -from beembase import transactions, operations +from beembase import operations #removed deprecated transactions module from .exceptions import ( InsufficientAuthorityError, MissingKeyError, diff --git a/beembase/operationids.py b/beembase/operationids.py index 6b3d023c..36ae82da 100644 --- a/beembase/operationids.py +++ b/beembase/operationids.py @@ -10,6 +10,7 @@ 'limit_order_cancel', 'feed_publish', 'convert', + 'collateralized_convert' 'account_create', 'account_update', 'witness_update', @@ -64,7 +65,6 @@ 'comment_payout_update', 'return_vesting_delegation', 'comment_benefactor_reward', - 'producer_reward', 'clear_null_account_balance', 'proposal_pay', 'sps_fund', diff --git a/beembase/operations.py b/beembase/operations.py index 126024a9..aca68bce 100644 --- a/beembase/operations.py +++ b/beembase/operations.py @@ -642,6 +642,24 @@ def __init__(self, *args, **kwargs): ('amount', Amount(kwargs["amount"], prefix=prefix, json_str=json_str)), ])) +#Operation added for HF25 for the new HBD/Hive conversion operation +class Collateralized_convert(GrapheneObject): + def __init__(self, *args, **kwargs): + 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) + super(Collateralized_convert, self).__init__( + OrderedDict([ + ('owner', String(kwargs["owner"])), + ('requestid', Uint32(kwargs["requestid"])), + ('amount', Amount(kwargs["amount"], prefix=prefix, json_str=json_str)), + + ])) + + class Set_withdraw_vesting_route(GrapheneObject): def __init__(self, *args, **kwargs): From 7551f6b08bcde7194986e1003fca5287b45de373 Mon Sep 17 00:00:00 2001 From: sicarius Date: Sun, 13 Jun 2021 00:28:21 -0500 Subject: [PATCH 4/6] added a method for the account class for the new convert op --- beem/account.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/beem/account.py b/beem/account.py index 7257827a..d6dfddb7 100644 --- a/beem/account.py +++ b/beem/account.py @@ -3000,6 +3000,38 @@ def convert(self, amount, account=None, request_id=None): return self.blockchain.finalizeOp(op, account, "active") + #Added to differentiate and match the addition of the HF25 convert operation + def collateralized_convert(self, amount, account=None, request_id=None, **kwargs): + """ Convert Hive dollars to Hive (this method is meant to be more instant) + and reflect the method added in HF25 + + :param float amount: amount of SBD to convert + :param str account: (optional) the source account for the transfer + if not ``default_account`` + :param str request_id: (optional) identifier for tracking the + conversion` + + """ + if account is None: + account = self + else: + account = Account(account, blockchain_instance=self.blockchain) + amount = self._check_amount(amount, self.blockchain.backed_token_symbol) + if request_id: + request_id = int(request_id) + else: + request_id = random.getrandbits(32) + op = operations.Collateralized_convert( + **{ + "owner": account["name"], + "requestid": request_id, + "amount": amount, + "prefix": self.blockchain.prefix, + "json_str": not bool(self.blockchain.config["use_condenser"]), + }) + + return self.blockchain.finalizeOp(op, account, "active", **kwargs) + def transfer_to_savings(self, amount, asset, memo, to=None, account=None, **kwargs): """ Transfer SBD or STEEM into a 'savings' account. From ad5f6e9421db615e986e62ca0d58a8a5e44887de Mon Sep 17 00:00:00 2001 From: sicarius97 Date: Fri, 18 Jun 2021 12:14:55 -0500 Subject: [PATCH 5/6] added recurring transfer op and added a method for it to account class --- beem/account.py | 63 ++++++++++++++++++++++++++++++++++++++++ beembase/operationids.py | 1 + beembase/operations.py | 29 ++++++++++++++++++ 3 files changed, 93 insertions(+) diff --git a/beem/account.py b/beem/account.py index d6dfddb7..912e46b8 100644 --- a/beem/account.py +++ b/beem/account.py @@ -2937,6 +2937,69 @@ def transfer(self, to, amount, asset, memo="", skip_account_check=False, account }) 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 36ae82da..4b4db9ad 100644 --- a/beembase/operationids.py +++ b/beembase/operationids.py @@ -4,6 +4,7 @@ 'vote', 'comment', 'transfer', + 'recurring_transfer', 'transfer_to_vesting', 'withdraw_vesting', 'limit_order_create', diff --git a/beembase/operations.py b/beembase/operations.py index aca68bce..25c1fca4 100644 --- a/beembase/operations.py +++ b/beembase/operations.py @@ -66,6 +66,35 @@ def __init__(self, *args, **kwargs): ('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): From 795e803caa75addf8c677f255f48f8a861c33490 Mon Sep 17 00:00:00 2001 From: sicarius97 Date: Fri, 18 Jun 2021 12:33:56 -0500 Subject: [PATCH 6/6] incremented version and noted changelog --- CHANGELOG.rst | 5 +++++ setup.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e591fbac..c8e648a0 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,5 +1,10 @@ Changelog ======== +0.24.23 +------- +* Fixed some small code issues +* Added reccurring_transfer op in preparation for HF25 (@sicarius) +* Added collateralized_convert op in preparation for HF25 (@sicarius) 0.24.22 ------- * Fix to parameter in transfer_to_vesting diff --git a/setup.py b/setup.py index 44402915..c37f4da6 100755 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ ascii = codecs.lookup('ascii') codecs.register(lambda name, enc=ascii: {True: enc}.get(name == 'mbcs')) -VERSION = '0.24.22' +VERSION = '0.24.23' tests_require = ['mock >= 2.0.0', 'pytest', 'pytest-mock', 'parameterized']