async def test_transaction_object_unfreeze(wallet, client):
    transaction = Transaction(wallet=wallet, client=client)
    unfreeze = await transaction.unfreeze_token(symbol="BNB", amount=0.1)
    print(unfreeze)
    assert unfreeze, "No result of unfreeze found"
    assert unfreeze[0]["hash"], "No txid found"
    await asyncio.sleep(1)
    tx = await client.get_transaction(unfreeze[0]["hash"])
    assert tx, "Transaction not on chain"
async def test_transaction_object_burn(wallet_two, client):
    transaction = Transaction(wallet=wallet_two, client=client)
    burn = await transaction.burn_token(symbol="BTC-531", amount=1)
    print(burn)
    assert burn, "No result of unfreeze found"
    assert burn[0]["hash"], "No txid found"
    await asyncio.sleep(1)
    tx = await client.get_transaction(burn[0]["hash"])
    assert tx, "Transaction not on chain"
    print(tx)
async def test_transaction_object_transfer(wallet, wallet_two, client):
    transaction = Transaction(wallet=wallet, client=client)
    transfer = await transaction.transfer(to_address=wallet_two.get_address(),
                                          symbol="BNB",
                                          amount=0.1)
    assert transfer, "No result of transfer found"
    assert transfer[0]["hash"], "No txid found"
    await asyncio.sleep(1)
    tx = await client.get_transaction(transfer[0]["hash"])
    assert tx, "Transaction not on chain"
async def test_transaction_object_cancel(wallet, client):
    address = wallet.get_address()
    open_orders = await client.get_open_orders(address)
    order = open_orders["order"][0]
    refid = order["orderId"]
    symbol = order["symbol"]
    transaction = Transaction(wallet=wallet, client=client)
    cancel_order = await transaction.cancel_order(symbol=symbol, refid=refid)
    print(cancel_order)
    assert cancel_order, "No result of cancel found"
    assert cancel_order[0]["hash"], "No txid found"
    await asyncio.sleep(1)
    tx = await client.get_transaction(cancel_order[0]["hash"])
    assert tx, "Transaction not on chain"
async def test_transaction_object_new_order(wallet, client):
    address = wallet.get_address()
    transaction = Transaction(wallet=wallet, client=client)
    new_order = await transaction.create_new_order(
        symbol=PAIR,
        side=Side.BUY,
        timeInForce=Timeinforce.GTE,
        price=0.01,
        quantity=1,
        ordertype=Ordertype.LIMIT,
    )
    assert new_order, "No result of new_order found"
    assert new_order[0]["hash"], "No txid found"
    await asyncio.sleep(1)
    tx = await client.get_transaction(new_order[0]["hash"])
    assert tx, "Transaction not on chain"
async def test_multi_transaction_object_transfer(wallet, wallet_two, client):
    transaction = Transaction(wallet=wallet_two, client=client)
    TOKEN_1 = "BNB"
    TOKEN_2 = "BTC-531"
    AMOUNT = 0.002
    transfers = [
        {
            "symbol": TOKEN_1,
            "amount": AMOUNT
        },
        {
            "symbol": TOKEN_2,
            "amount": AMOUNT
        },
    ]
    transfer = await transaction.multi_transfer(
        to_address=wallet.get_address(), transfers=transfers)
    assert transfer, "No result of transfer found"
    assert transfer[0]["hash"], "No txid found"
    await asyncio.sleep(1)
    tx = await client.get_transaction(transfer[0]["hash"])
    assert tx, "Transaction not on chain"
Exemplo n.º 7
0
async def transaction_example():
    transaction = Transaction(wallet=wallet, client=client)

    transfer = await transaction.transfer(to_address, symbol="BNB", amount=0.1)

    multi_transfer = await transaction.multi_transfer(
        to_address,
        transfers=[{"symbol": "BTC", "amount": 0.1}, {"symbol": "BNB", "amount": 0.1}],
    )

    new_order_txid = await transaction.create_new_order(
        symbol="binance_pair",
        side=Side.BUY,
        ordertype=Ordertype.LIMIT,
        price=1,
        quantity=1,
        timeInForce=Timeinforce.GTE,
    )

    cancel_order_txid = await transaction.cancel_order(symbol="pair", refid="")

    freeze_token_txid = await transaction.freeze_token(symbol="token", amount=1)

    unfreeze_token_txid = await transaction.unfreeze_token(symbol="token", amount=1)

    vote_txid = await transaction.vote(
        proposal_id="", option=Votes.YES
    )  # only validator can vote

    issue_token_txid = await transaction.issue_token(symbol, name, supply, mintable)

    mint_token_txid = await transaction.mint_token(symbol, amount)

    burn_token_txid = await transaction.burn_token(symbol, amount)
    """
    Create Unsigned Transaction, return transaction with message to sign and broadcast somewhere else
    """
    """
    Using default client if no client is passed in
    """

    transfer_transaction = await Transaction.transfer_transaction(
        from_address, to_address, symbol, amount
    )

    multi_transfer_transaction = await Transaction.multi_transfer_transaction(
        from_address,
        to_address,
        transfers=[{"symbol": "BTC", "amount": 0.1}, {"symbol": "BNB", "amount": 0.1}],
    )

    limit_buy_transaction = await Transaction.new_order_transaction(
        address="owner address",
        symbol="pair",
        side=Side.BUY,
        ordertype=Ordertype.LIMIT,
        price=1,
        quantity=1,
        timeInForce=Timeinforce.GTE,
        testnet=True,
        client=None,
    )

    limit_sell_transaction = await Transaction.new_order_transaction(
        address="owner address",
        symbol="pair",
        side=Side.BUY,
        ordertype=Ordertype.LIMIT,
        price=1,
        quantity=1,
        timeInForce=Timeinforce.GTE,
        testnet=True,
        client=None,
    )

    cancel_order_transaction = await Transaction.cancel_order(
        address="owner_address", symbol="pair", refid="", testnet=True, client=None
    )

    freeze_token_transaction = await Transaction.freeze_token(
        address="ownder_address", symbol="BNB", amount=1, testnet=True, client=None
    )

    unfreeze_token_tranasaction = await Transaction.unfreeze_token_transaction(
        address="ownder_address", symbol="BNB", amount=1, testnet=True, client=None
    )

    vote_transaction = await Transaction.vote_transaction(
        voter, proposal_id, option=Votes.YES, client=None, testnet=True
    )

    issue_token_transaction = await Transaction.issue_token_transaction(
        owner, name, symbol, sypply, mintable, client=None, testnet=True
    )

    mint_token_transaction = await Transaction.mint_token_transaction(
        owner, symbol, amount, client=None, testnet=True
    )

    burn_token_transaction = Transaction.burn_token_transaction(
        owner, symbol, amount, client=None, testnet=True
    )

    """
    Get Sign Message to sign with wallet
    """
    sign_message_bytes_format = limit_buy_transaction.get_sign_message()