def notify(algod_client: algod.AlgodClient, user: Account, seller: Account, trade_gtxn: list): params = algod_client.suggested_params() note = { 'buy_order': 'AlgoRealm Special Card', 'asset_id': CARD_ID, 'algo_amount': trade_gtxn[2].transaction.amt / 10**6, 'algo_royalty': (trade_gtxn[3].amt + trade_gtxn[4].amt) / 10**6, 'last_valid_block': trade_gtxn[2].transaction.last_valid_round } bytes_note = msgpack.packb(note) notification_txn = transaction.PaymentTxn( sender=user.address, sp=params, receiver=seller.address, amt=0, note=bytes_note, ) signed_txn = sign(user, notification_txn) tx_id = signed_txn.transaction.get_txid() print("✉️ Sending buy order notification to the Seller...\n") algod_client.send_transactions([signed_txn]) wait_for_confirmation(algod_client, tx_id) print("\n📄 Buy order notification:\n" "https://algoexplorer.io/tx/" + tx_id)
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 = ''
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️")
def add_network_params( client: algod.AlgodClient, tx_data: Dict[str, str or int]) -> Dict[str, str or int]: """ Adds network-related parameters to supplied transaction data. :param client -> ``algod.AlgodClient``: an algorand client object. :param tx_data -> ``Dict[str, str or int]``: data for the transaction. """ params = client.suggested_params() tx_data["first"] = params.first tx_data["last"] = params.last tx_data["gh"] = params.gh tx_data["gen"] = params.gen tx_data["fee"] = round(convert_algos_to_microalgo(.01)) tx_data["flat_fee"] = True return tx_data
def proof_asa_amount_eq_txn( algod_client: algod.AlgodClient, sender: Account, asa_id: int, asa_amount: int, ): params = algod_client.suggested_params() proof_txn = transaction.ApplicationNoOpTxn( sender=sender.address, sp=params, index=ASA_STATE_OBSERVER_APP_ID, app_args=["AsaAmountEq".encode(), asa_amount], foreign_assets=[asa_id], accounts=[sender.address], ) return proof_txn
def claim_card(algod_client: algod.AlgodClient, claimer: Account): params = algod_client.suggested_params() proof_crown_ownership = proof_asa_amount_eq_txn( algod_client=algod_client, sender=claimer, asa_id=CROWN_ID, asa_amount=1, ) proof_sceptre_ownership = proof_asa_amount_eq_txn( algod_client=algod_client, sender=claimer, asa_id=SCEPTRE_ID, asa_amount=1, ) nft_card_xfer = transaction.AssetTransferTxn( sender=CARD_CONTRACT.address, sp=params, receiver=claimer.address, amt=1, index=CARD_ID, revocation_target=CARD_CONTRACT.address, ) signed_group = group_and_sign( [claimer, claimer, CARD_CONTRACT], [proof_crown_ownership, proof_sceptre_ownership, nft_card_xfer], ) try: gtxn_id = algod_client.send_transactions(signed_group) wait_for_confirmation(algod_client, gtxn_id) except AlgodHTTPError: quit("\nOnly the generous heart of the Great Majesty of Algorand " "can break the spell!\n" "Conquer both the 👑 Crown of Entropy and the 🪄 Sceptre " "of Proof first!\n")
def card_order( algod_client: algod.AlgodClient, buyer: Account, seller: Account, price: int, ): params = algod_client.suggested_params() proof_crown_ownership = proof_asa_amount_eq_txn( algod_client=algod_client, sender=seller, asa_id=CROWN_ID, asa_amount=1, ) proof_sceptre_ownership = proof_asa_amount_eq_txn( algod_client=algod_client, sender=seller, asa_id=SCEPTRE_ID, asa_amount=1, ) nft_card_payment = transaction.PaymentTxn( sender=buyer.address, sp=params, receiver=seller.address, amt=price, ) royalty_amount = math.ceil(price * ROYALTY_PERC / 100) royalty_1_payment = transaction.PaymentTxn( sender=seller.address, sp=params, receiver=ROYALTY_COLLECTOR_1.address, amt=royalty_amount, ) royalty_2_payment = transaction.PaymentTxn( sender=seller.address, sp=params, receiver=ROYALTY_COLLECTOR_2.address, amt=royalty_amount, ) nft_card_xfer = transaction.AssetTransferTxn( sender=CARD_CONTRACT.address, sp=params, receiver=buyer.address, amt=1, index=CARD_ID, revocation_target=seller.address, ) trade_gtxn = [ proof_crown_ownership, proof_sceptre_ownership, nft_card_payment, royalty_1_payment, royalty_2_payment, nft_card_xfer ] transaction.assign_group_id(trade_gtxn) signed_nft_card_payment = trade_gtxn[2].sign(buyer.private_key) trade_gtxn[2] = signed_nft_card_payment trade_gtxn[5] = transaction.LogicSigTransaction(trade_gtxn[5], CARD_CONTRACT.lsig) transaction.write_to_file(trade_gtxn, 'trade_raw.gtxn', overwrite=True) print( "📝 Partially signed trade group transaction saved as: 'trade.gtxn'\n") return trade_gtxn