passphrase="extra hungry share oblige water equip slender surround quality jeans harbor liquid trade labor rapid polar length awake deposit pass success soul night absorb river" ************************************************************************************************************************************************************************************************* passphrase=" maze huge bronze student orphan news weasel cable column chaos project friend prefer demand bind frame total muffin exist acid unfold toddler era abstract soap" KNRTFTRSTNTG7AC5GUJFEWMAF3LMDK4IFIVN5O72PQXF3U5X6Z26DNJ4SQ ********************************************************************************************************************************************************************************* passphrase ="long bench click shift pact lizard explain violin pizza planet left speed glow pencil endless farm taste sense gauge angry demand whip broom able machine"(su) UW2GFXFO7GLP5Z2PAI3ALODDXEVPTXQSZZ6AIYHPNJUMZ4P52OE4QPF7BE ************************************************************************************************************************************************************************************* passphrase ="acid later donor solve trigger farm profit mutual never carry certain razor neither party dolphin suffer poet hawk argue frame alien sibling hotel absorb rubber"(bab) D2PT3PFCLRUASHE7OHHHNFSZIXWBEDWSOEDTL5TVYSWDKW2SFFHSL6DAY4 ********************************************************************************************************************************************************************************************* passphras="book adult apart security sign bid acid trend kitten stove volcano coconut before exhaust calm apart truck inspire hair now alien across water ability key"(babloo1) RB232H7I6YX34CX3EIICYPHT2A64GAQLZC7YCHNKPWGB4GJMADWBGZBSMA ******************************************************************************************************************************************************************************************* passphrase="develop menu torch front wish stem ski again general where rule castle virus expire suit minimum duty recycle seat chunk advice imitate journey ability calm" passphrase="polar curtain tenant usual boy hamster arctic design flock ride soul good smoke frown buzz potato outside put either shadow visa rapid holiday absent brain" passphrase = "canoe sustain edge prepare burden imitate swamp pepper fox decide weather banner remain viable connect sniff unaware arrange peanut matter young mule genius above stumble" =======================================================================================================================================================================================================from pyteal import * vtc contract def clear_app(): return Approve() def approve_app(): on_create = Seq( [ App.globalPut(Bytes("owner"), Global.creator_address()), App.globalPut(Bytes("task_id"), Txn.application_args[0] ), App.globalPut(Bytes("client_address"), Txn.accounts[1]), App.globalPut(Bytes("worker_address"), Txn.accounts[2]), App.globalPut(Bytes("review_address"), Global.creator_address()), App.globalPut(Bytes("no_of_Algos"),Txn.application_args[1]), Approve(), ]) on_update = Seq( Assert(Txn.sender()== App.globalGet(Bytes("owner"))), Approve(), ) on_delete = Seq( Assert(Txn.sender()== App.globalGet(Bytes("owner"))), Approve(), ) on_optin = Seq(Approve()) on_closeout = Seq( Reject() ) set_reviewer=Seq( Assert(Txn.sender() == App.globalGet(Bytes("owner"))), App.globalPut(Bytes("review_address"), Txn.accounts[1]), Approve(), ) # verification_task_completed = Seq([ # Assert( # And( # Or( # Txn.sender() == App.globalGet(Bytes("review_address")), # Txn.sender() == App.globalGet(Bytes("owner")), # ), # Txn.accounts[2]==App.globalGet(Bytes("worker_address")), # Global.group_size() == Int(1), # Txn.rekey_to() == Global.zero_address(), # ) # ), # InnerTxnBuilder.Begin(), # InnerTxnBuilder.SetFields({ # TxnField.type_enum: TxnType.Payment, # TxnField.receiver: Txn.accounts[2], # TxnField.amount:(Btoi(Txn.application_args[1]))*(Btoi(App.globalGet(Bytes("no_of_Algos"))))/Int(100) - Global.min_balance()-(Btoi(App.globalGet(Bytes("no_of_Algos")))*Int(5) / Int(100)), # }), # InnerTxnBuilder.Submit(), # InnerTxnBuilder.Begin(), # InnerTxnBuilder.SetFields({ # TxnField.type_enum: TxnType.Payment, # TxnField.receiver: Global.creator_address(), # TxnField.amount: ( Btoi(App.globalGet(Bytes("no_of_Algos")))*Int(5) / Int(100)), # TxnField.close_remainder_to:Txn.accounts[1], # }), # InnerTxnBuilder.Submit(), # Approve(), # ]) verification_task_completed = Seq([ Assert( And( Or( Txn.sender() == App.globalGet(Bytes("review_address")), Txn.sender() == App.globalGet(Bytes("owner")), ), Txn.accounts[1]==App.globalGet(Bytes("worker_address")), Global.group_size() == Int(1), Txn.rekey_to() == Global.zero_address(), ) ), If(Txn.application_args[1]==(Bytes("algos"))) .Then( InnerTxnBuilder.Begin(), InnerTxnBuilder.SetFields({ TxnField.type_enum: TxnType.Payment, TxnField.receiver: Txn.accounts[1], # Worker Address TxnField.amount: ((Btoi(App.globalGet(Bytes("no_of_Algos")))) -( Global.min_balance() + ((Btoi(App.globalGet(Bytes("no_of_Algos")))*(Int(5)) / Int(100))))), }), InnerTxnBuilder.Submit(), InnerTxnBuilder.Begin(), InnerTxnBuilder.SetFields({ TxnField.type_enum: TxnType.Payment, TxnField.receiver: Global.creator_address(), # SC OWNER TxnField.amount: (Btoi(App.globalGet(Bytes("no_of_Algos")))*(Int(5) / Int(100))), TxnField.close_remainder_to:Txn.accounts[1], # Client Address }), InnerTxnBuilder.Submit(), ) .Else( InnerTxnBuilder.Begin(), InnerTxnBuilder.SetFields({ TxnField.type_enum: TxnType.Payment, TxnField.close_remainder_to:Global.creator_address(), }), InnerTxnBuilder.Submit(), ), Approve(), ]) verification_task_not_completed = Seq([ Assert( And( Or( Txn.sender() == App.globalGet(Bytes("review_address")), Txn.sender() == App.globalGet(Bytes("owner")), ), Txn.accounts[1]==App.globalGet(Bytes("client_address")), Global.group_size() == Int(1), Txn.rekey_to() == Global.zero_address(), ) ), InnerTxnBuilder.Begin(), InnerTxnBuilder.SetFields({ TxnField.type_enum: TxnType.Payment, TxnField.receiver: Txn.accounts[1], TxnField.amount: Btoi(App.globalGet(Bytes("no_of_Algos")))-Global.min_balance(), TxnField.close_remainder_to:Global.creator_address(), }), InnerTxnBuilder.Submit(), Approve(), ] ) optin = Seq([ InnerTxnBuilder.Begin(), InnerTxnBuilder.SetFields({ TxnField.type_enum: TxnType.AssetTransfer, # TxnField.asset_sender: Global.current_application_address(), TxnField.asset_receiver: Global.current_application_address(), TxnField.asset_amount: Int(0), TxnField.xfer_asset : Txn.assets[0], }), InnerTxnBuilder.Submit(), Approve(), ]) return Cond( [Txn.application_id() == Int(0), on_create], [Txn.on_completion() == OnComplete.UpdateApplication, on_update], [Txn.on_completion() == OnComplete.DeleteApplication, on_delete], [Txn.on_completion() == OnComplete.OptIn,on_optin], [Txn.on_completion() == OnComplete.CloseOut, on_closeout], [Txn.application_args[0] == Bytes("add_reviewer"),set_reviewer], [Txn.application_args[0] == Bytes("vtc"),verification_task_completed], [Txn.application_args[0] == Bytes("vtnc"),verification_task_not_completed], [Txn.application_args[0] == Bytes("optin"),optin], ) with open("approve.teal","w") as f: approve_teal= compileTeal(approve_app(), Mode.Application, version=5) f.write(approve_teal) with open("clear.teal","w") as f: clear_teal= compileTeal(clear_app(), Mode.Application, version=5) f.write(clear_teal) =============================================================================================================================================================================================== deploy ======== import base64 from algosdk import account, mnemonic from algosdk.v2client import algod from algosdk.future import transaction from algosdk.logic import get_application_address import base64 algod_address = "https://testnet-api.algonode.cloud" algod_token = "" algod_client = algod.AlgodClient(algod_token, algod_address) ### DEPLOY SMART CONTRACT ### def deploy(owner_passphrase,task_id,no_of_algos,client_address,worker_address): owner = mnemonic.to_public_key(owner_passphrase) private_key = mnemonic.to_private_key(owner_passphrase) params = algod_client.suggested_params() local_ints = 0 local_bytes = 0 global_ints = 1 global_bytes = 6 global_schema = transaction.StateSchema(global_ints, global_bytes) local_schema = transaction.StateSchema(local_ints, local_bytes) with open("approve.teal","r") as f: approval_program =f.read() with open("clear.teal","r") as f: clear_state_program =f.read() app_response = algod_client.compile(approval_program) rej_response = algod_client.compile(clear_state_program) on_complete = transaction.OnComplete.NoOpOC.real txn = transaction.ApplicationCreateTxn( owner, params, on_complete, base64.b64decode(app_response["result"]), base64.b64decode(rej_response["result"]), global_schema, local_schema, app_args=[task_id,no_of_algos], accounts=[client_address,worker_address] ) # sign transaction signed_txn = txn.sign(private_key) txId = signed_txn.transaction.get_txid() # send transaction algod_client.send_transactions([signed_txn]) # wait for confirmation try: transaction_response = transaction.wait_for_confirmation(algod_client, txId, 1000) # display results transaction_response = algod_client.pending_transaction_info(txId) app_id = transaction_response['application-index'] Contract_Address = get_application_address(app_id) print("TXID: ", txId) print("Result confirmed in round: {}".format(transaction_response['confirmed-round'])) print("----------------------------Application Deployed----------------------------") return {'status':True,'sc_add':Contract_Address,'owner_add':owner,'app_id':app_id} except Exception as err: return {'status':False,'ERROR':err} data=deploy(" maze huge bronze student orphan news weasel cable column chaos project friend prefer demand bind frame total muffin exist acid unfold toddler era abstract soap","task344",5000000,"D2PT3PFCLRUASHE7OHHHNFSZIXWBEDWSOEDTL5TVYSWDKW2SFFHSL6DAY4","UW2GFXFO7GLP5Z2PAI3ALODDXEVPTXQSZZ6AIYHPNJUMZ4P52OE4QPF7BE") print(data) =================================================================================================================================================================================== import base64 from algosdk import account, mnemonic from algosdk.v2client import algod from algosdk.future import transaction from algosdk.logic import get_application_address import base64 algod_address = "https://testnet-api.algonode.cloud" algod_token = "" algod_client = algod.AlgodClient(algod_token, algod_address) ### DEPLOY SMART CONTRACT ### def deploy(owner_passphrase,task_id,no_of_algos,client_address,worker_address): owner = mnemonic.to_public_key(owner_passphrase) private_key = mnemonic.to_private_key(owner_passphrase) params = algod_client.suggested_params() local_ints = 0 local_bytes = 0 global_ints = 1 global_bytes = 6 global_schema = transaction.StateSchema(global_ints, global_bytes) local_schema = transaction.StateSchema(local_ints, local_bytes) with open("approve.teal","r") as f: approval_program =f.read() with open("clear.teal","r") as f: clear_state_program =f.read() app_response = algod_client.compile(approval_program) rej_response = algod_client.compile(clear_state_program) on_complete = transaction.OnComplete.NoOpOC.real txn = transaction.ApplicationCreateTxn( owner, params, on_complete, base64.b64decode(app_response["result"]), base64.b64decode(rej_response["result"]), global_schema, local_schema, app_args=[task_id,no_of_algos], accounts=[client_address,worker_address] ) # sign transaction signed_txn = txn.sign(private_key) txId = signed_txn.transaction.get_txid() # send transaction algod_client.send_transactions([signed_txn]) # wait for confirmation try: transaction_response = transaction.wait_for_confirmation(algod_client, txId, 1000) # display results transaction_response = algod_client.pending_transaction_info(txId) app_id = transaction_response['application-index'] Contract_Address = get_application_address(app_id) print("TXID: ", txId) print("Result confirmed in round: {}".format(transaction_response['confirmed-round'])) print("----------------------------Application Deployed----------------------------") return {'status':True,'sc_add':Contract_Address,'owner_add':owner,'app_id':app_id} except Exception as err: return {'status':False,'ERROR':err} def payAlgos(app_id,passphrase,no_of_algos): sender = mnemonic.to_public_key(passphrase) private_key = mnemonic.to_private_key(passphrase) params = algod_client.suggested_params() # create unsigned transaction txn = transaction.PaymentTxn( sender, params, amt=no_of_algos, receiver=get_application_address(app_id), ) # sign transaction signed_txn = txn.sign(private_key) try: txId = signed_txn.transaction.get_txid() # send transaction txId =algod_client.send_transactions([signed_txn]) # await confirmation transaction.wait_for_confirmation(algod_client, txId,1000) # display results return {'status':True,'Algos_deposited_into_application_by':sender} except Exception as err: return {'status':False,'ERROR':err} # def optin(index,passphrase): # # declare sender # private_key = mnemonic.to_private_key(passphrase) # sender = account.address_from_private_key(private_key) # algod_client = algod.AlgodClient(algod_token, algod_address) # print("OptIn from account: ", sender) # # get node suggested parameters # params = algod_client.suggested_params() # # comment out the next two (2) lines to use suggested fees # params.flat_fee = True # params.fee = 1000 # # Email ="Enter your Email Here" # # Account = "SVIBHXXDWUFFCDTL2GXVFLFQJJNVA5OYKWRM2SPXY5OPTZTQXE7GCREXBA" # # create unsigned transaction # txn = transaction.ApplicationOptInTxn(sender, params, index) # # sign transaction # signed_txn = txn.sign(private_key) # tx_id = signed_txn.transaction.get_txid() # # send transaction # algod_client.send_transactions([signed_txn]) # # await confirmation # transaction.wait_for_confirmation(algod_client, tx_id) # # display results # transaction_response = algod_client.pending_transaction_info(tx_id) # print("Opted to App ID:", transaction_response["txn"]["txn"]["apid"]) def setReviewer(app_id,passphrase,reviewer_address): sender = mnemonic.to_public_key(passphrase) private_key = mnemonic.to_private_key(passphrase) params = algod_client.suggested_params() # create unsigned transaction txn = transaction.ApplicationNoOpTxn( sender, params, index=app_id, app_args=["add_reviewer"], accounts=[reviewer_address] ) # sign transaction signed_txn = txn.sign(private_key) try: txId = signed_txn.transaction.get_txid() # send transaction txId =algod_client.send_transactions([signed_txn]) # await confirmation transaction.wait_for_confirmation(algod_client, txId,4) # display results # print("Reviewer_added") return {'status': True,'Reviewer_address_is':reviewer_address} except Exception as err: return {'status': False,'err':err} def vtc(app_id,passphrase,worker_address,client_address,percentage): sender = mnemonic.to_public_key(passphrase) private_key = mnemonic.to_private_key(passphrase) params = algod_client.suggested_params() # create unsigned transaction txn = transaction.ApplicationNoOpTxn( sender, params, index=app_id, app_args=["vtc",percentage], accounts=[client_address,worker_address] ## SHOULD GIVE WORKER ADDRESS ONLY ) # sign transaction signed_txn = txn.sign(private_key) try: txId = signed_txn.transaction.get_txid() # send transaction txId =algod_client.send_transactions([signed_txn]) # await confirmation transaction.wait_for_confirmation(algod_client, txId,4) # display results # print("Reviewer_added") return {'status': True,'reward_sent_to':worker_address} except Exception as err: return {'status': False,'err':err} def vtnc(app_id,passphrase,client_address): sender = mnemonic.to_public_key(passphrase) private_key = mnemonic.to_private_key(passphrase) params = algod_client.suggested_params() # create unsigned transaction txn = transaction.ApplicationNoOpTxn( sender, params, index=app_id, app_args=["vtnc"], accounts=[client_address] # SHOULD GIVE CLIENT ADD ONLY ) signed_txn = txn.sign(private_key) try: txId = signed_txn.transaction.get_txid() # send transaction txId =algod_client.send_transactions([signed_txn]) # await confirmation transaction.wait_for_confirmation(algod_client, txId,4) return {'status': True,'reward_sent_back_to':client_address} except Exception as err: return {'status': False,'err':err} # owner # senior rural about innocent soap require dish dial kiwi remove final shoe this quarter latin belt sunny blue sock enroll jealous tank gadget absorb pass # TYHWTKNXZCL6EQJOGM6CI43XCWBR4DKHBKIHOXP27GPSBPC4YNQ3NZWOQ4 # worker # eagle believe hurt lunar cheap furnace toss normal other fix analyst stick board car trouble kite ramp stuff canoe flat enough version match able unable # UFDXYZ7UN7CD457QIAYBY7E3QLTME7MFNFOW3GG2U4A6QSFET22ATMSYPU # client # entire please game large slim awful almost erase speed iron enter adjust coral evolve card ready village blade click hour orange scorpion tuition abandon fury # WP6QLQHU7IYKTQWQPOJ57W6DIUWATQE2W7KUKM4FWOE3QZE6272CQLYKMA # data= deploy("senior rural about innocent soap require dish dial kiwi remove final shoe this quarter latin belt sunny blue sock enroll jealous tank gadget absorb pass","task007",5000000,"WP6QLQHU7IYKTQWQPOJ57W6DIUWATQE2W7KUKM4FWOE3QZE6272CQLYKMA","UFDXYZ7UN7CD457QIAYBY7E3QLTME7MFNFOW3GG2U4A6QSFET22ATMSYPU") # print(data) # data=payAlgos(150551419,"entire please game large slim awful almost erase speed iron enter adjust coral evolve card ready village blade click hour orange scorpion tuition abandon fury",5000000) # print(data) # data = setReviewer(150551419,"senior rural about innocent soap require dish dial kiwi remove final shoe this quarter latin belt sunny blue sock enroll jealous tank gadget absorb pass","TYHWTKNXZCL6EQJOGM6CI43XCWBR4DKHBKIHOXP27GPSBPC4YNQ3NZWOQ4") # print(data) data=vtc(150551419,"senior rural about innocent soap require dish dial kiwi remove final shoe this quarter latin belt sunny blue sock enroll jealous tank gadget absorb pass","UFDXYZ7UN7CD457QIAYBY7E3QLTME7MFNFOW3GG2U4A6QSFET22ATMSYPU","WP6QLQHU7IYKTQWQPOJ57W6DIUWATQE2W7KUKM4FWOE3QZE6272CQLYKMA",100) print(data) data=vtnc(150551419,"senior rural about innocent soap require dish dial kiwi remove final shoe this quarter latin belt sunny blue sock enroll jealous tank gadget absorb pass","WP6QLQHU7IYKTQWQPOJ57W6DIUWATQE2W7KUKM4FWOE3QZE6272CQLYKMA") print(data)