Expand description
Postage batch CRUD + stamp metadata. Mirrors pkg/postage in
bee-go.
The endpoint methods live on PostageApi (get one from
crate::Client::postage). Pure stamp math — get_stamp_cost,
get_stamp_effective_bytes, etc. — is exposed as free functions
since it has no I/O.
§Batch-usability delay
A batch is not usable for uploads immediately after
PostageApi::create_postage_batch returns. Bee waits for N
confirmations of the purchase transaction (typically 8) before
flipping PostageBatch::usable to true. On Gnosis (5-second
blocks) this is ~40 s; on Sepolia (12-second blocks) it can be 2-3
minutes and occasionally longer.
Poll PostageApi::get_postage_batch in a loop until usable is
true, or supply the batch via an environment variable so tests can
reuse a known-good batch. Uploading against a not-yet-usable batch
returns HTTP 422 “stamp not usable”, surfaced as
crate::Error::Response with status = 422.
§Dilute is one-way
PostageApi::dilute_batch only allows depth to grow. Once a
batch’s depth is increased its previously-issued stamps remain
valid; there is no way to shrink depth and reclaim funds.
Structs§
- Batch
Bucket - Per-bucket collision count from
GET /stamps/{id}/buckets. - Envelope
- Per-chunk postage envelope returned by
Stamper::stamp. - Global
Postage Batch - Postage batch as returned by
GET /batches(chain-wide view; drops owner-only fields). - Postage
Api - Handle exposing the postage endpoints. Cheap to clone.
- Postage
Batch - Postage batch as returned by
GET /stamps/GET /stamps/{id}(owner-only view; includes utilization, label, blockNumber). - Postage
Batch Buckets - Aggregated bucket fill stats for one batch.
- Stamper
- Client-side stamper that tracks per-bucket utilisation and signs envelopes for individual chunks.
Constants§
- EFFECTIVE_
SIZE_ BREAKPOINTS - Effective-utilisation breakpoints for encrypted, medium-erasure
batches at each depth. Values mirror bee-js
stamps.tsexactly. - MARSHALED_
STAMP_ LENGTH - Wire-format length of a marshaled postage stamp:
batchID(32) || index(8) || timestamp(8) || signature(65). - MIN_
DEPTH - Bucket-depth floor: stamper depth must be strictly greater than
this value (matches bee-go and bee-js, which require
depth > 16). - NUM_
BUCKETS - Number of buckets in a postage batch (
2^16).
Functions§
- convert_
envelope_ to_ marshaled_ stamp - Marshal an
Envelopeinto the 113-byte stamp wire format. Thin wrapper overmarshal_stampfor callers that already hold a structured envelope (typically fromStamper::stamp). Mirrors bee-goConvertEnvelopeToMarshaledStamp/ bee-jsconvertEnvelopeToMarshaledStamp. - get_
depth_ for_ size - Smallest depth whose effective capacity covers
bytes. Falls back to35for sizes the table doesn’t cover. - get_
stamp_ cost - Cost of buying a batch:
2^depth * amountPLUR. - get_
stamp_ effective_ bytes - Practical capacity for the given depth using the encrypted-medium
erasure breakpoints (17..=34). Outside that range falls back to
0.9 * theoretical. - get_
stamp_ theoretical_ bytes - Theoretical capacity of a batch:
4096 * 2^depthbytes. - get_
stamp_ usage - Fractional usage
[0, 1]of a postage batch. - marshal_
stamp - Concatenate the components of a postage stamp into the wire format
Bee expects when a stamp travels alongside a chunk:
batchID(32) || index(8) || timestamp(8) || signature(65)— 113 bytes total. Mirrors bee-gopostage.MarshalStampand bee-jsmarshalStamp.