Cleanup blockchain policy function signatures

pull/452/head
Kieran Prasch 2018-09-24 22:27:01 -07:00
parent dadb49c4ce
commit 60180f8b2b
2 changed files with 21 additions and 23 deletions

View File

@ -130,8 +130,11 @@ class Miner(NucypherTokenActor):
return approve_txhash, deposit_txhash
@only_me
def divide_stake(self, stake_index: int, target_value: int,
additional_periods: int = None, expiration: maya.MayaDT = None) -> dict:
def divide_stake(self,
stake_index: int,
target_value: int,
additional_periods: int = None,
expiration: maya.MayaDT = None) -> dict:
"""
Modifies the unlocking schedule and value of already locked tokens.
@ -262,7 +265,7 @@ class Miner(NucypherTokenActor):
class PolicyAuthor(NucypherTokenActor):
"""Alice base class for blockchain operations, mocking up new policies!"""
def __init__(self, checksum_address: str, policy_agent: PolicyAgent = None) -> None:
def __init__(self, checksum_address: str, policy_agent: PolicyAgent = None, *args, **kwargs) -> None:
"""
:param policy_agent: A policy agent with the blockchain attached; If not passed, A default policy
agent and blockchain connection will be created from default values.
@ -280,7 +283,8 @@ class PolicyAuthor(NucypherTokenActor):
self.miner_agent = policy_agent.miner_agent
super().__init__(token_agent=self.policy_agent.token_agent,
checksum_address=checksum_address)
checksum_address=checksum_address,
*args, **kwargs)
def recruit(self, quantity: int, **options) -> List[str]:
"""
@ -288,7 +292,6 @@ class PolicyAuthor(NucypherTokenActor):
caches the resulting node ethereum addresses.
:param quantity: Number of ursulas to sample from the blockchain.
:return: None; Since it only mutates self
"""

View File

@ -233,19 +233,20 @@ class PolicyAgent(EthereumContractAgent):
principal_contract_name = "PolicyManager"
_upgradeable = True
__instance = None
__instance = NO_CONTRACT_AVAILABLE
def __init__(self,
miner_agent: MinerAgent = None,
registry_filepath=None,
*args, **kwargs) -> None:
miner_agent = miner_agent if miner_agent is not None else MinerAgent(registry_filepath=registry_filepath)
super().__init__(blockchain=miner_agent.blockchain, registry_filepath=registry_filepath, *args, **kwargs)
def __init__(self, miner_agent: MinerAgent, *args, **kwargs) -> None:
super().__init__(blockchain=miner_agent.blockchain, *args, **kwargs)
self.miner_agent = miner_agent
self.token_agent = miner_agent.token_agent
def create_policy(self, policy_id: str, author_address: str, value: int,
periods: int, reward: int, node_addresses: List[str]):
def create_policy(self,
policy_id: str,
author_address: str,
value: int,
periods: int,
reward: int,
node_addresses: List[str]) -> str:
txhash = self.contract.functions.createPolicy(policy_id,
periods,
@ -260,15 +261,9 @@ class PolicyAgent(EthereumContractAgent):
blockchain_record = self.contract.functions.policies(policy_id).call()
return blockchain_record
def revoke_policy(self, policy_id: bytes, author) -> str:
"""
Revoke by arrangement ID; Only the policy's author can revoke the policy.
:param policy_id: An existing arrangementID to revoke on the blockchain.
"""
txhash = self.contract.functions.revokePolicy(policy_id).transact({'from': author.address})
def revoke_policy(self, policy_id: bytes, author_address) -> str:
"""Revoke by arrangement ID; Only the policy's author_address can revoke the policy."""
txhash = self.contract.functions.revokePolicy(policy_id).transact({'from': author_address.address})
self.blockchain.wait_for_receipt(txhash)
return txhash