def deploy_crowdsale(project: Project, chain, source_definitions: dict, deploy_address) -> Tuple[dict, dict, dict]: """Deploy multiple contracts from crowdsale definitions. :param chain: Populus chain object :param data: One of mainnet/ropsten parsed data definitions in a YAML file :return: Tuple (expaneded definitions, statistics, contract object map). The expanded definitions are run-time data that has everything expanded out and actual contract addresses """ statistics = Counter() # This will contain our output and parsed values runtime_data = copy.deepcopy(source_definitions) # Contract handles for post-actions contracts = {} # Store the address we used for the deployment runtime_data["deploy_address"] = deploy_address chain_name = runtime_data["chain"] verify_on_etherscan = asbool(runtime_data["verify_on_etherscan"]) browser_driver = runtime_data.get("browser_driver", "chrome") need_unlock = runtime_data.get("unlock_deploy_address", True) for name, contract_def in runtime_data["contracts"].items(): contract_name = contract_def["contract_name"] # First expand out all variables address = contract_def.get("address") if address: print("Already deployed contract,", name, address) Contract = getattr(chain.contract_factories, contract_name) contracts[name] = Contract(address=address) statistics["already_deployed"] += 1 continue # Expand Jinja templated variables for this contract context = get_jinja_context(runtime_data) try: expanded_contract_def = interpolate_data(contract_def, context) except jinja2.exceptions.TemplateError as e: raise RuntimeError( "Could not expand data for section {}".format(name)) from e # Store expanded data for output runtime_data["contracts"][name] = expanded_contract_def contracts[name] = deploy_contract(project, chain, deploy_address, expanded_contract_def, chain_name, need_unlock=need_unlock) statistics["deployed"] += 1 # Perform manual verification of the deployed contract if verify_on_etherscan: fname = runtime_data["contracts"][name]["contract_file"] src = verify_contract( project=project, chain_name=chain_name, address=runtime_data["contracts"][name]["address"], contract_name=contract_name, contract_filename=fname, constructor_args=runtime_data["contracts"][name] ["constructor_args"], libraries=runtime_data["contracts"][name]["libraries"], browser_driver=browser_driver) runtime_data["contracts"][name][ "etherscan_link"] = get_etherscan_link( chain_name, runtime_data["contracts"][name]["address"]) # Write out our expanded contract expanded_path = os.path.join(os.getcwd(), "build", "expanded", fname) with open(expanded_path, "wt") as out: out.write(src) return runtime_data, statistics, contracts
def deploy_crowdsale(project: Project, chain, yaml_filename: str, source_definitions: dict, deploy_address) -> Tuple[dict, dict, dict]: """Deploy multiple contracts from crowdsale definitions. :param chain: Populus chain object :param data: One of mainnet/ropsten parsed data definitions in a YAML file :return: Tuple (expaneded definitions, statistics, contract object map). The expanded definitions are run-time data that has everything expanded out and actual contract addresses """ statistics = Counter() # This will contain our output and parsed values runtime_data = copy.deepcopy(source_definitions) # Contract handles for post-actions contracts = {} # Store the address we used for the deployment runtime_data["deploy_address"] = deploy_address chain_name = runtime_data["chain"] verify_on_etherscan = asbool(runtime_data["verify_on_etherscan"]) browser_driver = runtime_data.get("browser_driver", "chrome") solc = runtime_data["solc"] need_unlock = runtime_data.get("unlock_deploy_address", True) for name, contract_def in runtime_data["contracts"].items(): contract_name = contract_def["contract_name"] # First expand out all variables address = contract_def.get("address") if address: print("Already deployed contract,", name, address) Contract = get_contract_by_name(chain, contract_name) contracts[name] = Contract(address=address) statistics["already_deployed"] += 1 continue # Expand Jinja templated variables for this contract context = get_jinja_context(runtime_data) try: expanded_contract_def = interpolate_data(contract_def, context) except jinja2.exceptions.TemplateError as e: raise RuntimeError("Could not expand data for section {}".format(name)) from e # Store expanded data for output runtime_data["contracts"][name] = expanded_contract_def contracts[name] = deploy_contract(project, chain, deploy_address, expanded_contract_def, chain_name, need_unlock=need_unlock) statistics["deployed"] += 1 # Perform manual verification of the deployed contract if verify_on_etherscan: fname = runtime_data["contracts"][name]["contract_file"] src = verify_contract( project=project, chain_name=chain_name, address=runtime_data["contracts"][name]["address"], contract_name=contract_name, contract_filename=fname, constructor_args=runtime_data["contracts"][name]["constructor_args"], libraries=runtime_data["contracts"][name]["libraries"], browser_driver=browser_driver, compiler=solc["version"], optimization=asbool(solc["optimizations"]["optimizer"]), optimizer_runs=int(solc["optimizations"]["runs"]) ) runtime_data["contracts"][name]["etherscan_link"] = get_etherscan_link(chain_name, runtime_data["contracts"][name]["address"]) # Write out our expanded contract expanded_path = os.path.join(os.getcwd(), "build", "expanded", fname) with open(expanded_path, "wt") as out: out.write(src) # Write the ongoing output, so we can use it e.g. to debug EtherScan verification write_deployment_report(yaml_filename, runtime_data, partial=True) return runtime_data, statistics, contracts