def claim_interest(programstr, escrow_id, passphrase, amt, coupon, payment_id, interest_id, par_id, first_block, last_block, algod_client: algod_client()): add = mnemonic.to_public_key(passphrase) key = mnemonic.to_private_key(passphrase) sp = algod_client.suggested_params() sp.first = first_block sp.last = last_block sp.flat_fee = True sp.fee = 1000 print("--------------------------------------------") print("Bundling interest claim and submitting......") txn1 = AssetTransferTxn(add, sp, escrow_id, amt, interest_id) txn2 = AssetTransferTxn(add, sp, add, amt, par_id) txn3 = AssetTransferTxn(escrow_id, sp, add, amt * coupon, payment_id) t = programstr.encode() program = base64.decodebytes(t) arg = (4).to_bytes(8, 'big') lsig = LogicSig(program, args=[arg]) grp_id = calculate_group_id([txn1, txn2, txn3]) txn1.group = grp_id txn2.group = grp_id txn3.group = grp_id stxn1 = txn1.sign(key) stxn2 = txn2.sign(key) stxn3 = LogicSigTransaction(txn3, lsig) signed_group = [stxn1, stxn2, stxn3] tx_id = algod_client.send_transactions(signed_group) wait_for_confirmation(algod_client, tx_id, 200) print("Successfully committed transaction!") print("--------------------------------------------")
def optin(params_dict): algod_client, params = algod_connect(params_dict) print( '\n=====================================OPT-IN ASSET=====================================' ) print('asset_id:', params_dict['asset']) account_info = algod_client.account_info(params_dict['account']) holding = None idx = 0 # Verify if the account have an asset with the id: params_dict['asset'] for my_account_info in account_info['assets']: scrutinized_asset = account_info['assets'][idx] idx += 1 if scrutinized_asset['asset-id'] == params_dict['asset']: holding = True break # If the account is not holding the asset, optin the asset for this account if not holding: txn = AssetTransferTxn(sender=params_dict['account'], sp=params, receiver=params_dict['account'], amt=0, index=params_dict['asset']) private_key = mnemonic.to_private_key(params_dict['mnemonic']) stxn = txn.sign(private_key) txid = algod_client.send_transaction(stxn) print('Transaction ID: ', txid) wait_for_confirmation(algod_client, txid) print_asset_holding(algod_client, params_dict['account'], params_dict['asset'])
def opt_in(algodclient, receiver, receiver_sk, asset_id): params = algod_client.suggested_params() # comment these two lines if you want to use suggested params params.fee = 1000 params.flat_fee = True account_info = algod_client.account_info(receiver) holding = None idx = 0 for my_account_info in account_info['assets']: scrutinized_asset = account_info['assets'][idx] idx = idx + 1 if (scrutinized_asset['asset-id'] == asset_id): holding = True break if not holding: # Use the AssetTransferTxn class to transfer assets and opt-in txn = AssetTransferTxn(sender=receiver, sp=params, receiver=receiver, amt=0, index=asset_id) stxn = txn.sign(receiver_sk) txid = algod_client.send_transaction(stxn) print(txid) # Wait for the transaction to be confirmed wait_for_confirmation(algod_client, txid) # Now check the asset holding for that account. # This should now show a holding with a balance of 0. print_asset_holding(algod_client, receiver, asset_id)
def asset_transfer(sender, private_key, receiver, amount, index): """Function for asset transfer""" params = ALGODCLIENT.suggested_params() txn = AssetTransferTxn(sender, params, receiver, amount, index) signed_tx = txn.sign(private_key) ALGODCLIENT.send_transaction(signed_tx) return True
def distribute_dividends(asset_info): print("Distributing dividends for: ", asset_info['bond_name']) params = algod_client.suggested_params() purchases = [purchase for purchase in db.transaction.find({}) if purchase['asset_id'] == asset_info['asset_id'] and purchase['action'] == 'BUY'] for purchase in purchases: user_id = purchase['user_id'] user = db.user.find_one({'_id': user_id}) user_mnemonic = user['mnemonic'] user_pk = mnemonic.to_public_key(user_mnemonic) amount = int(asset_info["coupon_rate"])/100*int(asset_info["face_value"]) *\ (int(purchase['tokens'])/asset_info['issue_size']) # Fraction of real estate owned ## txn = AssetTransferTxn( sender=accounts[1]['pk'], sp=params, receiver=user_pk, amt=int(amount), index=USDT_asset_id) stxn = txn.sign(accounts[1]['sk']) txid = algod_client.send_transaction(stxn) print(txid) # Wait for the transaction to be confirmed wait_for_confirmation(algod_client, txid) # The balance should now be 10. print_asset_holding(algod_client, user_pk, USDT_asset_id) # Save Dividend Transaction db_dividend_tx = db.dividends.insert_one({ 'user_id': user_mnemonic, 'amount': amount, 'asset_id': asset_info['asset_id'] })
def purchase_bond(programstr, escrow_id, passphrase, amt, payment_id, par, interest_id, par_id, total_payments, algod_client: algod_client(), first_block, last_block): add = mnemonic.to_public_key(passphrase) key = mnemonic.to_private_key(passphrase) sp = algod_client.suggested_params() sp.first = first_block sp.last = last_block sp.flat_fee = True sp.fee = 1000 print("--------------------------------------------") print("Opt-in the buyer account for interest and par token......") txn0_1 = AssetTransferTxn(add, sp, add, 0, interest_id) txn0_2 = AssetTransferTxn(add, sp, add, 0, par_id) sign0_1 = txn0_1.sign(key) sign0_2 = txn0_2.sign(key) txn0_1_id = algod_client.send_transaction(sign0_1) wait_for_confirmation(algod_client, txn0_1_id, 5) print("Successfully opt-in") print("--------------------------------------------") print("--------------------------------------------") print("Bundling purchase transactions and submitting......") txn0_2_id = algod_client.send_transaction(sign0_2) wait_for_confirmation(algod_client, txn0_2_id, 5) txn1 = AssetTransferTxn(add, sp, escrow_id, amt * par, payment_id) txn2 = AssetTransferTxn(escrow_id, sp, add, amt, par_id) txn3 = AssetTransferTxn(escrow_id, sp, add, amt * total_payments, interest_id) t = programstr.encode() program = base64.decodebytes(t) arg = (3).to_bytes(8, 'big') lsig = LogicSig(program, args=[arg]) grp_id = calculate_group_id([txn1, txn2, txn3]) txn1.group = grp_id txn2.group = grp_id txn3.group = grp_id stxn1 = txn1.sign(key) stxn2 = LogicSigTransaction(txn2, lsig) stxn3 = LogicSigTransaction(txn3, lsig) signed_group = [stxn1, stxn2, stxn3] tx_id = algod_client.send_transactions(signed_group) wait_for_confirmation(algod_client, tx_id, 200) print("Successfulley commited transaction!") print("--------------------------------------------")
def replenish_account(passphrase, escrow_id, amt, payment_id, algod_client): add = mnemonic.to_public_key(passphrase) key = mnemonic.to_private_key(passphrase) sp = algod_client.suggested_params() sp.flat_fee = True sp.fee = 1000 txn = AssetTransferTxn(add, sp, escrow_id, amt, payment_id) stxn = txn.sign(key) tx_id = algod_client.send_transaction(stxn) wait_for_confirmation(algod_client, tx_id, 10)
def p2p_order(buyer, seller, order_details): params = algod_client.suggested_params() buyer_pk = mnemonic.to_public_key(buyer) buyer_sk = mnemonic.to_private_key(buyer) seller_pk = mnemonic.to_public_key(seller) seller_sk = mnemonic.to_private_key(seller) # activate buyer's account print("Activating Buyer's account") activate_account(order_details['asset_id'], buyer) # Token transaction print("\n Executing Token Transaction") token_txn = AssetTransferTxn( sender=seller_pk, sp=params, receiver=buyer_pk, amt=int(order_details['token_amount']), index=order_details['asset_id']) token_stxn = token_txn.sign(seller_sk) token_txid = algod_client.send_transaction(token_stxn) print(token_txid) wait_for_confirmation(algod_client, token_txid) print_asset_holding(algod_client, buyer_pk, order_details['asset_id']) # Activating USDT for seller print("Activating USDT for Seller") activate_account(USDT_asset_id, seller) # USDT Transaction print("\n USDT Transaction") usdt_txn = AssetTransferTxn( sender=buyer_pk, sp=params, receiver=seller_pk, amt=int(order_details['usdt_amount']), index=USDT_asset_id) usdt_stxn = usdt_txn.sign(buyer_sk) usdt_txid = algod_client.send_transaction(usdt_stxn) print(usdt_txid) wait_for_confirmation(algod_client, usdt_txid) print_asset_holding(algod_client, seller_pk, USDT_asset_id)
def asset_transaction(passphrase, amt, rcv, asset_id, algod_client) -> dict: params = algod_client.suggested_params() add = mnemonic.to_public_key(passphrase) key = mnemonic.to_private_key(passphrase) params.flat_fee = True params.fee = 1000 unsigned_txn = AssetTransferTxn(add, params, rcv, amt, asset_id) signed = unsigned_txn.sign(key) txid = algod_client.send_transaction(signed) pmtx = wait_for_confirmation(algod_client, txid, 4) return pmtx
def transfer_nft_to_user(asset_id, address): mypic_private_key = get_private_key_from_mnemonic(word_mnemonic) params = algod_client.suggested_params() params.fee = 1000 params.flat_fee = True txn = AssetTransferTxn(sender=ADDRESS_ALGO_OURSELF, sp=params, receiver=address, amt=1, index=asset_id) stxn = txn.sign(mypic_private_key) tx_id = algod_client.send_transaction(stxn) return tx_id
def optin(update, context, recipient, sk): """ Checks if user already optin for an ASA, subscribes users if condition is false. :param update: :param context: :param recipient: public key of subscriber :param sk: Signature of subscriber :return: true if success. """ algod_client = connect(update, context) params = algod_client.suggested_params() # Check if recipient holding DMT2 asset prior to opt-in print(algod_client.account_info(recipient)) account_info_pk = algod_client.account_info(recipient) print(account_info_pk) holding = None # idx = 0 for assetinfo in account_info_pk['assets']: scrutinized_asset = assetinfo['asset-id'] # idx = idx + 1 if asset_id == scrutinized_asset: holding = True msg = "This address has opted in for DMT2, ID {}".format(asset_id) logging.info("Message: {}".format(msg)) logging.captureWarnings(True) break if not holding: # Use the AssetTransferTxn class to transfer assets and opt-in txn = AssetTransferTxn(sender=recipient, sp=params, receiver=recipient, amt=0, index=asset_id) # Sign the transaction # Firstly, convert mnemonics to private key. # For tutorial purpose, we will focus on using private key # sk = mnemonic.to_private_key(seed) sendTrxn = txn.sign(sk) # Submit transaction to the network txid = algod_client.send_transaction(sendTrxn) message = "Transaction was signed with: {}.".format(txid) wait = wait_for_confirmation(update, context, algod_client, txid) time.sleep(2) hasOptedIn = bool(wait is not None) if hasOptedIn: update.message.reply_text(f"Opt in success\n{message}") return hasOptedIn
def resolve(self, bankrIdentifier, skey): # Check if Leafbank holding Bankers' asset prior to opt-in assetId = getAssetIdv2(transaction_executor) account_info_pk = algo_client.account_info(bankrIdentifier) holding = None idx = 0 print(account_info_pk) for assetinfo in account_info_pk['assets']: scrutinized_asset = assetinfo[idx] idx = idx + 1 if assetId == scrutinized_asset['asset-id']: holding = True msg = "This address has opted in for ISA, ID {}".format(assetId) logging.info("Message: {}".format(msg)) logging.captureWarnings(True) break if not holding: # Use the AssetTransferTxn class to transfer assets and opt-in txn = AssetTransferTxn( sender=bankrIdentifier, sp=params, receiver=bankrIdentifier, amt=0, index=assetId ) # Sign the transaction # Firstly, convert mnemonics to private key--. sk = mnemonic.to_private_key(seed) sendTrxn = txn.sign(sk) # Submit transaction to the network txid = algo_client.send_transaction(sendTrxn, headers={'content-type': 'application/x-binary'}) message = "Transaction was signed with: {}.".format(txid) wait = wait_for_confirmation(txid) time.sleep(2) hasOptedIn = bool(wait is not None) if hasOptedIn: self.hasResolve = True print(assetId) # Now check the asset holding for that account. # This should now show a holding with 0 balance. assetHolding = print_asset_holding(bankrIdentifier, assetId) logging.info("...##Asset Transfer... \nLeaf Bank address: {}.\nMessage: {}\nHas Opted in: {}\nOperation: {}\nHoldings: {}\n".format( bankrIdentifier, message, hasOptedIn, Bankers.resolve.__name__, assetHolding )) return hasOptedIn
def transfer_nft_to_user(algod_client, asset_id, mypic_public_key, mypic_private_key, user_public_key): params = algod_client.suggested_params() # comment these two lines if you want to use suggested params params.fee = 1000 params.flat_fee = True txn = AssetTransferTxn( sender=mypic_public_key, sp=params, receiver=user_public_key, amt=1, index=asset_id) stxn = txn.sign(mypic_private_key) txid = algod_client.send_transaction(stxn) return txid
def opt_in_asset(asset_id): mn = 'tattoo market oven bench betray double tuna box sand lottery champion spend melt virus motor label bacon wine rescue custom cannon pen merry absorb endorse' public_key = get_public_key_from_mnemonic(mn) print(public_key) private_key = get_private_key_from_mnemonic(mn) params = algod_client.suggested_params() params.fee = 1000 params.flat_fee = True txn = AssetTransferTxn(sender=ADDRESS_ALGO_OURSELF, sp=params, receiver=public_key, amt=0, index=asset_id) stxn = txn.sign(private_key) tx_id = algod_client.send_transaction(stxn) wait_for_confirmation(tx_id) print("Asset ", asset_id, " opted in for ACCOUNT ", public_key)
def transfer(update, context, receiver, amount): """ Transfer a custom asset from default account A to account B (Any) :param update: Default telegram argument :param context: Same as update :param sender: Sender of this transaction :param receiver: The beneficiary of the asset in transit :param amount: Amount in custom asset other than ALGO :return: """ global saleable params = algod_client.suggested_params() params.fee = 1000 params.flat_fee = True print(auth) try: assert saleable >= amount, response_end( update, context, "Sales for the period is exhausted") txn = AssetTransferTxn( sender=to, # asset_manage_authorized, sp=params, receiver=receiver, amt=int(amount), index=asset_id ) # Sign the transaction sk = mnemonic.to_private_key(auth) signedTrxn = txn.sign(sk) # Submit transaction to the network tx_id = algod_client.send_transaction(signedTrxn) message = "Successful! \nTransaction hash: {}.".format(tx_id) wait_for_confirmation(update, context, algod_client, tx_id) logging.info( "...##Asset Transfer... \nReceiving account: {}.\nMessage: {}\nOperation: {}\nTxn Hash: {}" .format(receiver, message, transfer.__name__, tx_id)) update.message.reply_text(message, reply_markup=markup2) saleable -= amount # Erase the key soon as you're done with it. context.user_data.clear() except Exception as err: print(err) return markup2
def opt_in_asset(algod_client, sender, asset_id): """ @params{algod_client} - AlgodClient instance created by calling algod.AlgodClient @params{sender} - a dictionary containing the public/private key of the holder - { 'public_key': string, 'private_key': string } @params{asset_id} - int asset id Opts in an asset with the asset id. @returns { 'status': boolean, 'txid': string 'info': json string containing the transaction information if status is True else a string of error message } """ params = algod_client.suggested_params() params.flat_fee = True params.fee = 1000 account_info = algod_client.account_info(sender['public_key']) hold = False for scrutinized_asset in account_info['assets']: if scrutinized_asset['asset-id'] == asset_id: hold = True break if not hold: unsigned_txn = AssetTransferTxn(sender=sender['public_key'], sp=params, receiver=sender['public_key'], amt=0, index=asset_id) signed_txn = unsigned_txn.sign(sender['private_key']) txid = algod_client.send_transaction(signed_txn) print('Pending transaction with id: {}'.format(txid)) try: confirmed_txn = wait_for_confirmation(algod_client, txid) except Exception as err: print(err) return { 'status': False, 'txid': txid, 'info': getattr(err, 'message', str(err)) } return { 'status': True, 'txid': txid, 'info': json.dumps(confirmed_txn) } return { 'status': True, 'txid': '', 'info': '' }
def transfer_assets(sender, receiver, amount, asset=settings.ALGO_ASSET, close_assets_to=None): _params = params() atxn = AssetTransferTxn( sender.address, _params, receiver.address, int(amount * 1000000), asset, close_assets_to=close_assets_to.address if close_assets_to else None) if sender.type == accounts.models.Account.SMART_CONTRACT_ACCOUNT: signed_atxn = sender.smart_contract.sign(atxn) else: signed_atxn = atxn.sign(sender.private_key) fee = (_params.min_fee if _params.fee == 0 else _params.fee) / 1000000 return CLIENT.send_transaction(signed_atxn), fee
def opt_in_asset(algod_client, asset_id, public_key, private_key): params = algod_client.suggested_params() # comment these two lines if you want to use suggested params params.fee = 1000 params.flat_fee = True # Use the AssetTransferTxn class to transfer assets and opt-in txn = AssetTransferTxn( sender=public_key, sp=params, receiver=public_key, amt=0, index=asset_id) stxn = txn.sign(private_key) txid = algod_client.send_transaction(stxn) # Wait for the transaction to be confirmed wait_for_confirmation(algod_client, txid) # Now check the asset holding for that account. # This should now show a holding with a balance of 0. #print_asset_holding(algod_client, public_key, asset_id) print("Asset ",asset_id," opted in for ACCOUNT ",public_key,"\n")
def transfer_asset_holding(algodclient, account, account_sk, receiver, asset_id): # transfer asset of 10 from account 1 to account 3 params = algod_client.suggested_params() # comment these two lines if you want to use suggested params params.fee = 1000 params.flat_fee = True txn = AssetTransferTxn( sender=account, #accounts[1]['pk'], sp=params, receiver=receiver, #accounts[3]["pk"], amt=1, index=asset_id) stxn = txn.sign(account_sk) txid = algod_client.send_transaction(stxn) print(txid) # Wait for the transaction to be confirmed wait_for_confirmation(algod_client, txid) # The balance should now be 10. print_asset_holding(algod_client, receiver, asset_id) return stxn
def activate_account(asset_id, user_memonic): # Check if asset_id is in account 3's asset holdings prior # to opt-in params = algod_client.suggested_params() # comment these two lines if you want to use suggested params params.fee = 0 params.flat_fee = False params.min_fee = 0 account = { 'pk': mnemonic.to_public_key(user_memonic), 'sk': mnemonic.to_private_key(user_memonic) } account_info = algod_client.account_info(account['pk']) holding = None idx = 0 for my_account_info in account_info['assets']: scrutinized_asset = account_info['assets'][idx] idx = idx + 1 if (scrutinized_asset['asset-id'] == asset_id): holding = True break if not holding: # Use the AssetTransferTxn class to transfer assets and opt-in txn = AssetTransferTxn( sender=account['pk'], sp=params, receiver=account["pk"], amt=0, index=asset_id) stxn = txn.sign(account['sk']) txid = algod_client.send_transaction(stxn) print(txid) # Wait for the transaction to be confirmed wait_for_confirmation(algod_client, txid) # Now check the asset holding for that account. # This should now show a holding with a balance of 0. print_asset_holding(algod_client, account['pk'], asset_id)
def transferAssets(algod_client, alice, bob, asset_id): print("--------------------------------------------") print("Transfering Alice's token to Bob......") params = algod_client.suggested_params() # comment these two lines if you want to use suggested params # params.fee = 1000 # params.flat_fee = True txn = AssetTransferTxn(sender=alice['pk'], sp=params, receiver=bob["pk"], amt=100, index=asset_id) stxn = txn.sign(alice['sk']) txid = algod_client.send_transaction(stxn) print(txid) # Wait for the transaction to be confirmed confirmed_txn = wait_for_confirmation(algod_client, txid, 4) print("TXID: ", txid) print("Result confirmed in round: {}".format( confirmed_txn['confirmed-round'])) # The balance should now be 10. print_asset_holding(algod_client, bob['pk'], asset_id)
def transfer_asset(algod_client, sender, receiver, asset_id, sign=True): """ @params{algod_client} - AlgodClient instance created by calling algod.AlgodClient @params{sender} - a dictionary containing the public/private key of the holder - { 'public_key': string, 'private_key': string } @params{receiver} - a string of the public key (account address) of the receiver @params{asset_id} - int asset id @params{sign} OPTIONAL - boolean whether or not to sign and send the transaction Transfer 1 asset (NFT) from sender to receiver. @returns { 'status': boolean, 'txid': string 'info': json string containing the transaction information if status is True else a string of error message } if sign else { 'sender': a dictionary containing the public/private key of the holder, 'txn': unsigned transaction } """ params = algod_client.suggested_params() params.flat_fee = True params.fee = 1000 unsigned_txn = AssetTransferTxn(sender=sender['public_key'], sp=params, receiver=receiver, amt=1, index=asset_id) if not sign: return { 'sender': sender, 'txn': unsigned_txn } signed_txn = unsigned_txn.sign(sender['private_key']) txid = algod_client.send_transaction(signed_txn) print('Pending transaction with id: {}'.format(txid)) try: confirmed_txn = wait_for_confirmation(algod_client, txid) except Exception as err: print(err) return { 'status': False, 'txid': txid, 'info': getattr(err, 'message', str(err)) } return { 'status': True, 'txid': txid, 'info': json.dumps(confirmed_txn) }
def optIn(algod_client, bob, asset_id): print("--------------------------------------------") print("Opt-in for Alice's token......") # Check if asset_id is in Bob's asset holdings prior # to opt-in params = algod_client.suggested_params() # comment these two lines if you want to use suggested params # params.fee = 1000 # params.flat_fee = True account_info = algod_client.account_info(bob['pk']) holding = None idx = 0 for my_account_info in account_info['assets']: scrutinized_asset = account_info['assets'][idx] idx = idx + 1 if (scrutinized_asset['asset-id'] == asset_id): holding = True break if not holding: # Use the AssetTransferTxn class to transfer assets and opt-in txn = AssetTransferTxn(sender=bob['pk'], sp=params, receiver=bob["pk"], amt=0, index=asset_id) stxn = txn.sign(bob['sk']) txid = algod_client.send_transaction(stxn) print(txid) # Wait for the transaction to be confirmed confirmed_txn = wait_for_confirmation(algod_client, txid, 4) print("TXID: ", txid) print("Result confirmed in round: {}".format( confirmed_txn['confirmed-round'])) # Now check the asset holding for that account. # This should now show a holding with a balance of 0. print_asset_holding(algod_client, bob['pk'], asset_id)
def transfer_asset(asset_id, user_memonic, amount): account = { 'pk': mnemonic.to_public_key(user_memonic), 'sk': mnemonic.to_private_key(user_memonic) } # transfer asset of 10 from account 1 to account 3 params = algod_client.suggested_params() # comment these two lines if you want to use suggested params params.fee = 1 params.flat_fee = True txn = AssetTransferTxn( sender=accounts[1]['pk'], sp=params, receiver=account["pk"], amt=int(amount), index=asset_id) stxn = txn.sign(accounts[1]['sk']) txid = algod_client.send_transaction(stxn) print(txid) # Wait for the transaction to be confirmed wait_for_confirmation(algod_client, txid) # The balance should now be 10. print_asset_holding(algod_client, account['pk'], asset_id)
def transfer(asset_id, sender_account_id, receiver_account_id): print( '\n=====================================ASSET TRANSFER=====================================' ) print('asset_id:', asset_id) # Transfert une valeur de 10 actifs du compte sender_account_id au compte receiver_account_id txn = AssetTransferTxn(sender=accounts_dict[sender_account_id]['pk'], sp=params, receiver=accounts_dict[receiver_account_id]['pk'], amt=10, index=asset_id) stxn = txn.sign(accounts_dict[sender_account_id]['sk']) txid = algod_client.send_transaction(stxn) print('Transaction ID: ', txid) wait_for_confirmation(algod_client, txid) # txid_list.append(txid) # Attend la confirmation le la liste de toutes les transactions précédentes # wait_for_confirmation_list(algod_client, txid_list) print_asset_holding(algod_client, accounts_dict[receiver_account_id]['pk'], asset_id)
def claim_par(programstr, escrow_id, passphrase, amt, par, payment_id, par_id, first_block, last_block, algod_client): add = mnemonic.to_public_key(passphrase) key = mnemonic.to_private_key(passphrase) sp = algod_client.suggested_params() sp.first = first_block sp.last = last_block sp.flat_fee = True sp.fee = 1000 txn1 = AssetTransferTxn(add, sp, escrow_id, amt, par_id) txn2 = AssetTransferTxn(escrow_id, sp, add, amt * par, payment_id) t = programstr.encode() program = base64.decodebytes(t) arg = (5).to_bytes(8, 'big') lsig = LogicSig(program, args=[arg]) grp_id = calculate_group_id([txn1, txn2]) txn1.group = grp_id txn2.group = grp_id stxn1 = txn1.sign(key) stxn2 = LogicSigTransaction(txn2, lsig) signed_group = [stxn1, stxn2] tx_id = algod_client.send_transactions(signed_group) wait_for_confirmation(algod_client, tx_id, 10)
def revoke(asset_id, sender_account_id, receiver_account_id, target_account_id): print( '\n=====================================REVOKE ASSET=====================================' ) print('asset_id:', asset_id) print('\n--- Before revoke') print('\nAccount', target_account_id) print_asset_holding(algod_client, accounts_dict[target_account_id]['pk'], asset_id) print('\nAccount', receiver_account_id) print_asset_holding(algod_client, accounts_dict[receiver_account_id]['pk'], asset_id) txn = AssetTransferTxn( sender=accounts_dict[sender_account_id]['pk'], sp=params, receiver=accounts_dict[receiver_account_id]['pk'], index=asset_id, amt=10, revocation_target=accounts_dict[target_account_id]['pk']) stxn = txn.sign(accounts_dict[sender_account_id]['sk']) txid = algod_client.send_transaction(stxn) print('Transaction ID:', txid) wait_for_confirmation(algod_client, txid) print('\n--- After revoke') print('\nAccount', target_account_id) print_asset_holding(algod_client, accounts_dict[target_account_id]['pk'], asset_id) print('\nAccount', receiver_account_id) print_asset_holding(algod_client, accounts_dict[receiver_account_id]['pk'], asset_id)
info = [line.strip() for line in fd] accountA['mnemonic'] = info[2].split(': ')[1] accountA['pk'] = mnemonic.to_public_key(accountA['mnemonic']) accountA['sk'] = mnemonic.to_private_key(accountA['mnemonic']) accountB = dict() with open('../accountB.creds', 'r') as fd: info = [line.strip() for line in fd] accountB['mnemonic'] = info[2].split(': ')[1] accountB['pk'] = mnemonic.to_public_key(accountB['mnemonic']) accountB['sk'] = mnemonic.to_private_key(accountB['mnemonic']) algod_client = algod.AlgodClient( algod_token='', algod_address='https://api.testnet.algoexplorer.io', headers={'User-Agent': 'DoYouLoveMe?'}) params = algod_client.suggested_params() params.fee = 1000 params.flat_fee = True asset_id = 14075399 txn = AssetTransferTxn(sender=accountA['pk'], sp=params, receiver=accountB['pk'], amt=1, index=asset_id) stxn = txn.sign(accountA['sk']) txid = algod_client.send_transaction(stxn) print(txid) wait_for_confirmation(algod_client, txid) print_asset_holding(algod_client, accountB['pk'], asset_id)