You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
:any:`Global.opcode_budget()` :code:`TealType.uint64` 6 The remaining cost that can be spent by opcodes in this program
241
+
:any:`Global.caller_app_id()` :code:`TealType.uint64` 6 The ID of the application that called the current application, or zero. Application mode only
242
+
:any:`Global.caller_app_address()` :code:`TealType.bytes` 6 32 byte address of the application that called the current application, or the zero address. Application mode only.
243
+
:any:`Global.asset_create_min_balance()` :code:`TealType.uint64` 10 The minimum balance required to create and opt into an asset
244
+
:any:`Global.asset_opt_in_min_balance()` :code:`TealType.uint64` 10 The minimum balance required to opt in to an asset
245
+
:any:`Global.genesis_hash()` :code:`TealType.bytes` 10 The genesis hash for the network
@@ -267,9 +269,10 @@ The app account's minimum balance requirement (MBR) is increased with each addit
267
269
If one deletes an application with outstanding boxes, the MBR is not recoverable from the deleted app account.
268
270
It is recommended that *before* app deletion, all box storage be deleted, and funds previously allocated to the MBR be withdrawn.
269
271
270
-
Box sizes and names cannot be changed after initial allocation, but they can be deleted and re-allocated.
271
272
Boxes are only visible to the application itself; in other words, an application cannot read from or write to another application's boxes on-chain.
272
273
274
+
Boxes are fixed-length structures, though they can be resized with the :any:`App.box_resize` method (or by deleting and recreating the box).
275
+
273
276
The following sections explain how to work with boxes.
274
277
275
278
.. _Creating Boxes:
@@ -311,19 +314,67 @@ For :any:`App.box_put`, the first argument is the box name to create or to write
311
314
# write to box `poemLine` with new value
312
315
App.box_put(Bytes("poemLine"), Bytes("The lone and level sands stretch far away."))
313
316
317
+
Resizing Boxes
318
+
~~~~~~~~~~~~~~
319
+
320
+
Boxes that already exist can be resized using the :any:`App.box_resize` method. This is the only way to resize a box, besides deleting it and recreating it.
321
+
322
+
For :any:`App.box_resize`, the first argument is the box name to resize, and the second argument is the new byte size to be allocated.
323
+
324
+
.. note::
325
+
If the new size is smaller than the existing box's byte size, then the box will lose the bytes at the end.
326
+
If the new size is larger than the existing box's byte size, then the box will be padded with zeros at the end.
327
+
328
+
For all size changes, the app account's minimum balance requirement (MBR) will be updated accordingly.
329
+
330
+
For example:
331
+
332
+
.. code-block:: python
333
+
334
+
# resize a box called "BoxA" to byte size 200
335
+
App.box_resize(Bytes("BoxA"), Int(200))
336
+
314
337
Writing to a Box
315
338
~~~~~~~~~~~~~~~~
316
339
317
-
To write to a box, use :any:`App.box_replace`, or :any:`App.box_put` method.
340
+
To write to a box, use :any:`App.box_replace`, :any:`App.box_splice` , or :any:`App.box_put` method.
318
341
319
-
:any:`App.box_replace`writes bytes of certain length from a start indexin a box.
342
+
:any:`App.box_replace`replaces a range of bytesin a box.
320
343
The first argument is the box name to write into, the second argument is the starting index to write,
321
344
and the third argument is the replacement bytes. For example:
322
345
323
346
.. code-block:: python
324
347
325
-
# replace 2 bytes starting from the 0'th byte by `Ne` in the box named `wordleBox`
Replaces the range of bytes from `start` through `start + length` with `new_content`.
296
+
297
+
Bytes after `start + length` will be shifted to the right.
298
+
299
+
Recall that boxes are constant length, and this operation will not change the length of the
300
+
box. Instead content may be adjusted as so:
301
+
302
+
* If the length of the new content is less than `length`, the bytes following `start + length` will be shifted to the left, and the end of the box will be padded with zeros.
303
+
304
+
* If the length of the new content is greater than `length`, the bytes following `start + length` will be shifted to the right and bytes exceeding the length of the box will be truncated.
305
+
306
+
Args:
307
+
name: The name of the box to modify. Must evaluate to bytes.
308
+
start: The byte index into the box to start writing. Must evaluate to uint64.
309
+
length: The length of the bytes to be replaced. Must evaluate to uint64.
310
+
new_content: The new content to write into the box. Must evaluate to bytes.
311
+
"""
312
+
returnBoxSplice(name, start, length, new_content)
313
+
275
314
@classmethod
276
315
defbox_length(cls, name: Expr) ->MaybeValue:
277
316
"""Get the byte length of the box specified by its name.
0 commit comments