示例#1
0
def opt_in(
    algod_client: algod.AlgodClient,
    user: Account,
    nft_id: int,
):
    nft_name = algod_client.asset_info(nft_id)['params']['name']
    optin = ''
    while not optin:
        optin = str(
            input(
                f"Do you want to opt-in the {nft_name} (ID: {nft_id})? (Y/n) ")
        )
        print("")
        if optin.lower() == 'y':
            params = algod_client.suggested_params()

            opt_in_txn = transaction.AssetOptInTxn(
                sender=user.address,
                sp=params,
                index=nft_id,
            )
            return sign_send_wait(algod_client, user, opt_in_txn)

        elif optin.lower() == 'n':
            return
        else:
            optin = ''
示例#2
0
def claim_nft(
    algod_client: algod.AlgodClient,
    indexer_client: indexer.IndexerClient,
    claimer: Account,
    claim_arg: str,
    new_majesty: str,
    donation_amount: int,
    nft_id: int,
):
    params = algod_client.suggested_params()

    claim_txn = transaction.ApplicationNoOpTxn(
        sender=claimer.address,
        sp=params,
        index=ALGOREALM_APP_ID,
        app_args=[claim_arg.encode(), new_majesty.encode()])

    donation_txn = transaction.PaymentTxn(
        sender=claimer.address,
        sp=params,
        receiver=REWARDS_POOL,
        amt=donation_amount,
    )

    nft_transfer = transaction.AssetTransferTxn(
        sender=ALGOREALM_LAW.address,
        sp=params,
        receiver=claimer.address,
        amt=1,
        index=nft_id,
        revocation_target=current_owner(indexer_client, nft_id),
    )

    signed_group = group_and_sign(
        [claimer, claimer, ALGOREALM_LAW],
        [claim_txn, donation_txn, nft_transfer],
    )

    nft_name = algod_client.asset_info(nft_id)['params']['name']

    print(f"Claiming the {nft_name} as {new_majesty}, "
          f"donating {donation_amount / 10 ** 6} ALGO...\n")
    try:
        gtxn_id = algod_client.send_transactions(signed_group)
        wait_for_confirmation(algod_client, gtxn_id)
    except AlgodHTTPError:
        quit("\n☹️  Were you too stingy? Only generous hearts will rule over "
             "Algorand Realm!\n️")