pub struct Batch { /* private fields */ }Expand description
A postage batch represents a prepaid storage allocation in the Swarm network.
Batches are created by sending BZZ tokens to the postage stamp contract. Each batch has a depth that determines the maximum number of chunks it can stamp, and a bucket depth that controls the uniformity of chunk distribution.
Implementations§
Source§impl Batch
impl Batch
Sourcepub const fn new(
id: BatchId,
value: u128,
start: u64,
owner: Address,
depth: u8,
bucket_depth: u8,
immutable: bool,
) -> Self
pub const fn new( id: BatchId, value: u128, start: u64, owner: Address, depth: u8, bucket_depth: u8, immutable: bool, ) -> Self
Creates a new batch with the given parameters.
Sourcepub const fn bucket_depth(&self) -> u8
pub const fn bucket_depth(&self) -> u8
Returns the bucket depth.
This controls the uniformity of chunk distribution across collision buckets.
Sourcepub const fn immutable(&self) -> bool
pub const fn immutable(&self) -> bool
Returns whether this batch is immutable.
Immutable batches cannot be diluted (depth increased) and chunks cannot be overwritten. Mutable batches allow writing new chunks to the same bucket index with a later timestamp, replacing the previous chunk.
Sourcepub const fn bucket_upper_bound(&self) -> u32
pub const fn bucket_upper_bound(&self) -> u32
Returns the maximum number of chunks per bucket.
This is equal to 2^(depth - bucket_depth).
Sourcepub const fn bucket_count(&self) -> u32
pub const fn bucket_count(&self) -> u32
Returns the number of collision buckets.
This is equal to 2^bucket_depth.
Sourcepub const fn set_value(&mut self, value: u128)
pub const fn set_value(&mut self, value: u128)
Updates the batch value (for top-up operations).
Sourcepub const fn set_depth(&mut self, depth: u8)
pub const fn set_depth(&mut self, depth: u8)
Updates the batch depth (for dilution operations).
Sourcepub const fn is_expired(&self, total_amount: u128) -> bool
pub const fn is_expired(&self, total_amount: u128) -> bool
Checks if the batch has expired given the current chain state.
Sourcepub const fn is_usable(&self, current_block: u64, threshold: u64) -> bool
pub const fn is_usable(&self, current_block: u64, threshold: u64) -> bool
Checks if the batch is usable (has enough confirmations).
Sourcepub const fn validate_index(&self, index: &StampIndex) -> Result<(), StampError>
pub const fn validate_index(&self, index: &StampIndex) -> Result<(), StampError>
Validates that an index is within the valid range for this batch.
Checks that:
- The bucket is within the valid range (< bucket_count)
- The position within the bucket is within capacity (< bucket_upper_bound)
§Returns
Ok(()) if the index is valid, or Err(StampError::InvalidIndex) otherwise.
Sourcepub fn bucket_for_address(&self, address: &SwarmAddress) -> u32
pub fn bucket_for_address(&self, address: &SwarmAddress) -> u32
Calculates which bucket a chunk address belongs to.
The bucket is determined by taking the first bucket_depth bits of the
chunk address, interpreted as a big-endian unsigned integer.
Sourcepub fn validate_bucket(
&self,
index: &StampIndex,
address: &SwarmAddress,
) -> Result<(), StampError>
pub fn validate_bucket( &self, index: &StampIndex, address: &SwarmAddress, ) -> Result<(), StampError>
Checks if a chunk address matches the expected bucket for a stamp index.
§Returns
Ok(()) if the bucket matches, or Err(StampError::BucketMismatch) otherwise.
Trait Implementations§
Source§impl<'a> Arbitrary<'a> for Batch
Available on crate feature arbitrary only.
impl<'a> Arbitrary<'a> for Batch
arbitrary only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl<'de> Deserialize<'de> for Batch
impl<'de> Deserialize<'de> for Batch
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Batch
impl StructuralPartialEq for Batch
Auto Trait Implementations§
impl Freeze for Batch
impl RefUnwindSafe for Batch
impl Send for Batch
impl Sync for Batch
impl Unpin for Batch
impl UnsafeUnpin for Batch
impl UnwindSafe for Batch
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<'de, T> BorrowedRpcObject<'de> for T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more