Skip to content

Commit

Permalink
update atomic swap
Browse files Browse the repository at this point in the history
  • Loading branch information
stechu committed May 1, 2020
1 parent 935bbe4 commit 23c35ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
29 changes: 19 additions & 10 deletions examples/atomic_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@
alice = Addr("6ZHGHH5Z5CTPCF5WCESXMGRSVK7QJETR63M3NY5FJCUYDHO57VTCMJOBGY")
bob = Addr("7Z5PWO2C6LFNQFGHWKSK5H47IQP5OJW2M3HA2QPXTY3WTNP5NU2MHBW27M")
secret = Bytes("base32", "23232323232323")
timeout = 3000

fee_cond = Txn.fee() < Int(1000)
type_cond = Txn.type_enum() == Int(1)
recv_cond = (Txn.close_remainder_to() == Global.zero_address()).And(
Txn.receiver() == alice).And(
Sha256(Arg(0)) == secret)
esc_cond = (Txn.close_remainder_to() == Global.zero_address()).And(
Txn.receiver() == bob).And(
Txn.first_valid() > Int(3000))
def htlc(tmpl_seller=alice,
tmpl_buyer=bob,
tmpl_fee=1000,
tmpl_secret=secret,
tmpl_hash_fn=Sha256,
tmpl_timeout=timeout):
fee_cond = Txn.fee() < Int(tmpl_fee)
type_cond = Txn.type_enum() == Int(1)
recv_cond = And(Txn.close_remainder_to() == Global.zero_address(),
Txn.receiver() == tmpl_seller,
Sha256(Arg(0)) == tmpl_secret)
esc_cond = And(Txn.close_remainder_to() == Global.zero_address(),
Txn.receiver() == tmpl_buyer,
Txn.first_valid() > Int(tmpl_timeout))

atomic_swap = fee_cond.And(type_cond).And(recv_cond.Or(esc_cond))
return And(fee_cond,
type_cond,
Or(recv_cond, esc_cond))

print(atomic_swap.teal())
print(htlc().teal())
4 changes: 4 additions & 0 deletions examples/periodic_payment_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@
print("Transaction ID: " + txid )
# except Exception as e:
# print(e)

# send raw LogicSigTransaction again to network
txid = acl.send_transaction(lstx)
print("Transaction ID: " + txid )

0 comments on commit 23c35ea

Please sign in to comment.