github.com/platonnetwork/platon-go@v0.7.6/cases/tests/lib/delegate.py (about) 1 from environment.env import TestEnvironment 2 from environment.node import Node 3 from .economic import Economic 4 5 6 class Delegate: 7 """ 8 Used to initiate a delegate transaction, 9 if you need to use the call method, please call ppos 10 example: 11 >>>delegate=Delegate(env, node) 12 >>>delegate.ppos.getDelegateInfo(...) 13 """ 14 15 def __init__(self, env: TestEnvironment, node: Node): 16 self.node = node 17 self.economic = Economic(env) 18 19 @property 20 def ppos(self): 21 """ 22 use sdk ppos object 23 :return: 24 """ 25 return self.node.ppos 26 27 def delegate(self, typ, from_address, node_id=None, amount=None, tansaction_cfg=None): 28 """ 29 Initiate delegate 30 :param typ: Amount type 31 :param from_address: Initiating a delegate account 32 :param node_id: The id of the delegate node 33 :param amount: delegate amount 34 :param tansaction_cfg: 35 :return: 36 """ 37 if node_id is None: 38 node_id = self.node.node_id 39 if amount is None: 40 amount = self.economic.delegate_limit 41 pri_key = self.economic.account.find_pri_key(from_address) 42 return self.ppos.delegate(typ, node_id, amount, pri_key, transaction_cfg=tansaction_cfg) 43 44 def withdrew_delegate(self, staking_blocknum, from_address, node_id=None, amount=None, transaction_cfg=None): 45 """ 46 Release delegate 47 :param staking_blocknum: staking block height 48 :param from_address: Initiating a delegate account 49 :param node_id: The id of the delegate node 50 :param amount: Release delegate amount 51 :param transaction_cfg: 52 :return: 53 """ 54 if node_id is None: 55 node_id = self.node.node_id 56 if amount is None: 57 amount = self.economic.delegate_limit 58 pri_key = self.economic.account.find_pri_key(from_address) 59 return self.ppos.withdrewDelegate(staking_blocknum, node_id, amount, pri_key, transaction_cfg) 60 61 def withdraw_delegate_reward(self, from_address, transaction_cfg=None): 62 pri_key = self.economic.account.find_pri_key(from_address) 63 return self.ppos.withdrawDelegateReward(pri_key, transaction_cfg)