From 9f4c9609635d99e33a8506e6f62f6a03ce308264 Mon Sep 17 00:00:00 2001 From: Kieran Prasch Date: Fri, 6 Apr 2018 17:14:34 -0700 Subject: [PATCH] [KMS-ETH]- Publish arrangement method --- nkms_eth/policies.py | 28 ++++++++++++++++++++++++++++ nkms_eth/utilities.py | 1 + 2 files changed, 29 insertions(+) diff --git a/nkms_eth/policies.py b/nkms_eth/policies.py index 6e7028892..222428a3d 100644 --- a/nkms_eth/policies.py +++ b/nkms_eth/policies.py @@ -63,3 +63,31 @@ class BlockchainPolicy: def __init__(self): self._arrangements = list() + + def publish_arrangement(self, miner, periods: int, rate: int, arrangement_id: bytes=None) -> 'BlockchainArrangement': + """ + Create a new arrangement to carry out a blockchain policy for the specified rate and time. + """ + + value = rate * periods + arrangement = BlockchainArrangement(author=self, + miner=miner, + value=value, + periods=periods) + + self._arrangements[arrangement.id] = {arrangement_id: arrangement} + return arrangement + + def get_arrangement(self, arrangement_id: bytes) -> BlockchainArrangement: + """Fetch a published arrangement from the blockchain""" + + blockchain_record = self.policy_agent.read().policies(arrangement_id) + author_address, miner_address, rate, start_block, end_block, downtime_index = blockchain_record + + duration = end_block - start_block + + miner = Miner(address=miner_address, miner_agent=self.policy_agent.miner_agent) + arrangement = BlockchainArrangement(author=self, miner=miner, periods=duration) + + arrangement.is_published = True + return arrangement diff --git a/nkms_eth/utilities.py b/nkms_eth/utilities.py index fa6ae8d8e..52870c887 100644 --- a/nkms_eth/utilities.py +++ b/nkms_eth/utilities.py @@ -9,6 +9,7 @@ from nkms_eth.deployers import MinerEscrowDeployer, NuCypherKMSTokenDeployer class TesterBlockchain(TheBlockchain): """Transient, in-memory, local, private chain""" + _network = 'tester' def wait_time(self, wait_hours, step=50):