예제 #1
0
def contract_deploy(contract_file, gas):
    try:
        with open(contract_file) as fp:
            contract = Contract(fp.read(),
                                Contract.SOPHIA,
                                client=_epoch_cli())
            kp, _ = _keypair()
            address, tx = contract.tx_create(kp, gas=gas)
            _pp([
                ("Contract address", address),
                ("Transaction hash", tx.tx_hash),
            ])
    except Exception as e:
        print(e)
예제 #2
0
def contract_deploy(contract_file, gas):
    """
    Deploy a contract to the chain and create a deploy descriptor
    with the contract informations that can be use to invoke the contract
    later on.

    The generated descriptor will be created in the same folde of the contract
    source file. Multiple deploy of the same contract file will generate different
    deploy descriptor
    """
    try:
        with open(contract_file) as fp:
            code = fp.read()
            contract = Contract(code, client=_epoch_cli())
            kp, _ = _keypair()
            tx = contract.tx_create(kp, gas=gas)

            # save the contract data
            contract_data = {
                'source': contract.source_code,
                'bytecode': contract.bytecode,
                'address': contract.address,
                'transaction': tx.tx_hash,
                'owner': kp.get_address(),
                'created_at': datetime.now().isoformat('T')
            }
            # write the contract data to a file
            deploy_descriptor = f"{contract_file}.deploy.{contract.address[3:]}.json"
            with open(deploy_descriptor, 'w') as fw:
                json.dump(contract_data, fw, indent=2)
            _pp([
                ("Contract address", contract.address),
                ("Transaction hash", tx.tx_hash),
                ("Deploy descriptor", deploy_descriptor),
            ])
    except Exception as e:
        print(e)
예제 #3
0
def test_sophia_contract_tx_create():
    contract = Contract(aer_identity_contract, Contract.SOPHIA)
    address, tx = contract.tx_create(KEYPAIR, gas=1000)
    assert address is not None
    assert len(address) > 0