Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pyteal atomic transfer

# This example is provided for informational purposes only and has not been audited for security.

from pyteal import *

"""Atomic Swap"""

alice = Addr("6ZHGHH5Z5CTPCF5WCESXMGRSVK7QJETR63M3NY5FJCUYDHO57VTCMJOBGY")
bob = Addr("7Z5PWO2C6LFNQFGHWKSK5H47IQP5OJW2M3HA2QPXTY3WTNP5NU2MHBW27M")
secret = Bytes("base32", "2323232323232323")
timeout = 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)
    safety_cond = And(
        Txn.type_enum() == TxnType.Payment,
        Txn.close_remainder_to() == Global.zero_address(),
        Txn.rekey_to() == Global.zero_address(),
    )

    recv_cond = And(Txn.receiver() == tmpl_seller, tmpl_hash_fn(Arg(0)) == tmpl_secret)

    esc_cond = And(Txn.receiver() == tmpl_buyer, Txn.first_valid() > Int(tmpl_timeout))

    return And(fee_cond, safety_cond, Or(recv_cond, esc_cond))


if __name__ == "__main__":
    print(compileTeal(htlc(), mode=Mode.Signature, version=2))
Comment

PREVIOUS NEXT
Code Example
Python :: how to get key stroke pygame 
Python :: timestamp from date python 
Python :: python ravel function output 
Python :: python import problem fix 
Python :: build the .pyx file to c and run on python 
Python :: python certain charaacter in string 
Python :: stack overflow pop item from list in python 
Python :: url encoding in python 
Python :: custom save method django 
Python :: alignment to numpy array 
Python :: csv file python 
Python :: rmtree (remove tree) example 
Python :: normalize a distribution plot 
Python :: get predict proba category order 
Python :: check if varible is emyt pyton 
Python :: Convert PySpark RDD to DataFrame 
Python :: numpy retrieve 5 highest value index 
Python :: python yellow 
Python :: find if string is substring of another 
Python :: while except python 
Python :: ValueError: minvalue must be less than or equal to maxvalue 
Python :: slice all elements from list 
Python :: how to get 2 values form a dictionary in python 
Python :: python file operation 
Python :: cgi in python; get() method 
Python :: read://https_www.tumblr.com/?url=https://www.tumblr.com/login?redirect_to=%2Fneue_web%2Fiframe%2Freblog%2F629907744681590784%2FjQw7OUs8&3739a18c-0c68-43cc-a4cb-b8b99e9bfd72=a52e06db-92b6-4b86-b3c5-fa2ab267405c 
Python :: internet spam 
Python :: how to write statements in python 
Python :: python inline print variable 
Python :: load pandas dataframe with one row per line and 1 column no delimiter 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =