PolicyManager contract API methods on its agent. update on BlockchainArrangement

pull/330/head
Kieran Prasch 2018-06-11 10:51:08 -07:00
parent 0528d14708
commit ba2089a606
2 changed files with 52 additions and 10 deletions

View File

@ -272,15 +272,57 @@ class PolicyAgent(EthereumContractAgent):
self.miner_agent = miner_agent
self.token_agent = miner_agent.token_agent
def fetch_arrangement_data(self, arrangement_id: bytes) -> list:
blockchain_record = self.contract.functions.policies(arrangement_id).call()
return blockchain_record
def create_policy(self, policy_id: str, author_address: str, value: int,
periods: int, reward: int, node_addresses: List[str]):
def revoke_arrangement(self, arrangement_id: bytes, author):
"""
Revoke by arrangement ID; Only the policy author can revoke the policy
"""
txhash = self.contract.functions.revokePolicy(arrangement_id).transact({'from': author.address})
txhash = self.contract.functions.createPolicy(policy_id,
periods,
reward,
node_addresses).transact({'from': author_address,
'value': value})
self.blockchain.wait_for_receipt(txhash)
return txhash
def fetch_policy(self, policy_id: str) -> list:
"""Fetch raw stored blockchain data regarding the policy with the given policy ID"""
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})
self.blockchain.wait_for_receipt(txhash)
return txhash
def collect_policy_reward(self, collector_address: str):
"""Collect rewarded ETH"""
policy_reward_txhash = self.contract.functions.withdraw().transact({'from': collector_address})
self.blockchain.wait_for_receipt(policy_reward_txhash)
return policy_reward_txhash
def fetch_policy_arrangements(self, policy_id):
records = self.contract.functions.getArrangementsLength(policy_id).call()
for records in range(records):
arrangement = self.contract.functions.getArrangementInfo(policy_id, 0).call()[records]
yield arrangement
def revoke_arrangement(self, policy_id: str, node_address: str):
txhash = self.contract.functions.revokeArrangement(policy_id, node_address)
self.blockchain.wait_for_receipt(txhash)
return txhash
def calculate_refund(self, policy_id: str, author_address: str) -> str:
txhash = self.contract.functions.calculateRefundValue(policy_id).transact({'from': author_address})
self.blockchain.wait_for_receipt(txhash)
return txhash
def collect_refund(self, policy_id: str, author_address: str) -> str:
txhash = self.contract.functions.refund(policy_id).transact({'from': author_address})
self.blockchain.wait_for_receipt(txhash)
return txhash

View File

@ -64,7 +64,7 @@ class BlockchainArrangement(Arrangement):
def revoke(self) -> str:
"""Revoke this arrangement and return the transaction hash as hex."""
txhash = self.policy_agent.revoke_arrangement(self.id, author=self.author)
txhash = self.policy_agent.revoke_policy(self.id, author=self.author)
self.revoke_transaction = txhash
self.is_revoked = True
return txhash