Skip to content

Commit 7565f8d

Browse files
committed
add notes for higher level Box interfaces to docs
1 parent 8c1ef85 commit 7565f8d

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

docs/coverage.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ See which `algorand-python` stubs are implemented by the `algorand-python-testin
2525
| Application | Emulated |
2626
| subroutine | Emulated |
2727
| Global | Emulated |
28+
| op.Box.\* | Emulated |
2829
| Box | Emulated |
30+
| BoxRef | Emulated |
31+
| BoxMap | Emulated |
2932
| Block | Emulated |
3033
| logicsig | Emulated |
3134
| log | Emulated |

docs/usage.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,35 @@ To be documented...
232232

233233
### Boxes
234234

235-
To be documented...
235+
The higher-level Boxes interface, introduced in version 2.1.0, along with all low-level Box 'op' calls, are available.
236236

237-
> NOTE: Higher level Boxes interface introduce in v2.1.0 is not supported yet, however all low level Box 'op' calls are available.
237+
```py
238+
import algopy
239+
240+
# Check and mark the sender's POA claim in the Box by their address
241+
# to prevent duplicates using low-level Box 'op' calls.
242+
_id, has_claimed = algopy.op.Box.get(algopy.Txn.sender.bytes)
243+
assert not has_claimed, "Already claimed POA"
244+
algopy.op.Box.put(algopy.Txn.sender.bytes, algopy.op.itob(minted_asset.id))
245+
246+
# Utilizing the higher-level 'Box' interface for an alternative implementation.
247+
box = algopy.Box(algopy.UInt64, key=algopy.Txn.sender.bytes)
248+
has_claimed = bool(box)
249+
assert not has_claimed, "Already claimed POA"
250+
box.value = minted_asset.id
251+
252+
# Utilizing the higher-level 'BoxRef' interface for an alternative implementation.
253+
box_ref = algopy.BoxRef(key=algopy.Txn.sender.bytes)
254+
has_claimed = bool(box_ref)
255+
assert not has_claimed, "Already claimed POA"
256+
box_ref.put(algopy.op.itob(minted_asset.id))
257+
258+
# Utilizing the higher-level 'BoxMap' interface for an alternative implementation.
259+
box_map = algopy.BoxMap(algopy.Bytes, algopy.UInt64, key_prefix="box_map")
260+
has_claimed = algopy.Txn.sender.bytes in self.box_map
261+
assert not has_claimed, "Already claimed POA"
262+
self.box_map[algopy.Txn.sender.bytes] = minted_asset.id
263+
```
238264

239265
## Smart Signatures
240266

0 commit comments

Comments
 (0)