Extra operations for PyTEAL
Project description
Pyteal Extensions
Additional useful operations for Python
Available Operations
MulDiv64
: calculatem1*m2/d
with no overflow on multiplication (TEAL 3+)Min
,Max
: calculate minimum/maximum of 2 expressions, without using slots or evaluating arguments more than once (TEAL 4+)LazyAnd
,LazyOr
: lazily evaluate arguments in And/Or operation
State manipulation
GlobalState
and LocalState
allow for manipulating global and local state respectively.
They both have the same interface.
from pyteal import App, Bytes, Int, Seq, TealType
from pytealext import LocalState
user_counter = LocalState("UC", TealType.uint64)
program = Seq(
# increment using pyteal local state
App.localPut(Int(0), Bytes("UC"), App.localGet(Int(0), Bytes("UC")) + Int(1)),
# increment using put/get
user_counter.put(user_counter.get() + Int(1)),
# increment using add_assign
user_counter.add_assign(Int(1))
# decrement
user_counter.sub_assign(Int(1))
)
Example usage
Example usage for LazyAnd
:
from pyteal import Gtxn, TxnType, Bytes, Int
from pytealext import LazyAnd
# Evaluate fields of some transaction but don't panic if an argument down the line would panic
validation = LazyAnd(
Gtxn[0].type_enum() == TxnType.ApplicationCall,
Gtxn[0].application_args.length() == Int(1),
Gtxn[0].application_args[0] == Bytes("AX"),
)
Testing
pytest
Created by Łukasz Ptak and Paweł Rejkowicz
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pytealext-1.0.1.tar.gz
(17.2 kB
view hashes)
Built Distribution
pytealext-1.0.1-py3-none-any.whl
(19.0 kB
view hashes)
Close
Hashes for pytealext-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92539ce31ca494558a6efd6ee80fa3a264b8d7d10f20478ca4adcd66873a3313 |
|
MD5 | 54e15eb097ec81c1c4c028fbfdedca51 |
|
BLAKE2b-256 | 07422c00615194b543960cdf88ed247861a14d9021c50e15a8214639bb833485 |