diff --git a/demo/Pyteal Demonstration.ipynb b/demo/Pyteal Demonstration.ipynb deleted file mode 100644 index 8ca9f5194..000000000 --- a/demo/Pyteal Demonstration.ipynb +++ /dev/null @@ -1,186 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Pyteal Working Examples" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Pyteal is a python library for Teal to help algorand developers to get easy and smooth developing experiences. It can work on its own or together with Python SDK." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### A simple pyteal program" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "txn Fee\n", - "int 300\n", - "<\n" - ] - } - ], - "source": [ - "from pyteal import *\n", - "\"\"\" fee is less than 300\n", - "\"\"\"\n", - "cond = Txn.fee() < Int(300)\n", - "print(cond.teal())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Oops, type error" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "ename": "TealTypeError", - "evalue": "Type error: TealType.bytes while expected TealType.uint64 ", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTealTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \"\"\" type error\n\u001b[1;32m 3\u001b[0m \"\"\"\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mcond\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mTxn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfee\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0mTxn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreceiver\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;32m~/work/pyteal/pyteal/expr.py\u001b[0m in \u001b[0;36m__lt__\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m 29\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__lt__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 30\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0;34m.\u001b[0m\u001b[0mops\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mLt\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 31\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mLt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 32\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 33\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__gt__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/work/pyteal/pyteal/ops.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, left, right)\u001b[0m\n\u001b[1;32m 259\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__init__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mleft\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mExpr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mright\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mExpr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 260\u001b[0m \u001b[0mrequire_type\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mleft\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtype_of\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mTealType\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muint64\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 261\u001b[0;31m \u001b[0mrequire_type\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mright\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtype_of\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mTealType\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muint64\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 262\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mleft\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mleft\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 263\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mright\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mright\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/work/pyteal/pyteal/util.py\u001b[0m in \u001b[0;36mrequire_type\u001b[0;34m(actual, expected)\u001b[0m\n\u001b[1;32m 41\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mrequire_type\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mactual\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mTealType\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexpected\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mTealType\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 42\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mactual\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0mexpected\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 43\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mTealTypeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mactual\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexpected\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 44\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 45\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mTealTypeError\u001b[0m: Type error: TealType.bytes while expected TealType.uint64 " - ] - } - ], - "source": [ - "from pyteal import *\n", - "\"\"\" type error\n", - "\"\"\"\n", - "cond = Txn.fee() < Txn.receiver()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Hased Time Locked Contract" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "txn Fee\n", - "int 300\n", - "<\n", - "txn TypeEnum\n", - "int 1\n", - "==\n", - "&&\n", - "txn CloseRemainderTo\n", - "global ZeroAddress\n", - "==\n", - "txn Receiver\n", - "addr 6ZHGHH5Z5CTPCF5WCESXMGRSVK7QJETR63M3NY5FJCUYDHO57VTCMJOBGY\n", - "==\n", - "&&\n", - "arg 0\n", - "sha256\n", - "byte base32 23232323232323\n", - "==\n", - "&&\n", - "txn CloseRemainderTo\n", - "global ZeroAddress\n", - "==\n", - "txn Receiver\n", - "addr 7Z5PWO2C6LFNQFGHWKSK5H47IQP5OJW2M3HA2QPXTY3WTNP5NU2MHBW27M\n", - "==\n", - "&&\n", - "txn FirstValid\n", - "int 3000\n", - ">\n", - "&&\n", - "||\n", - "&&\n" - ] - } - ], - "source": [ - "from pyteal import *\n", - "\n", - "\"\"\" Hashed Time Locked Contract\n", - "\"\"\"\n", - "alice = Addr(\"6ZHGHH5Z5CTPCF5WCESXMGRSVK7QJETR63M3NY5FJCUYDHO57VTCMJOBGY\")\n", - "bob = Addr(\"7Z5PWO2C6LFNQFGHWKSK5H47IQP5OJW2M3HA2QPXTY3WTNP5NU2MHBW27M\")\n", - "secret = Bytes(\"base32\", \"23232323232323\")\n", - "\n", - "fee_cond = Txn.fee() < Int(300)\n", - "type_cond = Txn.type_enum() == Int(1)\n", - "recv_cond = And(Txn.close_remainder_to() == Global.zero_address(),\n", - " Txn.receiver() == alice,\n", - " Sha256(Arg(0)) == secret)\n", - "esc_cond = And(Txn.close_remainder_to() == Global.zero_address(),\n", - " Txn.receiver() == bob,\n", - " Txn.first_valid() > Int(3000))\n", - "\n", - "atomic_swap = And(fee_cond,\n", - " type_cond,\n", - " recv_cond.Or(esc_cond)) \n", - "\n", - "print(atomic_swap.teal())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.4" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -}