Skip to content

Commit 867c2cd

Browse files
authored
Method for delegating capital (#20)
1 parent d37645c commit 867c2cd

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

viz/viz.py

+36-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Any, DefaultDict, Dict, List, Optional, Union
55

66
from graphenecommon.chain import AbstractGrapheneChain
7-
from graphenecommon.exceptions import KeyAlreadyInStoreException
7+
from graphenecommon.exceptions import KeyAlreadyInStoreException,AccountDoesNotExistsException
88

99
from vizapi.noderpc import NodeRPC
1010
from vizbase import operations
@@ -689,7 +689,7 @@ def update_account_profile(
689689
:raises AccountDoesNotExistsException: if the account does not exist
690690
"""
691691

692-
# check if account already exists
692+
# check if the account does not exist
693693
try:
694694
Account(account_name, blockchain_instance=self)
695695
except Exception:
@@ -704,6 +704,40 @@ def update_account_profile(
704704
op = operations.Account_update(**op)
705705

706706
return self.finalizeOp(ops=op, account=account_name, permission="active")
707+
708+
def delegate_vesting_shares(
709+
self,
710+
delegator: str,
711+
delegatee: str,
712+
amount: float
713+
) -> dict:
714+
"""
715+
Delegate vesting SHARES to account.
716+
717+
:param str delegator: account that delegates
718+
:param str delegatee: account to which is delegated
719+
:param float amount: number of SHARES to be delegated
720+
"""
721+
722+
# check if the account does not exist
723+
try:
724+
Account(delegatee, blockchain_instance=self)
725+
except Exception:
726+
raise AccountDoesNotExistsException
727+
728+
op = {
729+
"delegator": delegator,
730+
"delegatee": delegatee,
731+
"vesting_shares": "{:.{prec}f} {asset}".format(
732+
float(amount),
733+
prec=PRECISIONS.get(self.rpc.chain_params["shares_symbol"]),
734+
asset=self.rpc.chain_params["shares_symbol"],
735+
),
736+
}
737+
738+
op = operations.Delegate_vesting_shares(**op)
739+
740+
return self.finalizeOp(op, delegator, "active")
707741

708742
def _store_keys(self, *args):
709743
"""Store private keys to local storage."""
@@ -714,7 +748,6 @@ def _store_keys(self, *args):
714748
pass
715749

716750
# TODO: Methods to implement:
717-
# - delegate_vesting_shares
718751
# - witness_update
719752
# - chain_properties_update
720753
# - allow / disallow

0 commit comments

Comments
 (0)