Skip to content
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

Acct params get #165

Merged
merged 8 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyteal/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ __all__ = [
"AppParam",
"AssetHolding",
"AssetParam",
"AcctParam",
"InnerTxnBuilder",
"InnerTxn",
"InnerTxnAction",
Expand Down
2 changes: 2 additions & 0 deletions pyteal/ast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from .global_ import Global, GlobalField
from .app import App, AppField, OnComplete, AppParam
from .asset import AssetHolding, AssetParam
from .acct import AcctParam

# inner txns
from .itxn import InnerTxnBuilder, InnerTxn, InnerTxnAction
Expand Down Expand Up @@ -151,6 +152,7 @@
"AppParam",
"AssetHolding",
"AssetParam",
"AcctParam",
"InnerTxnBuilder",
"InnerTxn",
"InnerTxnAction",
Expand Down
62 changes: 62 additions & 0 deletions pyteal/ast/acct.py
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 AcctParam:
barnjamin marked this conversation as resolved.
Show resolved Hide resolved
@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 account to check.
Must evaluate to uint64.
ahangsu marked this conversation as resolved.
Show resolved Hide resolved
"""
ahangsu marked this conversation as resolved.
Show resolved Hide resolved
require_type(acct, TealType.uint64)
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.
Must evaluate to uint64.
"""
require_type(acct, TealType.uint64)
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.
barnjamin marked this conversation as resolved.
Show resolved Hide resolved

Args:
app: An index into Txn.accounts that corresponds to the application to check.
Must evaluate to uint64.
"""
require_type(acct, TealType.uint64)
return MaybeValue(
Op.acct_params_get,
TealType.bytes,
immediate_args=["AcctAuthAddr"],
args=[acct],
)


AcctParam.__module__ = "pyteal"
1 change: 1 addition & 0 deletions pyteal/ir/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def min_version(self) -> int:
gitxn = OpType("gitxn", Mode.Application, 6)
gitxna = OpType("gitxna", Mode.Application, 6)
gloadss = OpType("gloadss", Mode.Application, 6)
acct_params_get = OpType("acct_params_get", Mode.Application, 6)
# fmt: on


Expand Down