Skip to content

Commit

Permalink
docs: make another pass on documentation to prepare for v1 (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin authored Mar 27, 2023
1 parent 3ab6d3b commit 0caf26a
Show file tree
Hide file tree
Showing 53 changed files with 842 additions and 394 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ print(result.return_value) # "Hello, Beaker"

You can install from pip:

`pip install beaker-pyteal==1.0.0b2`
`pip install beaker-pyteal`

Or from github directly (no promises on stability):

Expand Down
66 changes: 64 additions & 2 deletions beaker/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ def _set_ctx(app: "Application", client: "AlgodClient | None") -> Iterator[None]


class Application(Generic[TState]):
"""A class representing an Application."""

# TODO: more

@overload
def __init__(
self: "Application[None]",
Expand Down Expand Up @@ -139,7 +143,6 @@ def __init__(
descr: str | None = None,
build_options: BuildOptions | None = None,
):
"""<TODO>"""
self._state: TState = state
self.name = name
self.descr = descr
Expand Down Expand Up @@ -186,6 +189,8 @@ def precompiled(
value: "Application | LogicSignature | LogicSignatureTemplate",
/,
) -> PrecompiledApplication | PrecompiledLogicSignature | PrecompiledLogicSignatureTemplate:
"""Precompile an Application or LogicSignature for use in the logic of the application."""

if value is self:
raise PrecompileContextError("Attempted to precompile current Application")
try:
Expand Down Expand Up @@ -402,7 +407,7 @@ def external(
Args:
fn: The function being wrapped.
method_config: <TODO>
method_config: A MethodConfig or MethodConfigDict that defines the OnComplete fields that are valid for this method
name: Name of ABI method. If not set, name of the python method will be used.
Useful for method overriding.
authorize: a subroutine with input of ``Txn.sender()`` and output uint64
Expand Down Expand Up @@ -547,6 +552,7 @@ def create(
bare: bool = False,
override: bool | None = False,
) -> ABIReturnSubroutine | DecoratorFuncType:
"""Mark a method as one that should be callable during application create."""
decorator = self.external(
method_config={"no_op": CallConfig.CREATE},
name=name,
Expand Down Expand Up @@ -626,6 +632,14 @@ def delete(
bare: bool = False,
override: bool | None = False,
) -> ABIReturnSubroutine | DecoratorFuncType:
"""Mark a method as one that should be callable during application delete.
Args:
name: The name of the method. If not provided, the name of the method will be used.
authorize: A function that will be called to authorize the method. If not provided, the method will not be authorized.
bare: If True, the router will only consider the OnComplete of the app call transaction to do routing.
override: If True, the method will override any existing method with the same name.
"""

decorator = self.external(
method_config={"delete_application": CallConfig.CALL},
Expand Down Expand Up @@ -706,6 +720,14 @@ def update(
bare: bool = False,
override: bool | None = False,
) -> ABIReturnSubroutine | DecoratorFuncType:
"""Mark a method as one that should be callable during application update.
Args:
name: The name of the method. If not provided, the name of the method will be used.
authorize: A function that will be called to authorize the method. If not provided, the method will not be authorized.
bare: If True, the router will only consider the OnComplete of the app call transaction to do routing.
override: If True, the method will override any existing method with the same name.
"""
decorator = self.external(
method_config={"update_application": CallConfig.CALL},
name=name,
Expand Down Expand Up @@ -790,6 +812,15 @@ def opt_in(
bare: bool = False,
override: bool | None = False,
) -> ABIReturnSubroutine | DecoratorFuncType:
"""Mark a method as one that should be callable during application opt-in.
Args:
allow_create: If True, the method will be callable even if the application does not exist.
name: The name of the method. If not provided, the name of the method will be used.
authorize: A function that will be called to authorize the method. If not provided, the method will not be authorized.
bare: If True, the router will only consider the OnComplete of the app call transaction to do routing.
override: If True, the method will override any existing method with the same name.
"""
decorator = self.external(
method_config={
"opt_in": CallConfig.ALL if allow_create else CallConfig.CALL
Expand Down Expand Up @@ -871,6 +902,14 @@ def close_out(
bare: bool = False,
override: bool | None = False,
) -> ABIReturnSubroutine | DecoratorFuncType:
"""Mark a method as one that should be callable during application close-out.
Args:
name: The name of the method. If not provided, the name of the method will be used.
authorize: A function that will be called to authorize the method. If not provided, the method will not be authorized.
bare: If True, the router will only consider the OnComplete of the app call transaction to do routing.
override: If True, the method will override any existing method with the same name.
"""
decorator = self.external(
method_config={"close_out": CallConfig.CALL},
name=name,
Expand Down Expand Up @@ -964,6 +1003,17 @@ def no_op(
read_only: bool = False,
override: bool | None = False,
) -> ABIReturnSubroutine | DecoratorFuncType:
"""Mark a method as one that should be callable during application no-op.
Args:
allow_call: If True, the method will be callable during application no-op after creation.
allow_create: If True, the method will be callable during application create.
name: The name of the method. If not provided, the name of the method will be used.
authorize: A function that will be called to authorize the method. If not provided, the method will not be authorized.
bare: If True, the router will only consider the OnComplete of the app call transaction to do routing.
override: If True, the method will override any existing method with the same name.
"""

if allow_call and allow_create:
call_config = CallConfig.ALL
elif allow_call:
Expand Down Expand Up @@ -1008,6 +1058,13 @@ def clear_state(
name: str | None = None,
override: bool | None = False,
) -> SubroutineFnWrapper | Callable[[Callable[[], Expr]], SubroutineFnWrapper]:
"""Mark a method as one that should be callable during application clear-state.
Args:
name: The name of the method. If not provided, the name of the method will be used.
override: If True, the method will override any existing method with the same name.
"""

def decorator(fun: Callable[[], Expr]) -> SubroutineFnWrapper:
sub = SubroutineFnWrapper(fun, TealType.none, name=name)
if sub.subroutine.argument_count():
Expand All @@ -1030,6 +1087,11 @@ def apply(
*args: P.args,
**kwargs: P.kwargs,
) -> "Application[TState]":
"""Apply a ``blueprint`` function to the application
Args:
func: the blueprint function to apply to the application
"""
func(self, *args, **kwargs)
return self

Expand Down
Binary file modified docs/doctrees/application.doctree
Binary file not shown.
Binary file modified docs/doctrees/application_client.doctree
Binary file not shown.
Binary file modified docs/doctrees/boxes.doctree
Binary file not shown.
Binary file modified docs/doctrees/decorators.doctree
Binary file not shown.
Binary file modified docs/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/doctrees/index.doctree
Binary file not shown.
Binary file modified docs/doctrees/lsig.doctree
Binary file not shown.
Binary file modified docs/doctrees/migration.doctree
Binary file not shown.
Binary file modified docs/doctrees/precompile.doctree
Binary file not shown.
Binary file modified docs/doctrees/sandbox.doctree
Binary file not shown.
Binary file modified docs/doctrees/state.doctree
Binary file not shown.
Binary file modified docs/doctrees/testing.doctree
Binary file not shown.
Binary file modified docs/doctrees/usage.doctree
Binary file not shown.
Loading

0 comments on commit 0caf26a

Please # to comment.