mirror of https://github.com/nucypher/nucypher.git
Dehydrate contract names; code style fixes.
parent
6807ac0bfc
commit
cf5bef9e0d
|
@ -3,7 +3,6 @@ from abc import ABC
|
|||
from typing import Generator, List, Tuple, Union
|
||||
|
||||
from constant_sorrow import constants
|
||||
from web3.contract import Contract
|
||||
|
||||
from nucypher.blockchain.eth import constants
|
||||
from nucypher.blockchain.eth.chains import Blockchain
|
||||
|
@ -16,7 +15,7 @@ class EthereumContractAgent(ABC):
|
|||
|
||||
_upgradeable = NotImplemented
|
||||
|
||||
_principal_contract_name = NotImplemented
|
||||
principal_contract_name = NotImplemented
|
||||
__contract_address = NotImplemented
|
||||
|
||||
class ContractNotDeployed(Exception):
|
||||
|
@ -29,16 +28,16 @@ class EthereumContractAgent(ABC):
|
|||
self.blockchain = blockchain
|
||||
|
||||
# Fetch the contract by reading address and abo from the registry and blockchain
|
||||
contract = self.blockchain.interface.get_contract_by_name(name=self._principal_contract_name,
|
||||
contract = self.blockchain.interface.get_contract_by_name(name=self.principal_contract_name,
|
||||
upgradeable=self._upgradeable)
|
||||
self.__contract = contract
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
super().__init__()
|
||||
|
||||
def __repr__(self):
|
||||
class_name = self.__class__.__name__
|
||||
r = "{}(blockchain={}, contract={})"
|
||||
return r.format(class_name, self.blockchain, self._principal_contract_name)
|
||||
return r.format(class_name, self.blockchain, self.principal_contract_name)
|
||||
|
||||
def __eq__(self, other):
|
||||
return bool(self.contract_address == other.contract_address)
|
||||
|
@ -53,7 +52,7 @@ class EthereumContractAgent(ABC):
|
|||
|
||||
@property
|
||||
def contract_name(self) -> str:
|
||||
return self._principal_contract_name
|
||||
return self.principal_contract_name
|
||||
|
||||
def get_balance(self, address: str=None) -> int:
|
||||
"""Get the balance of a token address, or of this contract address"""
|
||||
|
@ -62,7 +61,7 @@ class EthereumContractAgent(ABC):
|
|||
|
||||
|
||||
class NucypherTokenAgent(EthereumContractAgent):
|
||||
_principal_contract_name = "NuCypherToken"
|
||||
principal_contract_name = "NuCypherToken"
|
||||
_upgradeable = False
|
||||
|
||||
def approve_transfer(self, amount: int, target_address: str, sender_address: str) -> str:
|
||||
|
@ -82,7 +81,7 @@ class MinerAgent(EthereumContractAgent):
|
|||
for a duration measured in periods.
|
||||
"""
|
||||
|
||||
_principal_contract_name = "MinersEscrow"
|
||||
principal_contract_name = "MinersEscrow"
|
||||
_upgradeable = True
|
||||
|
||||
class NotEnoughMiners(Exception):
|
||||
|
@ -217,7 +216,7 @@ class MinerAgent(EthereumContractAgent):
|
|||
|
||||
class PolicyAgent(EthereumContractAgent):
|
||||
|
||||
_principal_contract_name = "PolicyManager"
|
||||
principal_contract_name = "PolicyManager"
|
||||
_upgradeable = True
|
||||
|
||||
def __init__(self, miner_agent: MinerAgent, *args, **kwargs):
|
||||
|
|
|
@ -5,18 +5,17 @@ These values are static and do not need to be changed during runtime;
|
|||
Once the NuCypherToken contract is deployed to a network with one set of constant values,
|
||||
those values are then required to be compatible with the rest of the network.
|
||||
"""
|
||||
import math
|
||||
|
||||
import maya
|
||||
from constant_sorrow.constants import (NULL_ADDRESS, TOKEN_SATURATION, MINING_COEFFICIENT, TOKEN_SUPPLY,
|
||||
M, HOURS_PER_PERIOD, MIN_LOCKED_PERIODS, MAX_MINTING_PERIODS,
|
||||
MIN_ALLOWED_LOCKED, MAX_ALLOWED_LOCKED, SECONDS_PER_PERIOD, )
|
||||
MIN_ALLOWED_LOCKED, MAX_ALLOWED_LOCKED, SECONDS_PER_PERIOD,
|
||||
POLICY_ID_LENGTH, )
|
||||
|
||||
|
||||
#
|
||||
# Token
|
||||
#
|
||||
from nucypher.blockchain.eth.chains import Blockchain
|
||||
|
||||
|
||||
class TokenConfigError(ValueError):
|
||||
|
@ -64,6 +63,18 @@ __mining_coeff = ( # TODO: label
|
|||
MINING_COEFFICIENT(__mining_coeff)
|
||||
|
||||
|
||||
#
|
||||
# Policy
|
||||
#
|
||||
|
||||
|
||||
class PolicyConfigError(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
POLICY_ID_LENGTH(16)
|
||||
|
||||
|
||||
def __validate(rulebook) -> bool:
|
||||
for rule, failure_message in rulebook:
|
||||
if not rule:
|
||||
|
|
|
@ -162,7 +162,7 @@ class ContractDeployer:
|
|||
class NucypherTokenDeployer(ContractDeployer):
|
||||
|
||||
agency = NucypherTokenAgent
|
||||
_contract_name = agency.contract_name # TODO
|
||||
_contract_name = agency.principal_contract_name # TODO
|
||||
|
||||
def __init__(self, blockchain, deployer_address):
|
||||
if not type(blockchain.interface) is self._interface_class:
|
||||
|
@ -199,15 +199,14 @@ class DispatcherDeployer(ContractDeployer):
|
|||
|
||||
_contract_name = 'Dispatcher'
|
||||
|
||||
def __init__(self, token_agent, target_contract, *args, **kwargs):
|
||||
self.token_agent = token_agent
|
||||
def __init__(self, target_contract, *args, **kwargs):
|
||||
self.target_contract = target_contract
|
||||
super().__init__(blockchain=token_agent.blockchain, *args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def deploy(self) -> str:
|
||||
|
||||
dispatcher_contract, txhash = self.blockchain.interface.deploy_contract(
|
||||
'Dispatcher', self.target_contract.address)
|
||||
dispatcher_contract, txhash = self.blockchain.interface.deploy_contract('Dispatcher',
|
||||
self.target_contract.address)
|
||||
|
||||
self._contract = dispatcher_contract
|
||||
return txhash
|
||||
|
@ -219,7 +218,7 @@ class MinerEscrowDeployer(ContractDeployer):
|
|||
"""
|
||||
|
||||
agency = MinerAgent
|
||||
_contract_name = 'MinersEscrow'
|
||||
_contract_name = agency.principal_contract_name
|
||||
|
||||
def __init__(self, token_agent, *args, **kwargs):
|
||||
super().__init__(blockchain=token_agent.blockchain, *args, **kwargs)
|
||||
|
@ -261,7 +260,7 @@ class MinerEscrowDeployer(ContractDeployer):
|
|||
*map(int, constants.MINING_COEFFICIENT))
|
||||
|
||||
# 2 - Deploy the dispatcher used for updating this contract #
|
||||
dispatcher_deployer = DispatcherDeployer(token_agent=self.token_agent,
|
||||
dispatcher_deployer = DispatcherDeployer(blockchain=self.token_agent.blockchain,
|
||||
target_contract=the_escrow_contract,
|
||||
deployer_address=self.deployer_address)
|
||||
|
||||
|
@ -312,7 +311,7 @@ class PolicyManagerDeployer(ContractDeployer):
|
|||
"""
|
||||
|
||||
agency = PolicyAgent
|
||||
_contract_name = 'PolicyManager'
|
||||
_contract_name = agency.principal_contract_name
|
||||
|
||||
def make_agent(self) -> EthereumContractAgent:
|
||||
agent = self.agency(miner_agent=self.miner_agent, contract=self._contract)
|
||||
|
@ -331,7 +330,7 @@ class PolicyManagerDeployer(ContractDeployer):
|
|||
the_policy_manager_contract, deploy_txhash = self.blockchain.interface.deploy_contract(
|
||||
self._contract_name, self.miner_agent.contract_address)
|
||||
|
||||
dispatcher_deployer = DispatcherDeployer(token_agent=self.token_agent,
|
||||
dispatcher_deployer = DispatcherDeployer(blockchain=self.token_agent.blockchain,
|
||||
target_contract=the_policy_manager_contract,
|
||||
deployer_address=self.deployer_address)
|
||||
|
||||
|
|
Loading…
Reference in New Issue