def closs_asset(self,program,asset_id,receiver): first, last, gen, gh, min_fee = self.get_params() lsig = LogicSig(program) txn = AssetTransferTxn( sender = lsig.address(), fee=min_fee, first=first, last=last, gh=gh, receiver=None, amt=0, index=asset_id, flat_fee=True, closs_assets_to=receiver) return txn
# program = b"hex-encoded-program" # b"\x01\x20\x01\x00\x22 is `int 0` # see more info here: https://developer.algorand.org/docs/features/asc1/sdks/#accessing-teal-program-from-sdks program = b"\x01\x20\x01\x00\x22" # program = b"hex-encoded-program" lsig = LogicSig(program) # string parameter # arg_str = "my string" # arg1 = arg_str.encode() # lsig = transaction.LogicSig(program, args=[arg1]) # integer parameter # arg1 = (123).to_bytes(8, 'big') # lsig = transaction.LogicSig(program, args=[arg1]) sender = lsig.address() #Recover the account that is wanting to delegate signature passphrase = "canal enact luggage spring similar zoo couple stomach shoe laptop middle wonder eager monitor weather number heavy skirt siren purity spell maze warfare ability ten" # passphrase = "25-word-mnemonic<PLACEHOLDER>" sk = mnemonic.to_private_key(passphrase) addr = account.address_from_private_key(sk) print("Address of Sender/Delegator: " + addr) # sign the logic signature with an account sk lsig.sign(sk) # get suggested parameters params = algod_client.suggested_params() # comment out the next two (2) lines to use suggested fees params.flat_fee = True
def main_pub(passphrase, proj_name, vol, url, par, coupon, payment_id, closure, start_round, period, total_payments, span, hold_up, client): # ensuring that buyer will be able to claim coupon on start_round add = mnemonic.to_public_key(passphrase) key = mnemonic.to_private_key(passphrase) print("Checking configurations......") print("--------------------------------------------") cl = client if start_round % period != 0: start_round = (start_round + period) - (start_round % period) print("Start round for interest payment refactored to {}".format( start_round)) end_round = start_round + (total_payments - 1) * period print("--------------------------------------------") # issuance of tokens print("Issuing tokens......") print("--------------------------------------------") try: interest_txid, interest_id = interest_token_issuance( cl, passphrase, proj_name, vol, url, total_payments) par_txid, par_id = par_token_issuance(cl, passphrase, proj_name, vol, url) except Exception as e: print("Issuance failed :{}".format(e)) return print("Issued tokens successfully") print("Interest token id: {}, recorded in {}".format( interest_id, interest_txid)) print("Par token id: {}, recorded in {}".format(par_id, par_txid)) print("--------------------------------------------") # creating escrow account print("--------------------------------------------") print("Creating escrow account......") try: escrow_result, escrow_id = create_escrow(add, proj_name, interest_id, par_id, payment_id, closure, start_round, end_round, par, coupon, total_payments, period, span, hold_up, cl) except Exception as e: print("Escrow account creation failed :{}".format(e)) return print("Created escrow account successfully") print("Escrow account result :{}".format(escrow_result)) print("Escrow account public address: {}".format(escrow_id)) print("--------------------------------------------") # activating escrow account print("--------------------------------------------") print("Activating escrow account......") try: txn = payment_transaction(passphrase, 1000000, escrow_id, cl) except Exception as e: print("Activation failed :{}".format(e)) return print("Activated successfully") print(txn) print("--------------------------------------------") # opt-in the escrow account for interest token print("--------------------------------------------") print("Opt-in for interest token......") try: program_str = escrow_result.encode() program = base64.decodebytes(program_str) arg1 = (0).to_bytes(8, 'big') lsig = LogicSig(program, [arg1]) sp = cl.suggested_params() atn = AssetTransferTxn(lsig.address(), sp, lsig.address(), 0, interest_id) lstx = LogicSigTransaction(atn, lsig) txid = cl.send_transaction(lstx) msg = wait_for_confirmation(cl, txid, 5) except Exception as e: print("Opt-in interest token failed :{}".format(e)) return print("Opt-in interest token success!") print(msg) print("--------------------------------------------") # opt-in the escrow account for par token print("--------------------------------------------") print("Opt-in for par token......") try: program_str = escrow_result.encode() program = base64.decodebytes(program_str) arg1 = (1).to_bytes(8, 'big') lsig = LogicSig(program, [arg1]) sp = cl.suggested_params() atn = AssetTransferTxn(lsig.address(), sp, lsig.address(), 0, par_id) lstx = LogicSigTransaction(atn, lsig) txid = cl.send_transaction(lstx) msg = wait_for_confirmation(cl, txid, 5) except Exception as e: print("Opt-in par token failed :{}".format(e)) return print("Opt-in par token success!") print(msg) print("--------------------------------------------") # opt-in the escrow account for payment token print("--------------------------------------------") print("Opt-in for payment token......") try: program_str = escrow_result.encode() program = base64.decodebytes(program_str) arg1 = (6).to_bytes(8, 'big') lsig = LogicSig(program, [arg1]) sp = cl.suggested_params() atn = AssetTransferTxn(lsig.address(), sp, lsig.address(), 0, payment_id) lstx = LogicSigTransaction(atn, lsig) txid = cl.send_transaction(lstx) msg = wait_for_confirmation(cl, txid, 5) except Exception as e: print("Opt-in payment token failed :{}".format(e)) return print("Opt-in payment token success!") print(msg) print("--------------------------------------------") # transferring the interest tokens to escrow account print("--------------------------------------------") print("Transfer interest token to escrow account......") try: atn = asset_transaction(passphrase, vol * total_payments, escrow_id, interest_id, cl) except Exception as e: print("Transferred interest token failed :{}".format(e)) return print("Transferred interest token successfully") print(atn) print("--------------------------------------------") # transferring the par tokens to escrow account print("--------------------------------------------") print("Transfer par token to escrow account......") try: atn = asset_transaction(passphrase, vol, escrow_id, par_id, cl) except Exception as e: print("Transferred par token failed :{}".format(e)) return print("Transferred par token successfully") print(atn) print("--------------------------------------------") print("Setup-complete!") return interest_id, par_id, escrow_result, escrow_id