def deploy_and_migrate_networks_from_file( *, web3, beacon_address: str, owner_address: str, addresses_file_path: str, private_key: bytes = None, transaction_options: Dict = None, ): """Deploy new owned currency network proxies and migrate old networks to it""" if transaction_options is None: transaction_options = {} verify_owner_not_deployer(web3, owner_address, private_key) currency_network_interface = get_contract_interface("CurrencyNetwork") for old_address in read_addresses_in_csv(addresses_file_path): old_network = web3.eth.contract(abi=currency_network_interface["abi"], address=old_address) deploy_and_migrate_network( web3=web3, beacon_address=beacon_address, owner_address=owner_address, old_network=old_network, private_key=private_key, transaction_options=transaction_options, )
def read_addresses_to_migrate(old_addresses_file_path, new_addresses_file_path): if not os.path.isfile(old_addresses_file_path): raise ValueError( f"Old addresses file not found at {old_addresses_file_path}") if not os.path.isfile(new_addresses_file_path): raise ValueError( f"New addresses file not found at {new_addresses_file_path}") old_currency_network_addresses = read_addresses_in_csv( old_addresses_file_path) new_currency_network_addresses = read_addresses_in_csv( new_addresses_file_path) if len(old_currency_network_addresses) != len( new_currency_network_addresses): raise ValueError( f"The number of old and new addresses do not match: " f"{len(old_currency_network_addresses)} old and {len(new_currency_network_addresses)} new" ) return zip(old_currency_network_addresses, new_currency_network_addresses)
def check_whitelist(whitelist_file: str, auction_address: str, jsonrpc: str) -> None: web3 = connect_to_json_rpc(jsonrpc) whitelist = read_addresses_in_csv(whitelist_file) contracts = get_deployed_auction_contracts(web3, auction_address) number_of_missing_addresses = len( missing_whitelisted_addresses(contracts.auction, whitelist)) if number_of_missing_addresses == 0: click.echo(f"All {len(whitelist)} addresses have been whitelisted") else: click.echo( f"{number_of_missing_addresses} of {len(whitelist)} addresses have not been whitelisted yet" )
def whitelist( whitelist_file: str, auction_address: str, batch_size: int, keystore: str, jsonrpc: str, gas: int, gas_price: int, nonce: int, auto_nonce: bool, ) -> None: web3 = connect_to_json_rpc(jsonrpc) whitelist = read_addresses_in_csv(whitelist_file) private_key = retrieve_private_key(keystore) nonce = get_nonce(web3=web3, nonce=nonce, auto_nonce=auto_nonce, private_key=private_key) transaction_options = build_transaction_options(gas=gas, gas_price=gas_price, nonce=nonce) contracts = get_deployed_auction_contracts(web3, auction_address) number_of_whitelisted_addresses = whitelist_addresses( contracts.auction, whitelist, batch_size=batch_size, web3=web3, transaction_options=transaction_options, private_key=private_key, ) click.echo("Number of whitelisted addresses: " + str(number_of_whitelisted_addresses))
def deploy_and_migrate_networks_from_file( *, web3, beacon_address: str, owner_address: str, addresses_file_path: str, private_key: bytes = None, transaction_options: Dict = None, output_file_path: str, ): """Deploy new owned currency network proxies and migrate old networks to it""" if transaction_options is None: transaction_options = {} verify_owner_not_deployer(web3, owner_address, private_key) currency_network_interface = get_contract_interface("CurrencyNetwork") network_addresses_mapping = {} for old_address in read_addresses_in_csv(addresses_file_path): old_network = web3.eth.contract(abi=currency_network_interface["abi"], address=old_address) new_network = deploy_and_migrate_network( web3=web3, beacon_address=beacon_address, owner_address=owner_address, old_network=old_network, private_key=private_key, transaction_options=transaction_options, ) network_addresses_mapping[old_network.address] = new_network.address with open(output_file_path, "w") as file: json.dump(network_addresses_mapping, file) click.secho("Wrote mapping {old_address: new_address} to " + output_file_path, fg="blue")
def test_read_incorrect_addresses_in_csv(incorrect_list_csv_path): with pytest.raises(InvalidAddressException): read_addresses_in_csv(incorrect_list_csv_path)
def test_read_addresses_in_csv(address_list_csv_path, address_list): addresses = read_addresses_in_csv(address_list_csv_path) assert addresses == address_list