Skip to main content

Module storage

Module storage 

Source
Expand description

High-level storage helpers built on top of Client.

Wraps the postage-batch lifecycle so callers can think in terms of (size, duration) instead of (amount, depth). The math comes from crate::postage (depth/cost formulas) and crate::swarm (Network for block time, Size for byte-count parsing).

Mirrors bee-js’s client.buy_storage / client.get_storage_cost.

Structs§

StorageCost
Storage-cost preview returned by get_storage_cost.
StorageOptions
Options for buy_storage. network shapes the per-block amount math; label is the optional batch label; immutable selects an immutable batch.

Functions§

buy_storage
Preview + buy in one call: compute the cost via get_storage_cost and forward to crate::postage::PostageApi::create_postage_batch. Returns the freshly-minted BatchId.
calculate_top_up_for_bzz
Top-up amount (PLUR) needed for the batch to reach target_bzz total spend, using the chain’s current per-chunk price as the floor. Mirrors bee-js calculateTopUpForBzz.
extend_storage_duration
Top up an existing batch by the per-chunk amount needed to extend it for the given wall-clock duration on the chosen network. The on-chain top-up amount is current_price * blocks(duration).
extend_storage_size
Dilute (deepen) an existing batch so its effective capacity covers new_size. No-op (returns Ok(())) if the batch is already deep enough.
get_duration_extension_cost
Total cost (PLUR) of extending a batch by duration on network, given the current per-chunk price from /chainstate. current_price * blocks(duration) * 2^current_depth.
get_size_extension_cost
Cost (PLUR) of growing a batch’s effective capacity to cover new_size. The dilution cost equals (2^new_depth - 2^old_depth) * batch.amount. Returns 0 if the batch is already deep enough.
get_storage_cost
Compute the depth + amount for a (size, duration) tuple, using the chain’s current price (PLUR/chunk/block) as the per-block price floor. Does not perform the purchase; pure preview.