示例#1
0
def create_app(client, private_key, approval_program, clear_program,
               global_schema, local_schema, app_args):
    # define sender as creator
    sender = account.address_from_private_key(private_key)

    # declare on_complete as NoOp
    on_complete = transaction.OnComplete.NoOpOC.real

    # get node suggested parameters
    params = client.suggested_params()
    # comment out the next two (2) lines to use suggested fees
    params.flat_fee = True
    params.fee = 1000

    # create unsigned transaction
    txn = transaction.ApplicationCreateTxn(sender, params, on_complete, \
                                            approval_program, clear_program, \
                                            global_schema, local_schema, app_args)

    # sign transaction
    signed_txn = txn.sign(private_key)
    tx_id = signed_txn.transaction.get_txid()

    # send transaction
    client.send_transactions([signed_txn])

    # await confirmation
    wait_for_confirmation(client, tx_id)

    # display results
    transaction_response = client.pending_transaction_info(tx_id)
    app_id = transaction_response['application-index']
    print("Created new app-id:", app_id)

    return app_id
示例#2
0
def deploy_exchange_manager(manager_approve_code, manager_clear_code):
    print("Deploying exchange manager application...")

    create_manager_transaction = transaction.ApplicationCreateTxn(
        sender=DEVELOPER_ACCOUNT_ADDRESS,
        sp=algod_client.suggested_params(),
        on_complete=transaction.OnComplete.NoOpOC,
        approval_program=manager_approve_code,
        clear_program=manager_clear_code,
        global_schema=transaction.StateSchema(num_uints=0, num_byte_slices=1),
        local_schema=transaction.StateSchema(num_uints=10, num_byte_slices=0),
    ).sign(DEVELOPER_ACCOUNT_PRIVATE_KEY)
    tx_id = algod_client.send_transaction(create_manager_transaction)
    manager_app_id = wait_for_transaction(tx_id)['created-application-index']
    print(
        f"Exchange Manager deployed with Application ID: {manager_app_id} (Txn ID: https://testnet.algoexplorer.io/tx/{tx_id})"
    )

    print()

    return manager_app_id
示例#3
0
def create_app(
    client,
    creator,
    creator_priv_key,
    suggested_params,
    asset_index,
):
    txn = transaction.ApplicationCreateTxn(
        creator,
        suggested_params,
        transaction.OnComplete.NoOpOC.real,
        compile_program(client,
                        open('./contracts/state.teal', 'rb').read()),
        compile_program(client,
                        open('./contracts/clear.teal', 'rb').read()),
        transaction.StateSchema(num_byte_slices=2, num_uints=4),
        transaction.StateSchema(num_byte_slices=0, num_uints=3),
        app_args=[int_to_bytes(asset_index)])

    signed_txn = txn.sign(creator_priv_key)
    tx_id = client.send_transactions([signed_txn])

    return tx_id
示例#4
0
global_schema = transaction.StateSchema(global_ints, global_bytes)
local_schema = transaction.StateSchema(local_ints, local_bytes)

# declare on_complete as NoOp
on_complete = transaction.OnComplete.NoOpOC.real

# get node suggested parameters
params = client.suggested_params()
# comment out the next two (2) lines to use suggested fees
params.flat_fee = True
params.fee = int(sys.argv[12])

# create unsigned transaction
approval_program = compile_program(client, sys.argv[9])
clear_program = compile_program(client, sys.argv[10])
txn = transaction.ApplicationCreateTxn(creator, params, on_complete, approval_program,  clear_program, global_schema, local_schema, app_args)

# sign transaction
signed_txn = txn.sign(creator_private_key)
tx_id = signed_txn.transaction.get_txid()

# send transaction
client.send_transactions([signed_txn])

# await confirmation
wait_for_confirmation(client, tx_id)

# display results
transaction_response = client.pending_transaction_info(tx_id)
app_id = transaction_response['application-index']
示例#5
0
文件: deploy.py 项目: w1r2p1/AlgoSwap
        f"Exchange manager approve program currently uses {len(manager_approve_code)} of 1000 bytes"
    )
    manager_clear_teal_code = compileTeal(manager.clear_program(),
                                          Mode.Application)
    compile_response = algod_client.compile(manager_clear_teal_code)
    manager_clear_code = base64.b64decode(compile_response['result'])
    print(
        f"Exchange manager clear program currently uses {len(manager_clear_code)} of 1000 bytes"
    )

    print("Deploying exchange manager application...")
    create_application_transaction = transaction.ApplicationCreateTxn(
        sender=DEVELOPER_ACCOUNT_ADDRESS,
        sp=algod_client.suggested_params(),
        on_complete=transaction.OnComplete.NoOpOC,
        approval_program=manager_approve_code,
        clear_program=manager_clear_code,
        global_schema=transaction.StateSchema(num_uints=0, num_byte_slices=1),
        local_schema=transaction.StateSchema(num_uints=7, num_byte_slices=1),
    ).sign(DEVELOPER_ACCOUNT_PRIVATE_KEY)
    transaction_id = algod_client.send_transaction(
        create_application_transaction)
    exchange_application_id = wait_for_transaction(
        transaction_id)['created-application-index']
    print(
        f"Exchange manager deployed with application ID {exchange_application_id} (transaction: {transaction_id})"
    )

    # deploy escrow
    escrow_teal_code = compileTeal(escrow.logicsig(), Mode.Application)
    compile_response = algod_client.compile(escrow_teal_code)