Skip to content

Commit

Permalink
transaction and atomic transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
Shumo Chu committed Feb 4, 2020
1 parent 35d2094 commit 8c90fa5
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 13 deletions.
66 changes: 64 additions & 2 deletions docs/accessing_transaction_field.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,64 @@
Acessing Transaction Field
==========================
.. _transaction-fields:

Transaction Fields and Global Parameters
========================================

A PyTeal expression can be the value of a field of
the current transaction or the value of a global parameter.
Blow are the PyTeal expressions that refer to transaction fields:

================================= ======================= =======================================================================
Operator Type Notes
================================= ======================= =======================================================================
:code:`Txn.sender()` :code:`TealType.bytes` 32 byte address
:code:`Txn.fee()` :code:`TealType.uint64` in microAlgos
:code:`Txn.first_valid()` :code:`TealType.uint64` round number
:code:`Txn.first_valid_time()` :code:`TealType.uint64` causes program to fail, reserved for future use
:code:`Txn.last_valid()` :code:`TealType.uint64` round number
:code:`Txn.note()` :code:`TealType.bytes`
:code:`Txn.lease()` :code:`TealType.bytes`
:code:`Txn.receiver()` :code:`TealType.bytes` 32 byte address
:code:`Txn.amount()` :code:`TealType.uint64` in microAlgos
:code:`Txn.close_remainder_to()` :code:`TealType.bytes` 32 byte address
:code:`Txn.vote_pk()` :code:`TealType.bytes` 32 byte address
:code:`Txn.selection_pk()` :code:`TealType.bytes` 32 byte address
:code:`Txn.vote_first()` :code:`TealType.uint64`
:code:`Txn.vote_last()` :code:`TealType.uint64`
:code:`Txn.vote_key_dilution()` :code:`TealType.uint64`
:code:`Txn.type()` :code:`TealType.bytes`
:code:`Txn.type_enum()` :code:`TealType.uint64` see table below
:code:`Txn.xfer_asset()` :code:`TealType.uint64` asset ID
:code:`Txn.asset_amount()` :code:`TealType.uint64` value in Asset's units
:code:`Txn.asset_sender()` :code:`TealType.bytes` 32 byte address, causes clawback of all value if sender is the Clawback
:code:`Txn.asset_receiver()` :code:`TealType.bytes` 32 byte address
:code:`Txn.asset_close_to()` :code:`TealType.bytes` 32 byte address
:code:`Txn.group_index()` :code:`TealType.uint64` position of this transaction within a transaction group
:code:`Txn.tx_id()` :code:`TealType.bytes` the computed ID for this transaction, 32 bytes
================================= ======================= =======================================================================

:code:`Txn.type_enum()` values:

============== ============ =========================
Value Type String Description
============== ============ =========================
:code:`Int(0)` unkown unknown type, invalid
:code:`Int(1)` pay payment
:code:`Int(2)` keyreg key registration
:code:`Int(3)` acfg asset config
:code:`Int(4)` axfer asset transfer
:code:`Int(5)` afrz asset freeze
============== ============ =========================

PyTeal expressions that refer to global parameters:

============================== ======================= ============================================================
Operator Type Notes
============================== ======================= ============================================================
:code:`Global.min_txn_fee()` :code:`TealType.uint64` in microAlgos
:code:`Global.min_balance()` :code:`TealType.uint64` in mircoAlgos
:code:`Global.max_txn_life()` :code:`TealType.uint64` number of rounds
:code:`Global.zero_address()` :code:`TealType.bytes` 32 byte address of all zero bytes
:code:`Global.group_size()` :code:`TealType.uint64` number of txns in this atomic transaction group, At least 1
============================== ======================= ============================================================


24 changes: 13 additions & 11 deletions docs/arithmetic_expression.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
.. _arithmetic_expressions:

Arithmetic Expressions
======================
Arithmetic Operators
====================

An arithmetic expression is an expression that results in a :code:`TealType.uint64` value.
In PyTeal, arithmetic expressions include integer arithmetics operators and boolean operators.
We overloaded all integer arithmetics operator in Python.

==================== =========== ================================================= =========================
==================== =========== ================================================= ===========================
Operator Overloaded Semantics Example
==================== =========== ================================================= =========================
==================== =========== ================================================= ===========================
:code:`Lt(a, b)` :code:`<` `1` if a is less than b, `0` otherwise :code:`Int(1) < Int(5)`
:code:`Gt(a, b)` :code:`>` `1` if a is greater than b, `0` otherwise :code:`Int(1) > Int(5)`
:code:`Le(a, b)` :code:`<=` `1` if a is no greater than b, `0` otherwise :code:`Int(1) <= Int(5)`
Expand All @@ -20,20 +20,22 @@ Operator Overloaded Semantics
:code:`Div(a, b)` :code:`/` `a / b`, error if devided by zero :code:`Int(3) / Int(2)`
:code:`Mod(a, b)` :code:`%` `a % b`, modulo operation :code:`Int(7) % Int(3)`
:code:`Eq(a, b)` :code:`==` `1` if a equals b, `0` otherwise :code:`Int(7) == Int(7)`
==================== =========== ================================================= =========================

