Пример #1
0
def upgrade_smart_contract(args):
    logger.debug("upgrade_smart_contract")

    contract_address = args.contract
    project_directory = args.project
    pem_file = args.pem
    proxy_url = args.proxy
    arguments = args.arguments
    gas_price = args.gas_price
    gas_limit = args.gas_limit
    value = args.value
    metadata_upgradeable = args.metadata_upgradeable

    project = load_project(project_directory)
    bytecode = project.get_bytecode()
    metadata = CodeMetadata(metadata_upgradeable)
    contract = SmartContract(contract_address,
                             bytecode=bytecode,
                             metadata=metadata)
    environment = TestnetEnvironment(proxy_url)
    caller = Account(pem_file=pem_file)

    def flow():
        tx_hash = environment.upgrade_contract(contract, caller, arguments,
                                               gas_price, gas_limit, value)
        logger.info("Tx hash: %s", tx_hash)

    environment.run_flow(flow)
Пример #2
0
def deploy_smart_contract(args):
    logger.debug("deploy_smart_contract")

    project_directory = args.project
    pem_file = args.pem
    proxy_url = args.proxy
    arguments = args.arguments
    gas_price = args.gas_price
    gas_limit = args.gas_limit
    value = args.value
    metadata_upgradeable = args.metadata_upgradeable

    # TODO: apply guards

    project = load_project(project_directory)
    bytecode = project.get_bytecode()
    metadata = CodeMetadata(metadata_upgradeable)
    contract = SmartContract(bytecode=bytecode, metadata=metadata)
    environment = TestnetEnvironment(proxy_url)
    owner = Account(pem_file=pem_file)

    def flow():
        tx_hash, address = environment.deploy_contract(contract, owner,
                                                       arguments, gas_price,
                                                       gas_limit, value)
        logger.info("Tx hash: %s", tx_hash)
        logger.info("Contract address: %s", address)
        utils.dump_out_json({
            "tx": tx_hash,
            "contract": address.bech32()
        }, args.outfile)

    environment.run_flow(flow)
Пример #3
0
def _prepare_contract(args: Any) -> SmartContract:
    if args.bytecode:
        bytecode = utils.read_file(args.bytecode, binary=True).hex()
    else:
        project = load_project(args.project)
        bytecode = project.get_bytecode()

    metadata = CodeMetadata(args.metadata_upgradeable, args.metadata_payable)
    contract = SmartContract(bytecode=bytecode, metadata=metadata)
    return contract
Пример #4
0
    def _estimate_sc_deploy(self, contract_path):
        if contract_path is None:
            logger.fatal("contract-path argument missing")
            return

        project = load_project(contract_path)
        bytecode = project.get_bytecode()
        base64_bytecode = base64.b64encode(bytecode.encode())

        sender = self._SENDER_ADDRESS
        receiver = self._RECEIVER_ADDRESS
        estimate = self._send_transaction(sender, receiver,
                                          base64_bytecode.decode())
        return estimate
Пример #5
0
 def load_project(self, name):
     return projects.load_project(self.testdata.joinpath(name))