Skip to content

Commit

Permalink
Documentation: Adds examples to be pulled into docs (#506)
Browse files Browse the repository at this point in the history
* starting example location

* first example working

* more examples

* adding more examples

* Adding atomic group examples

* adding asset examples

* adding codec examples

* adding indexer examples

* starting to add kmd examples

* found interface for key export

* adding kmd examples

* adding randoms

* adding participation examples

* add fee override example

* fmt

* add abi type examples

* adding example of tws in atc

* start to add app examples

* adding app examples

* Adding lsig examples

* adding dryrun examples

* shorter api keys, fix fee override

---------

Co-authored-by: egieseke <eric_gieseke@yahoo.com>
Co-authored-by: John Lee <john.lee@algorand.com>
Co-authored-by: Barbara Poon <barbara.poon@algorand.com>
Co-authored-by: Lucky Baar <lucky.baar@algorand.com>
Co-authored-by: Arthur Kepler <610274+excalq@users.noreply.github.com>
  • Loading branch information
6 people authored Mar 16, 2023
1 parent 3b32c33 commit b57b34c
Show file tree
Hide file tree
Showing 24 changed files with 2,101 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Algorand Java SDK Examples



Running
--------
Package with `mvn`
```sh
mvn package
```

Run an example with java
```sh
java -cp target/sdk-extras-1.0-SNAPSHOT.jar com.algorand.examples.Example
```
100 changes: 100 additions & 0 deletions examples/application/approval.teal
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#pragma version 4
// Handle each possible OnCompletion type. We don't have to worry about
// handling ClearState, because the ClearStateProgram will execute in that
// case, not the ApprovalProgram.
txn ApplicationID
int 0
==
bnz handle_approve

txn OnCompletion
int NoOp
==
bnz handle_noop

txn OnCompletion
int OptIn
==
bnz handle_approve

txn OnCompletion
int CloseOut
==
bnz handle_closeout

txn OnCompletion
int UpdateApplication
==
bnz handle_updateapp

txn OnCompletion
int DeleteApplication
==
bnz handle_deleteapp

// Unexpected OnCompletion value. Should be unreachable.
err

handle_noop:
// Handle NoOp

// read global state
byte "counter"
dup
app_global_get

// increment the value
int 1
+

// store to scratch space
dup
store 0

// update global state
app_global_put

// read local state for sender
int 0
byte "counter"
app_local_get

// increment the value
int 1
+
store 1

// update local state for sender
int 0
byte "counter"
load 1
app_local_put

// load return value as approval
load 0
return


handle_closeout:
// Handle CloseOut
//approval
int 1
return

handle_deleteapp:
// Check for creator
global CreatorAddress
txn Sender
==
return

handle_updateapp:
// Check for creator
global CreatorAddress
txn Sender
==
return

handle_approve:
int 1
return
107 changes: 107 additions & 0 deletions examples/application/approval_refactored.teal
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#pragma version 4
// Handle each possible OnCompletion type. We don't have to worry about
// handling ClearState, because the ClearStateProgram will execute in that
// case, not the ApprovalProgram.

txn ApplicationID
int 0
==
bnz handle_approve

txn OnCompletion
int NoOp
==
bnz handle_noop

txn OnCompletion
int OptIn
==
bnz handle_approve

txn OnCompletion
int CloseOut
==
bnz handle_closeout

txn OnCompletion
int UpdateApplication
==
bnz handle_updateapp

txn OnCompletion
int DeleteApplication
==
bnz handle_deleteapp

// Unexpected OnCompletion value. Should be unreachable.
err

handle_noop:
// Handle NoOp

// read global state
byte "counter"
dup
app_global_get

// increment the value
int 1
+

// store to scratch space
dup
store 0

// update global state
app_global_put

// read local state for sender
int 0
byte "counter"
app_local_get

// increment the value
int 1
+
store 1

// update local state for sender
// update "counter"
int 0
byte "counter"
load 1
app_local_put

// update "timestamp"
int 0
byte "timestamp"
txn ApplicationArgs 0
app_local_put

// load return value as approval
load 0
return

handle_closeout:
// Handle CloseOut
//approval
int 1
return

handle_deleteapp:
// Check for creator
global CreatorAddress
txn Sender
==
return

handle_updateapp:
// Check for creator
global CreatorAddress
txn Sender
==
return

handle_approve:
int 1
return
3 changes: 3 additions & 0 deletions examples/application/clear.teal
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma version 4
int 1
return
Loading

0 comments on commit b57b34c

Please sign in to comment.