pub trait StampValidator {
type Error: From<StampError>;
// Required method
fn validate(
&self,
stamp: &Stamp,
address: &SwarmAddress,
state: &PostageContext,
) -> Result<(), Self::Error>;
// Provided method
fn validate_structure(
&self,
stamp: &Stamp,
address: &SwarmAddress,
state: &PostageContext,
) -> Result<(), Self::Error> { ... }
}Expand description
A trait for validating postage stamps.
Implementations of this trait verify that stamps are valid for a given chunk address and postage context. Validation includes checking:
- The batch exists and is not expired
- The stamp index is within valid bounds
- The chunk address matches the expected bucket
- The signature is valid (implementation-dependent)
§Example
ⓘ
use nectar_postage::{StampValidator, Stamp, PostageContext};
use nectar_primitives::SwarmAddress;
struct MyValidator { /* ... */ }
impl StampValidator for MyValidator {
type Error = nectar_postage::StampError;
fn validate(&self, stamp: &Stamp, address: &SwarmAddress, state: &PostageContext) -> Result<(), Self::Error> {
// Validation logic...
Ok(())
}
}Required Associated Types§
Sourcetype Error: From<StampError>
type Error: From<StampError>
The error type returned when validation fails.
Required Methods§
Sourcefn validate(
&self,
stamp: &Stamp,
address: &SwarmAddress,
state: &PostageContext,
) -> Result<(), Self::Error>
fn validate( &self, stamp: &Stamp, address: &SwarmAddress, state: &PostageContext, ) -> Result<(), Self::Error>
Provided Methods§
Sourcefn validate_structure(
&self,
stamp: &Stamp,
address: &SwarmAddress,
state: &PostageContext,
) -> Result<(), Self::Error>
fn validate_structure( &self, stamp: &Stamp, address: &SwarmAddress, state: &PostageContext, ) -> Result<(), Self::Error>
Validates only the structural properties of a stamp without signature verification.
This is useful for quick validation before performing more expensive cryptographic operations. It checks:
- The batch exists
- The batch is usable (enough confirmations)
- The batch is not expired
- The stamp index is within valid bounds
- The chunk address matches the expected bucket
The default implementation calls validate, but implementations may
override this for performance.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".