-
Notifications
You must be signed in to change notification settings - Fork 145
Box support for Application calls and Atomic Transaction Composer #338
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
Changes from 17 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
99a2850
starting to add box support
barnjamin 4684025
Add boxes to atc
barnjamin c10cff1
Format files with black
algochoi c5fbd30
Add boxes docstring
algochoi d9381e3
Add boxes support for appl creation
algochoi bd0c41e
Update cucumber steps for appl txn encoding for boxes
algochoi 8313c8e
Formatting
algochoi af73bbe
Point testing branch to box-reference (WIP)
algochoi 5f39d5c
Sort imports on relevant files and format
algochoi f949e09
Add translation for foreign apps in box refs and some local unit tests
algochoi ce32d63
Add some invalid cases for box translation
algochoi 3b20d42
Check for None when iterating box refs
algochoi af9f6b4
Add self app id references and tests
algochoi adbd4da
Minor changes for box support
algochoi b6f3653
Split boxref to separate file
algochoi 6f15a91
Change box name type to bytes
algochoi 7ddcd77
Change docs references from box string to bytes
algochoi ae3fba9
Refactor cucumber steps
algochoi 1e1b5d7
Refactoring code and adding docstrings
algochoi afceed7
Add another comment
algochoi 9c039f4
Change test steps to encode box args like app args
algochoi 1dd96e9
Add safety checks for box references
algochoi 919923c
Add some detailed errors and refactor
algochoi b861c44
Format unit test
algochoi ffe6b1c
Fix foreign index error and revise undictify method
algochoi ff5b7e1
Merge branch 'feature/box-storage' into box-support
algochoi 8f48f6c
Finish merging cucumber steps
algochoi 71bee9a
Formatting
algochoi 935bd0a
Fix box tests again
algochoi a94cf7e
Encoded as bytes unit test (#344)
tzaffi 1bc926b
Accept AttributeError for foreign apps array if it is referencing its…
algochoi f53f274
Add unit test for empty foreign app array
algochoi 959ec1d
Change unit test to pass in None foreign array
algochoi d45c6c2
Change undictify method for boxes
algochoi 05d5a49
Formatting
algochoi 6960daa
Change test branch
algochoi 485d2ad
Change type hints for atc boxes
algochoi 9eff272
Check for int type for box reference id
algochoi 8a26a05
Change type ignore annotation
algochoi 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| from collections import OrderedDict | ||
| from typing import List, Tuple | ||
|
|
||
| from algosdk import error | ||
|
|
||
|
|
||
| class BoxReference: | ||
| def __init__(self, app_index: int, name: bytes): | ||
| self.app_index = app_index | ||
| self.name = name | ||
|
|
||
| @staticmethod | ||
| def translate_box_references( | ||
| references: List[Tuple[int, bytes]], | ||
| foreign_apps: List[int], | ||
| this_app_id: int, | ||
| ) -> List["BoxReference"]: | ||
| if not references: | ||
| return [] | ||
|
|
||
| box_references = [] | ||
| for ref in references: | ||
| # Try coercing reference id and name. | ||
| from algosdk.future.transaction import ApplicationCallTxn | ||
|
|
||
| ref_id, ref_name = int(ref[0]), ApplicationCallTxn.as_bytes(ref[1]) | ||
| index = 0 | ||
| try: | ||
| # Foreign apps start from index 1; index 0 is its own app ID. | ||
| index = foreign_apps.index(ref_id) + 1 | ||
| except ValueError: | ||
| # Check if the app referenced is itself after checking the | ||
| # foreign apps array (in case its own app id is in its own | ||
| # foreign apps array). | ||
| if ref_id == 0 or ref_id == this_app_id: | ||
| pass | ||
| else: | ||
| raise error.InvalidForeignAppIdError( | ||
| f"Box ref with appId {ref_id} not in foreign-apps" | ||
| ) | ||
| box_references.append(BoxReference(index, ref_name)) | ||
| return box_references | ||
|
|
||
| def dictify(self): | ||
| d = dict() | ||
|
tzaffi marked this conversation as resolved.
|
||
| if self.app_index: | ||
| d["i"] = self.app_index | ||
| if self.name: | ||
| d["n"] = self.name | ||
| od = OrderedDict(sorted(d.items())) | ||
| return od | ||
|
|
||
| @staticmethod | ||
| def undictify(d): | ||
| args = { | ||
| "app_index": d["i"] if "i" in d else None, | ||
| "name": d["n"] if "n" in d else None, | ||
| } | ||
| return args | ||
|
tzaffi marked this conversation as resolved.
Outdated
|
||
|
|
||
| def __eq__(self, other): | ||
| if not isinstance(other, BoxReference): | ||
| return False | ||
| return self.app_index == other.app_index and self.name == other.name | ||
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
Oops, something went wrong.
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.