示例#1
0
 def __init__(self, web3, old_currency_network_address: str,
              new_currency_network_address: str):
     old_network_interface = get_contract_interface("CurrencyNetwork")
     self.old_network = web3.eth.contract(
         address=old_currency_network_address,
         abi=old_network_interface["abi"])
     new_network_interface = get_contract_interface(
         "CurrencyNetworkOwnable")
     self.new_network = web3.eth.contract(
         address=new_currency_network_address,
         abi=new_network_interface["abi"])
     self.users = set(self.old_network.functions.getUsers().call())
     click.secho(
         f"Found {len(self.users)} users in the old currency network",
         fg="blue")
示例#2
0
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,
        )
示例#3
0
def deploy_currency_network_proxy(
    *,
    web3,
    network_settings: NetworkSettings,
    exchange_address=None,
    authorized_addresses=None,
    beacon_address,
    owner_address,
    private_key: bytes = None,
    transaction_options: Dict = None,
):
    verify_owner_not_deployer(web3, owner_address, private_key)

    if transaction_options is None:
        transaction_options = {}

    proxy = deploy(
        "AdministrativeProxy",
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
        constructor_args=(beacon_address, ""),
    )
    increase_transaction_options_nonce(transaction_options)

    change_owner = proxy.functions.changeAdmin(owner_address)
    wait_for_successful_function_call(
        change_owner,
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )
    increase_transaction_options_nonce(transaction_options)
    assert proxy.functions.admin().call({"from":
                                         owner_address}) == owner_address

    interface = get_contract_interface("CurrencyNetwork")
    proxied_currency_network = web3.eth.contract(
        abi=interface["abi"],
        address=proxy.address,
        bytecode=interface["bytecode"])

    init_currency_network(
        web3=web3,
        network_settings=network_settings,
        currency_network=proxied_currency_network,
        exchange_address=exchange_address,
        authorized_addresses=authorized_addresses,
        transaction_options=transaction_options,
        private_key=private_key,
    )
    increase_transaction_options_nonce(transaction_options)

    return proxied_currency_network
示例#4
0
def remove_owner_of_network(*, web3, transaction_options, private_key,
                            currency_network_address: str):
    network_interface = get_contract_interface("CurrencyNetworkOwnable")
    network = web3.eth.contract(address=currency_network_address,
                                abi=network_interface["abi"])
    function_call = network.functions.removeOwner()

    wait_for_successful_function_call(
        function_call,
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )
示例#5
0
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")