Skip to content

Commit

Permalink
switch to delegate verison of periodic payment
Browse files Browse the repository at this point in the history
  • Loading branch information
stechu committed Apr 13, 2020
1 parent b42159a commit 935bbe4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
33 changes: 20 additions & 13 deletions examples/periodic_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,27 @@
tmpl_fee = Int(1000)
tmpl_period = Int(1000)
tmpl_dur = Int(1000)
tmpl_x = Bytes("base64", "y9OJ5MRLCHQj8GqbikAUKMBI7hom+SOj8dlopNdNHXI=")
tmpl_amt = Int(2000)
tmpl_lease = Bytes("base64", "y9OJ5MRLCHQj8GqbikAUKMBI7hom+SOj8dlopNdNHXI=")
tmpl_amt = Int(200000)
tmpl_rcv = Addr("ZZAF5ARA4MEC5PVDOP64JM5O5MQST63Q2KOY2FLYFLXXD3PFSNJJBYAFZM")

periodic_pay_core = And(Txn.type_enum() == Int(1),
Txn.fee() <= tmpl_fee)

periodic_pay_transfer = And(Txn.close_remainder_to() == Global.zero_address(),
Txn.receiver() == tmpl_rcv,
Txn.amount() == tmpl_amt,
Txn.first_valid() % tmpl_period == Int(0),
Txn.last_valid() == tmpl_dur + Txn.first_valid(),
Txn.lease() == tmpl_x)
def periodic_payment(tmpl_fee=tmpl_fee,
tmpl_period=tmpl_period,
tmpl_dur=tmpl_dur,
tmpl_lease=tmpl_lease,
tmpl_amt=tmpl_amt,
tmpl_rcv=tmpl_rcv):

periodic_pay = And(periodic_pay_core, periodic_pay_transfer)
periodic_pay_core = And(Txn.type_enum() == Int(1),
Txn.fee() <= tmpl_fee)

periodic_pay_transfer = And(Txn.close_remainder_to() == Global.zero_address(),
Txn.receiver() == tmpl_rcv,
Txn.amount() == tmpl_amt,
Txn.first_valid() % tmpl_period == Int(0),
Txn.last_valid() == tmpl_dur + Txn.first_valid(),
Txn.lease() == tmpl_lease)

print(periodic_pay.teal())
return And(periodic_pay_core, periodic_pay_transfer)

# print(periodic_payment().teal())
14 changes: 5 additions & 9 deletions examples/periodic_payment_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from pyteal import *
import uuid, params, base64
from algosdk import algod, transaction, account, mnemonic
from periodic_payment import periodic_pay
from periodic_payment import periodic_payment, tmpl_amt

#--------- compile & send transaction using Goal and Python SDK ----------

teal_source = periodic_pay.teal()
teal_source = periodic_payment().teal()

# compile teal
teal_file = str(uuid.uuid4()) + ".teal"
Expand Down Expand Up @@ -36,7 +36,8 @@
passphrase = "patrol crawl rule faculty enemy sick reveal embody trumpet win shy zero ill draw swim excuse tongue under exact baby moral kite spring absent double"
sk = mnemonic.to_private_key(passphrase)
addr = account.address_from_private_key(sk)
print( "Address of Sender/Delgator: " + addr )
print("Dispense at least 201000 microAlgo to {}".format(addr))
input("Make sure you did that. Press Enter to continue...")

# sign the logic signature with an account sk
lsig.sign(sk)
Expand All @@ -48,14 +49,10 @@
startRound = params["lastRound"] - (params["lastRound"] % 1000)
endRound = startRound + 1000
fee = 1000
amount = 2000
amount = 200000
receiver = "ZZAF5ARA4MEC5PVDOP64JM5O5MQST63Q2KOY2FLYFLXXD3PFSNJJBYAFZM"
lease = base64.b64decode("y9OJ5MRLCHQj8GqbikAUKMBI7hom+SOj8dlopNdNHXI=")

print(params["lastRound"])
print(startRound)
print(endRound)

# create a transaction
txn = transaction.PaymentTxn(addr, fee, startRound, endRound, gh, receiver, amount, flat_fee=True, lease=lease)

Expand All @@ -71,4 +68,3 @@
print("Transaction ID: " + txid )
# except Exception as e:
# print(e)

0 comments on commit 935bbe4

Please sign in to comment.