Skip to content

Commit

Permalink
Merge pull request #310 from sicarius97/1-HF25-ops-addition
Browse files Browse the repository at this point in the history
hf25 ops addition
  • Loading branch information
holgern authored Jun 22, 2021
2 parents 19a85f2 + 795e803 commit 6a92c7b
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ target/
*.swp
.ropeproject/
*/.ropeproject/

# IDEs
.vscode
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
95 changes: 95 additions & 0 deletions beem/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -3000,6 +3063,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.
Expand Down
2 changes: 1 addition & 1 deletion beem/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pytz
import time
import hashlib
import math
#import math currently unused module
import random
import logging
import click
Expand Down
4 changes: 2 additions & 2 deletions beem/transactionbuilder.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion beembase/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']))
Expand Down
3 changes: 2 additions & 1 deletion beembase/operationids.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
'vote',
'comment',
'transfer',
'recurring_transfer',
'transfer_to_vesting',
'withdraw_vesting',
'limit_order_create',
'limit_order_cancel',
'feed_publish',
'convert',
'collateralized_convert'
'account_create',
'account_update',
'witness_update',
Expand Down Expand Up @@ -64,7 +66,6 @@
'comment_payout_update',
'return_vesting_delegation',
'comment_benefactor_reward',
'producer_reward',
'clear_null_account_balance',
'proposal_pay',
'sps_fund',
Expand Down
52 changes: 50 additions & 2 deletions beembase/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -402,8 +431,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__(
Expand Down Expand Up @@ -641,6 +671,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):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down

0 comments on commit 6a92c7b

Please sign in to comment.