-
Notifications
You must be signed in to change notification settings - Fork 132
Acct params get #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Acct params get #165
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
43b3752
Adding account param getter
barnjamin 5b01fac
Add to init
barnjamin 5bf708a
fix op names and type
barnjamin aa8e030
Merge branch 'master' of github.com:algorand/pyteal into acct_params_get
barnjamin c7f236e
merge
barnjamin 3c00fe2
adding tests
barnjamin 99b467c
allow bytes to be passed
barnjamin e5d2915
tweak docs, add require check for any
barnjamin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,62 @@ | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from ..types import TealType, require_type | ||
| from ..ir import Op | ||
| from .expr import Expr | ||
| from .maybe import MaybeValue | ||
|
|
||
| if TYPE_CHECKING: | ||
| from ..compiler import CompileOptions | ||
|
|
||
|
|
||
| class AccountParam: | ||
| @classmethod | ||
| def balance(cls, acct: Expr) -> MaybeValue: | ||
| """Get the current balance in microalgos an account. | ||
|
|
||
| Args: | ||
| acct: An index into Txn.accounts that corresponds to the application to check or an address available at runtime. | ||
| May evaluate to uint64 or an address. | ||
| """ | ||
| require_type(acct, TealType.anytype) | ||
| return MaybeValue( | ||
| Op.acct_params_get, | ||
| TealType.uint64, | ||
| immediate_args=["AcctBalance"], | ||
| args=[acct], | ||
| ) | ||
|
|
||
| @classmethod | ||
| def minBalance(cls, acct: Expr) -> MaybeValue: | ||
| """Get the minimum balance in microalgos for an account. | ||
|
|
||
| Args: | ||
| acct: An index into Txn.accounts that corresponds to the application to check or an address available at runtime. | ||
| May evaluate to uint64 or an address. | ||
| """ | ||
| require_type(acct, TealType.anytype) | ||
| return MaybeValue( | ||
| Op.acct_params_get, | ||
| TealType.uint64, | ||
| immediate_args=["AcctMinBalance"], | ||
| args=[acct], | ||
| ) | ||
|
|
||
| @classmethod | ||
| def authAddr(cls, acct: Expr) -> MaybeValue: | ||
| """Get the authorizing address for an account. If the account is not rekeyed, the empty addresss is returned. | ||
|
|
||
| Args: | ||
| acct: An index into Txn.accounts that corresponds to the application to check or an address available at runtime. | ||
| May evaluate to uint64 or an address. | ||
| """ | ||
| require_type(acct, TealType.anytype) | ||
| return MaybeValue( | ||
| Op.acct_params_get, | ||
| TealType.bytes, | ||
| immediate_args=["AcctAuthAddr"], | ||
| args=[acct], | ||
| ) | ||
|
|
||
|
|
||
| AccountParam.__module__ = "pyteal" | ||
This file contains hidden or 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,80 @@ | ||
| import pytest | ||
|
|
||
| from .. import * | ||
|
|
||
| # this is not necessary but mypy complains if it's not included | ||
| from .. import CompileOptions | ||
|
|
||
| options = CompileOptions() | ||
| teal4Options = CompileOptions(version=4) | ||
| teal5Options = CompileOptions(version=5) | ||
| teal6Options = CompileOptions(version=6) | ||
|
|
||
|
|
||
| def test_acct_param_balance_valid(): | ||
| arg = Int(1) | ||
| expr = AccountParam.balance(arg) | ||
| assert expr.type_of() == TealType.none | ||
| assert expr.value().type_of() == TealType.uint64 | ||
|
|
||
| expected = TealSimpleBlock( | ||
| [ | ||
| TealOp(arg, Op.int, 1), | ||
| TealOp(expr, Op.acct_params_get, "AcctBalance"), | ||
| TealOp(None, Op.store, expr.slotOk), | ||
| TealOp(None, Op.store, expr.slotValue), | ||
| ] | ||
| ) | ||
|
|
||
| actual, _ = expr.__teal__(teal6Options) | ||
| actual.addIncoming() | ||
| actual = TealBlock.NormalizeBlocks(actual) | ||
|
|
||
| with TealComponent.Context.ignoreExprEquality(): | ||
| assert actual == expected | ||
|
|
||
|
|
||
| def test_acct_param_min_balance_valid(): | ||
| arg = Int(0) | ||
| expr = AccountParam.minBalance(arg) | ||
| assert expr.type_of() == TealType.none | ||
| assert expr.value().type_of() == TealType.uint64 | ||
|
|
||
| expected = TealSimpleBlock( | ||
| [ | ||
| TealOp(arg, Op.int, 0), | ||
| TealOp(expr, Op.acct_params_get, "AcctMinBalance"), | ||
| TealOp(None, Op.store, expr.slotOk), | ||
| TealOp(None, Op.store, expr.slotValue), | ||
| ] | ||
| ) | ||
|
|
||
| actual, _ = expr.__teal__(teal6Options) | ||
| actual.addIncoming() | ||
| actual = TealBlock.NormalizeBlocks(actual) | ||
|
|
||
| with TealComponent.Context.ignoreExprEquality(): | ||
| assert actual == expected | ||
|
|
||
|
|
||
| def test_acct_param_auth_addr_valid(): | ||
| arg = Int(1) | ||
| expr = AccountParam.authAddr(arg) | ||
| assert expr.type_of() == TealType.none | ||
| assert expr.value().type_of() == TealType.bytes | ||
|
|
||
| expected = TealSimpleBlock( | ||
| [ | ||
| TealOp(arg, Op.int, 1), | ||
| TealOp(expr, Op.acct_params_get, "AcctAuthAddr"), | ||
| TealOp(None, Op.store, expr.slotOk), | ||
| TealOp(None, Op.store, expr.slotValue), | ||
| ] | ||
| ) | ||
|
|
||
| actual, _ = expr.__teal__(teal6Options) | ||
| actual.addIncoming() | ||
| actual = TealBlock.NormalizeBlocks(actual) | ||
|
|
||
| with TealComponent.Context.ignoreExprEquality(): | ||
| assert actual == expected |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.