GithubHelp home page GithubHelp logo

priegle / steal Goto Github PK

View Code? Open in Web Editor NEW

This project forked from derbear/steal

0.0 0.0 0.0 90 KB

S-expression syntax sugar for Algorand TEAL contracts

License: GNU Affero General Public License v3.0

Racket 100.00%

steal's Introduction

sTEAL

sTEAL provides syntactic sugar for Algorand TEAL contracts, embedded in Scheme.

Use

Basic

Let's say we have the following sTEAL contract code:

(define sample '(= (txn Sender)
                   (txn Receiver)))

We can use the sTEAL compiler stealc to make TEAL assembly code. If we have the following code in example.rkt

#lang racket
(require "stealc.rkt")

(define sample '(= (txn Sender)
                   (txn Receiver)))

(displayln (stealc sample))

then running this program produces

$ racket example.rkt
txn Sender
txn Receiver
==

Template arguments

sTEAL can be used to make templates for TEAL contracts.

#lang racket
(require "stealc.rkt")

(define sample '(= (addr TMPL_RCV)
                   (txn Receiver)))

(displayln (stealc sample))

produces

addr TMPL_RCV
txn Receiver
==

To instantiate the templates with conrete values, use stealc-bind:

#lang racket
(require "stealc.rkt")

(define sample '(= (addr TMPL_RCV)
                   (txn Receiver)))

(define args
  '((TMPL_RCV "YC3XWSU3EUISB6N4EOGW5NYEMDSSWPGPMN3ZOKD33UDKPNK2HIXYPFLVXQ")))

(displayln (stealc (stealc-bind sample args)))

produces

addr YC3XWSU3EUISB6N4EOGW5NYEMDSSWPGPMN3ZOKD33UDKPNK2HIXYPFLVXQ
txn Receiver
==

Notes

Variable-length arguments

Certain symbols, such as and, compile into TEAL expressions that accept a variable number of arguments.

'(and (= (+ (txn FirstValid) (txn LastValid)) 500)
      (= arg_0 (byte base64 "uFVEhjBpkpKQ8sZaau0qsDsf0eW3oXFEn1Ar5o39vkk="))
      (> (txn Fee) (int TMPL_FEE)))

compiles into

txn FirstValid
txn LastValid
+
int 500
==
arg_0
byte base64 uFVEhjBpkpKQ8sZaau0qsDsf0eW3oXFEn1Ar5o39vkk=
==
&&
txn Fee
int TMPL_FEE
>
&&

Short-circuiting

Note that the and and or operators do not short-circuit as they do in Scheme.

The if symbol produces TEAL code which behaves similarly to Scheme's if special form.

'(if (= (global GroupSize) 1)
     (= (txn GroupIndex) 6)
     (< (txn Amount) 500))

compiles into

global GroupSize
int 1
==
bnz label0
txn Amount
int 500
<
int 1
bnz label1
label0:
txn GroupIndex
int 6
==
label1:

The labels produced in such a way are all unique.

steal's People

Contributors

derbear avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.