mirror of https://github.com/nucypher/nucypher.git
Create individual allocation file with beneficiary and contract address
parent
6b511c6157
commit
7141efd8e9
|
@ -421,15 +421,15 @@ class ContractAdministrator(NucypherTokenActor):
|
|||
|
||||
# Create an allocation template file, containing the allocation contract ABI and placeholder values
|
||||
# for the beneficiary and contract addresses. This file will be shared with all allocation users.
|
||||
empty_user_escrow_deployer = UserEscrowDeployer(registry=self.registry)
|
||||
allocation_contract_abi = empty_user_escrow_deployer.get_contract_abi()
|
||||
empty_allocation_escrow_deployer = PreallocationEscrowDeployer(registry=self.registry)
|
||||
allocation_contract_abi = empty_allocation_escrow_deployer.get_contract_abi()
|
||||
allocation_template = {
|
||||
"BENEFICIARY_ADDRESS": ["ALLOCATION_CONTRACT_ADDRESS", allocation_contract_abi]
|
||||
}
|
||||
|
||||
parent_path = Path(allocation_registry.filepath).parent # Use same folder as allocation registry
|
||||
template_filename = IndividualAllocationRegistry.REGISTRY_NAME
|
||||
template_parent_path = Path(allocation_registry.filepath).parent # Use same folder as allocation registry
|
||||
template_filepath = os.path.join(template_parent_path, template_filename)
|
||||
template_filepath = os.path.join(parent_path, template_filename)
|
||||
AllocationRegistry(filepath=template_filepath).write(registry_data=allocation_template)
|
||||
if emitter:
|
||||
emitter.echo(f"Saved allocation template file to {template_filepath}", color='blue', bold=True)
|
||||
|
@ -474,9 +474,20 @@ class ContractAdministrator(NucypherTokenActor):
|
|||
|
||||
else:
|
||||
allocation_receipts[beneficiary] = receipts
|
||||
principal_address = deployer.contract_address
|
||||
self.log.info(f"Created PreallocationEscrow contract at {principal_address} for beneficiary {beneficiary}.")
|
||||
allocated.append((allocation, principal_address))
|
||||
allocation_contract_address = deployer.contract_address
|
||||
self.log.info(f"Created {deployer.contract_name} contract at {allocation_contract_address} "
|
||||
f"for beneficiary {beneficiary}.")
|
||||
allocated.append((allocation, allocation_contract_address))
|
||||
|
||||
# Create individual allocation file
|
||||
individual_allocation_filename = f'allocation-{beneficiary}.json'
|
||||
individual_allocation_filepath = os.path.join(parent_path, individual_allocation_filename)
|
||||
individual_allocation_file_data = {
|
||||
'beneficiary_address': beneficiary,
|
||||
'contract_address': allocation_contract_address
|
||||
}
|
||||
with open(individual_allocation_filepath, 'w') as outfile:
|
||||
json.dump(individual_allocation_file_data, outfile)
|
||||
|
||||
if emitter:
|
||||
blockchain = BlockchainInterfaceFactory.get_interface()
|
||||
|
@ -486,12 +497,14 @@ class ContractAdministrator(NucypherTokenActor):
|
|||
emitter=emitter,
|
||||
chain_name=blockchain.client.chain_name,
|
||||
open_in_browser=False)
|
||||
emitter.echo(f"Saved individual allocation file to {individual_allocation_filepath}",
|
||||
color='blue', bold=True)
|
||||
|
||||
if emitter:
|
||||
paint_deployed_allocations(emitter, allocated, failed)
|
||||
|
||||
csv_filename = f'allocations-{self.deployer_address[:6]}-{maya.now().epoch}.csv'
|
||||
csv_filepath = os.path.join(template_parent_path, csv_filename)
|
||||
csv_filepath = os.path.join(parent_path, csv_filename)
|
||||
write_deployed_allocations_to_csv(csv_filepath, allocated, failed)
|
||||
if emitter:
|
||||
emitter.echo(f"Saved allocation summary CSV to {csv_filepath}", color='blue', bold=True)
|
||||
|
|
|
@ -265,8 +265,8 @@ class LocalContractRegistry(BaseContractRegistry):
|
|||
@classmethod
|
||||
def from_dict(cls, payload: dict, **overrides) -> 'LocalContractRegistry':
|
||||
payload.update({k: v for k, v in overrides.items() if v is not None})
|
||||
blockchain = cls(filepath=payload['filepath'])
|
||||
return blockchain
|
||||
registry = cls(filepath=payload['filepath'])
|
||||
return registry
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
payload = dict(filepath=self.__filepath)
|
||||
|
@ -384,6 +384,7 @@ class AllocationRegistry(LocalContractRegistry):
|
|||
|
||||
elif contract_address:
|
||||
records = list()
|
||||
# FIXME: Searching by contract_address seems broken. Also, no tests.
|
||||
for beneficiary_address, contract_data in allocation_data.items():
|
||||
contract_address, contract_abi = contract_data['address'], contract_data['abi']
|
||||
records.append(dict(address=contract_address, abi=contract_abi))
|
||||
|
@ -449,16 +450,26 @@ class IndividualAllocationRegistry(InMemoryAllocationRegistry):
|
|||
|
||||
REGISTRY_NAME = "individual_allocation_ABI.json"
|
||||
|
||||
def __init__(self, beneficiary_address: str, contract_address: str, *args, **kwargs):
|
||||
def __init__(self, beneficiary_address: str, contract_address: str, contract_abi=None, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.beneficiary_address = beneficiary_address
|
||||
self.contract_address = contract_address
|
||||
|
||||
# Download individual allocation template. Fill the template with beneficiary and contract addresses
|
||||
individual_allocation_template = json.loads(self.fetch_latest_publication())
|
||||
contract_data = [*individual_allocation_template.values()].pop()
|
||||
contract_abi = contract_data[1]
|
||||
individual_allocation = {beneficiary_address: [contract_address, contract_abi]}
|
||||
if not contract_abi:
|
||||
# Download individual allocation template to extract contract_abi
|
||||
individual_allocation_template = json.loads(self.fetch_latest_publication())
|
||||
contract_data = [*individual_allocation_template.values()].pop()
|
||||
contract_abi = contract_data[1]
|
||||
|
||||
# Fill template with beneficiary and contract addresses
|
||||
individual_allocation = {beneficiary_address: [contract_address, contract_abi]}
|
||||
self.write(registry_data=individual_allocation)
|
||||
|
||||
@classmethod
|
||||
def from_allocation_file(cls, filepath: str, **kwargs) -> 'IndividualAllocationRegistry':
|
||||
with open(filepath) as file:
|
||||
individual_allocation_file_data = json.load(file)
|
||||
|
||||
registry = cls(**individual_allocation_file_data, **kwargs)
|
||||
return registry
|
||||
|
|
Loading…
Reference in New Issue