:code:`And(a, b)` `1` if `a > 0 && b > 0`, `0` otherwise :code:`And(Int(1), Int(1))`
:code:`Or(a, b)` `1` if `a > 0 || b > 0`, `0` otherwise :code:`Or(Int(1), Int(0))`
==================== =========== ================================================= ===========================

All these operators takes two :code:`TealType.uint64` values.
In addition, :code:`Eq(a, b)` (:code:`==`) is polymorphic:
it also takes two `TealType.bytes` values. For example, :code:`Arg(0) == Arg(1)` is a valid PyTeal expression.

While using overloaded Python arithmatic operators, the associativity and precedence is the same as the
Both :code:`And` and :code:`Or` also support more than 2 arguements:

* :code:`And(a, b, ...)`
* :code:`Or(a, b, ...)`

The associativity and precedence of the overloaded Python arithmatic operators are the same as the
`original python operators <https://docs.python.org/3/reference/expressions.html#operator-precedence>`_ . For example:

* :code:`Int(1) + Int(2) + Int(3)` is equivalent to :code:`Add(Add(Int(1), Int(2)), Int(3))`
* :code:`Int(1) + Int(2) * Int(3)` is equivalent to :code:`Add(Int(1), Mul(Int(2), Int(3)))`





46 changes: 46 additions & 0 deletions docs/atomic_transfer.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,48 @@
.. _atomic_transfer:

Atomic Transfer
===============

`Atomic Transfer <https://developer.algorand.org/docs/atomic-transfers>`_ are irreducible batch transactions
that allow groups of transactions to be submitted at one time.
If any of the transactions fail, then all the transactions will fail.
PyTeal uses :code:`Gtxn` operator to access transactions in an atomic transfer.
For example: ::

Gtxn.sender(1)

gets the sender of the second (Atomic Transfers are 0 indexed) transaction in the atomic transaction group.

List of :code:`Gtxn` operators:

=================================== ======================= =======================================================================
Operator Type Notes
=================================== ======================= =======================================================================
:code:`Gtxn.sender(n)` :code:`TealType.bytes` 32 byte address
:code:`Gtxn.fee(n)` :code:`TealType.uint64` in microAlgos
:code:`Gtxn.first_valid(n)` :code:`TealType.uint64` round number
:code:`Gtxn.first_valid_time(n)` :code:`TealType.uint64` causes program to fail, reserved for future use
:code:`Gtxn.last_valid(n)` :code:`TealType.uint64` round number
:code:`Gtxn.note(n)` :code:`TealType.bytes`
:code:`Gtxn.lease(n)` :code:`TealType.bytes`
:code:`Gtxn.receiver(n)` :code:`TealType.bytes` 32 byte address
:code:`Gtxn.amount(n)` :code:`TealType.uint64` in microAlgos
:code:`Gtxn.close_remainder_to(n)` :code:`TealType.bytes` 32 byte address
:code:`Gtxn.vote_pk(n)` :code:`TealType.bytes` 32 byte address
:code:`Gtxn.selection_pk(n)` :code:`TealType.bytes` 32 byte address
:code:`Gtxn.vote_first(n)` :code:`TealType.uint64`
:code:`Gtxn.vote_last(n)` :code:`TealType.uint64`
:code:`Gtxn.vote_key_dilution(n)` :code:`TealType.uint64`
:code:`Gtxn.type(n)` :code:`TealType.bytes`
:code:`Gtxn.type_enum(n)` :code:`TealType.uint64` see table below
:code:`Gtxn.xfer_asset(n)` :code:`TealType.uint64` asset ID
:code:`Gtxn.asset_amount(n)` :code:`TealType.uint64` value in Asset's units
:code:`Gtxn.asset_sender(n)` :code:`TealType.bytes` 32 byte address, causes clawback of all value if sender is the Clawback
:code:`Gtxn.asset_receiver(n)` :code:`TealType.bytes` 32 byte address
:code:`Gtxn.asset_close_to(n)` :code:`TealType.bytes` 32 byte address
:code:`Gtxn.group_index(n)` :code:`TealType.uint64` position of this transaction within a transaction group
:code:`Gtxn.tx_id(n)` :code:`TealType.bytes` the computed ID for this transaction, 32 bytes
=================================== ======================= =======================================================================

where :code:`n >= 0 && n < 16`.

0 comments on commit 8c90fa5

Please sign in to comment.