Add helper function to AllocationRegistry to check if beneficiary is in

pull/1327/head
David Núñez 2019-09-17 21:28:32 +02:00
parent 78b0c579dd
commit 58b4b5512c
1 changed files with 13 additions and 2 deletions

View File

@ -30,6 +30,7 @@ from twisted.logger import Logger
from web3.contract import Contract
from nucypher.config.constants import DEFAULT_CONFIG_ROOT
from nucypher.blockchain.eth.constants import USER_ESCROW_CONTRACT_NAME
class BaseContractRegistry(ABC):
@ -341,9 +342,11 @@ class InMemoryContractRegistry(BaseContractRegistry):
class AllocationRegistry(LocalContractRegistry):
_multi_contract = False
_contract_name = 'UserEscrow'
_contract_name = USER_ESCROW_CONTRACT_NAME
_default_registry_filepath = os.path.join(DEFAULT_CONFIG_ROOT, 'allocation_registry.json')
REGISTRY_NAME = 'allocation_registry.json'
_default_registry_filepath = os.path.join(DEFAULT_CONFIG_ROOT, REGISTRY_NAME)
class NoAllocationRegistry(BaseContractRegistry.NoRegistry):
pass
@ -385,6 +388,14 @@ class AllocationRegistry(LocalContractRegistry):
return contract_data
def is_beneficiary_enrolled(self, beneficiary_address: str) -> bool:
try:
_ = self.search(beneficiary_address=beneficiary_address)
return True
except self.UnknownBeneficiary:
return False
# TODO: Tests!
def enroll(self, beneficiary_address, contract_address, contract_abi) -> None:
contract_data = [contract_address, contract_abi]
try: