algopy_testing.state.box
Module Contents
Section titled “Module Contents”Classes
Section titled “Classes”Box | Box abstracts the reading and writing of a single value to a single box. |
|---|---|
BoxRef | BoxRef abstracts the reading and writing of boxes containing raw binary data. |
BoxMap | BoxMap abstracts the reading and writing of a set of boxes using a common key and |
class Box
Section titled “class Box”Bases: Generic[_TValue]
Box abstracts the reading and writing of a single value to a single box.
The box size will be reconfigured dynamically to fit the size of the value being assigned to it.
app_id
Section titled “app_id”create(size: algopy.UInt64 | int | None = None) → bool
Section titled “create(size: algopy.UInt64 | int | None = None) → bool”property key : algopy.Bytes
Section titled “property key : algopy.Bytes”property value : _TValue
Section titled “property value : _TValue”property ref : BoxRef
Section titled “property ref : BoxRef”extract(start_index: algopy.UInt64 | int, length: algopy.UInt64 | int) → algopy.Bytes
Section titled “extract(start_index: algopy.UInt64 | int, length: algopy.UInt64 | int) → algopy.Bytes”Extract a slice of bytes from the box.
Fails if the box does not exist, or if start_index + length > len(box)
- Parameters:
- start_index – The offset to start extracting bytes from
- length – The number of bytes to extract
- Returns: The extracted bytes
resize(new_size: algopy.UInt64 | int) → None
Section titled “resize(new_size: algopy.UInt64 | int) → None”Resizes the box the specified new_size.
Truncating existing data if the new value is shorter or padding with zero bytes if it is longer.
- Parameters: new_size – The new size of the box
replace(start_index: algopy.UInt64 | int, value: algopy.Bytes | bytes) → None
Section titled “replace(start_index: algopy.UInt64 | int, value: algopy.Bytes | bytes) → None”Write value to the box starting at start_index.
Fails if the box does not exist, or if start_index + len(value) > len(box)
- Parameters:
- start_index – The offset to start writing bytes from
- value – The bytes to be written
splice(start_index: algopy.UInt64 | int, length: algopy.UInt64 | int, value: algopy.Bytes | bytes) → None
Section titled “splice(start_index: algopy.UInt64 | int, length: algopy.UInt64 | int, value: algopy.Bytes | bytes) → None”Set box to contain its previous bytes up to index start_index, followed by bytes, followed by the original bytes of the box that began at index start_index + length
Important: This op does not resize the box If the new value is longer than the box size, it will be truncated. If the new value is shorter than the box size, it will be padded with zero bytes
- Parameters:
- start_index – The index to start inserting value
- length – The number of bytes after start_index to omit from the new value
- value – The value to be inserted.
get(default: _TValue) → _TValue
Section titled “get(default: _TValue) → _TValue”maybe() → tuple[_TValue, bool]
Section titled “maybe() → tuple[_TValue, bool]”property length : algopy.UInt64
Section titled “property length : algopy.UInt64”class BoxRef
Section titled “class BoxRef”Bases: _BoxRef
BoxRef abstracts the reading and writing of boxes containing raw binary data.
The size is configured manually, and can be set to values larger than what the AVM can handle in a single value.
class BoxMap
Section titled “class BoxMap”Bases: Generic[_TKey, _TValue]
BoxMap abstracts the reading and writing of a set of boxes using a common key and content type.
Each composite key (prefix + key) still needs to be made available to the application via the boxes property of the Transaction.
app_id
Section titled “app_id”property key_prefix : algopy.Bytes
Section titled “property key_prefix : algopy.Bytes”get(key: _TKey, default: _TValue) → _TValue
Section titled “get(key: _TKey, default: _TValue) → _TValue”maybe(key: _TKey) → tuple[_TValue, bool]
Section titled “maybe(key: _TKey) → tuple[_TValue, bool]”length(key: _TKey) → algopy.UInt64
Section titled “length(key: _TKey) → algopy.UInt64”box(key: _TKey) → Box[_TValue]
Section titled “box(key: _TKey) → Box[_TValue]”Returns a Box holding the box value at key.