| 1 |
// https://developer.algorand.org/docs/get-details/dapps/avm/teal/#looping-and-subroutines |
| 2 |
// Are used to comment in TEAL |
| 3 |
// htlc.teal |
| 4 |
// Push the CloseRemainderTo property of the current transaction onto the stack |
| 5 |
txn CloseRemainderTo |
| 6 |
|
| 7 |
// Push addr2 onto the stack as the intended recipient |
| 8 |
addr SOEI4UA72A7ZL5P25GNISSVWW724YABSGZ7GHW5ERV4QKK2XSXLXGXPG5Y |
| 9 |
|
| 10 |
// The == operator is used to verify that both of these are the same |
| 11 |
// This pops the two values off the stack and pushes the result 0 or 1 |
| 12 |
== |
| 13 |
|
| 14 |
// Push the current transaction’s Receiver property onto the stack |
| 15 |
// In this example it should be addr2 |
| 16 |
txn Receiver |
| 17 |
|
| 18 |
// Push addr2 on the stack using the addr constant |
| 19 |
addr SOEI4UA72A7ZL5P25GNISSVWW724YABSGZ7GHW5ERV4QKK2XSXLXGXPG5Y |
| 20 |
|
| 21 |
// Use the == to verify that these are equal which pops off the top two values of the stack |
| 22 |
// and returns 0 or 1 |
| 23 |
== |
| 24 |
|
| 25 |
// The stack should currently have two values from the two top conditions |
| 26 |
// These will be either 0s or 1s |
| 27 |
// Push the && operator which will AND the two previous conditions and return |
| 28 |
// either 0 or 1, which leaves one value on the stack either a 0 or a 1 |
| 29 |
&& |
| 30 |
|
| 31 |
// Push the first argument to the transaction onto the stack |
| 32 |
arg 0 |
| 33 |
|
| 34 |
// The len operator pops the arg off the stack and |
| 35 |
// pushes the length of the argument onto the stack |
| 36 |
len |
| 37 |
|
| 38 |
// Push a constant int of value 46 onto the stack |
| 39 |
int 46 |
| 40 |
|
| 41 |
// The == operator verifies that the length of the argument |
| 42 |
// is equal to 46. This pops the two values and returns a 0 or 1 |
| 43 |
// The stack now contains two values with a value of 0 or 1 |
| 44 |
== |
| 45 |
|
| 46 |
// The && operator will AND the two values in the stack |
| 47 |
// which pops both values off the stack and returns a 0 or 1 |
| 48 |
// The stack should now only have one value on the stack, 0 or 1 |
| 49 |
&& |
| 50 |
|
| 51 |
// arg 0 is pushed back onto the stack |
| 52 |
// This represents the hashed passcode |
| 53 |
arg 0 |
| 54 |
|
| 55 |
// The sha256 operator pops the arg 0 off the stack |
| 56 |
// and pushes the hash value of the argument onto the stack |
| 57 |
sha256 |
| 58 |
|
| 59 |
// The constant byte array of the base64 version of our secret is pushed onto the stack |
| 60 |
byte base64 QzYhq9JlYbn2QdOMrhyxVlNtNjeyvyJc/I8d8VAGfGc= |
| 61 |
|
| 62 |
// The == operator pops the two values and pushes 0 or 1 onto the stack |
| 63 |
// If arg0 is equal to the secret this value will be 1 and if not it will be 0 |
| 64 |
== |
| 65 |
|
| 66 |
// Two values are now on the stack. The && operator is used |
| 67 |
// to pop the last two values and push either 0 or 1 |
| 68 |
// This will AND all previous conditions to this one. |
| 69 |
// The stack should only have a 0 or 1 value now |
| 70 |
&& |