-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Storage and ops docs + expand approvals with test
- Loading branch information
1 parent
f4c11f6
commit 8d57d2f
Showing
67 changed files
with
5,448 additions
and
2,127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# AVM Operations | ||
|
||
Algorand TypeScript allows you to express [every op code the AVM has available](https://developer.algorand.org/docs/get-details/dapps/avm/teal/opcodes/) excluding those that manipulate the stack or control execution as these would interfere with the compiler. These are all exported from the [ops module](api/namespaces/op/README.md). It is possible to import ops individually or via the entire namespace. | ||
|
||
```ts | ||
// Import op from module root | ||
import { assert, Contract, op } from '@algorandfoundation/algorand-typescript' | ||
// Import whole module from ./op | ||
import * as op2 from '@algorandfoundation/algorand-typescript/op' | ||
// Import individual ops | ||
import { bzero } from '@algorandfoundation/algorand-typescript/op' | ||
|
||
class MyContract extends Contract { | ||
test() { | ||
const a = bzero(8).bitwiseInvert() | ||
const b = op2.btoi(a) | ||
assert(b === 2 ** 64 - 1) | ||
|
||
const c = op.shr(b, 32) | ||
|
||
assert(c === 2 ** 32 - 1) | ||
} | ||
} | ||
``` | ||
|
||
## Txn, Global, and other Enums | ||
|
||
Many of the AVM ops which take an enum argument have been abstracted into a static type with a property or function per enum member | ||
|
||
```ts | ||
import { Contract, Global, log, Txn } from '@algorandfoundation/algorand-typescript' | ||
import { AppParams } from '@algorandfoundation/algorand-typescript/op' | ||
|
||
class MyContract extends Contract { | ||
test() { | ||
log(Txn.sender) | ||
log(Txn.applicationArgs(0)) | ||
log(Global.groupId) | ||
log(Global.creatorAddress) | ||
log(...AppParams.appAddress(123)) | ||
} | ||
} | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { assert, Contract, op } from '@algorandfoundation/algorand-typescript' | ||
import * as op2 from '@algorandfoundation/algorand-typescript/op' | ||
import { bzero } from '@algorandfoundation/algorand-typescript/op' | ||
|
||
class MyContract extends Contract { | ||
test() { | ||
const a = bzero(8).bitwiseInvert() | ||
const b = op2.btoi(a) | ||
assert(b === 2 ** 64 - 1) | ||
|
||
const c = op.shr(b, 32) | ||
|
||
assert(c === 2 ** 32 - 1) | ||
} | ||
} |
Oops, something went wrong.