Skip to content
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.

Commit

Permalink
chore: legacy management between tx v2 and v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Moustikitos committed Jul 2, 2022
1 parent 11ffd91 commit 90ff1af
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 40 deletions.
5 changes: 3 additions & 2 deletions dposlib/ark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def _load_builders():
"registerMultiSignature", "registerIpfs", "multiPayment",
"delegateResignation", "htlcSecret", "htlcLock", "htlcClaim",
"htlcRefund",
"legacyTransfer", "legacyVote"
"legacyTransfer", "legacyVote",
# ark specific transaction builder [implemented]
"entityRegister", "entityUpdate", "entityResign",
# solar specific transaction builder names [implemented]
Expand All @@ -183,7 +183,8 @@ def _load_builders():
except NotImplementedError:
pass
else:
__all__.append(func)
if func not in __all__:
__all__.append(func)


def _write_module(path, configuration={}, fees={}):
Expand Down
3 changes: 3 additions & 0 deletions dposlib/ark/builders/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def transfer(amount, address, vendorField=None, expiration=0):
)


legacyTransfer = transfer


def registerSecondSecret(secondSecret):
"""
Build a second secret registration transaction.
Expand Down
57 changes: 19 additions & 38 deletions dposlib/ark/builders/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,6 @@
}


def legacyTransfer(amount, address, vendorField=None, expiration=0):
"""
Build a transfer transaction. Emoji can be included in transaction
vendorField using unicode formating.
```python
>>> vendorField = u"message with sparkles \u2728"
```
Args:
amount (float): transaction amount in ark.
address (str): valid recipient address.
vendorField (str): vendor field message.
expiration (float): time of persistance in hour.
Returns:
dposlib.ark.tx.Transaction: orphan transaction.
"""
if cfg.txversion > 1 and expiration > 0:
block_remaining = expiration*60*60//rest.cfg.blocktime
expiration = int(
rest.GET.api.blockchain()
.get("data", {}).get("block", {}).get("height", -block_remaining) +
block_remaining
)

return Transaction(
type=0,
amount=amount*100000000,
recipientId=address,
vendorField=vendorField,
version=cfg.txversion,
expiration=None if cfg.txversion < 2 else expiration
)


def upVote(*usernames, **weights):
"""
Build an upvote transaction.
Expand All @@ -85,7 +49,7 @@ def upVote(*usernames, **weights):
assert xor(len(usernames), len(weights)), \
"give username list or a vote weight mapping"

remind = 10000 # 100.0 * 10
remind = 10000 # 100.0 * 10 to be distributed
votes = {}

if len(weights):
Expand Down Expand Up @@ -124,6 +88,23 @@ def upVote(*usernames, **weights):
)


def legacyVote(*usernames):
"""
Build an upvote transaction.
Args:
usernames (iterable): delegate usernames as str iterable.
Returns:
dposlib.ark.tx.Transaction: orphan transaction.
"""
return Transaction(
type=3,
version=cfg.txversion,
asset={
"votes": ["+" + username for username in usernames]
},
)


def downVote(*usernames):
raise NotImplementedError(
"downVote is not implemented for v3 transactions"
Expand Down Expand Up @@ -173,7 +154,7 @@ def transfer(*pairs, **kwargs):
)


multiPayment = multiTransfer = transfer
multiTransfer = transfer


def htlcSecret(secret, hash_type=0):
Expand Down

0 comments on commit 90ff1af

Please sign in to comment.