pub struct BandwidthProofState<S> {
pub id: String,
pub bytes_transferred: u64,
pub latency_ms: u64,
pub points: u64,
pub rejection_reason: Option<String>,
/* private fields */
}Expand description
Type-safe bandwidth proof with state machine enforcement.
Uses phantom types to ensure only valid state transitions are possible.
§Example
use chie_shared::BandwidthProofState;
use chie_shared::proof_states::*;
// Create a new proof
let proof = BandwidthProofState::<Created>::new("proof123", 1024, 100);
// Submit for verification (changes state)
let submitted = proof.submit();
// Verify the proof (changes state again)
let verified = submitted.verify(true);
// Can't submit again - compile error!
// let error = verified.submit(); // Error: method not available for Verified stateFields§
§id: StringProof identifier
bytes_transferred: u64Bytes transferred
latency_ms: u64Latency in milliseconds
points: u64Points awarded (only set in Verified state)
rejection_reason: Option<String>Rejection reason (only set in Rejected state)
Implementations§
Source§impl BandwidthProofState<Submitted>
impl BandwidthProofState<Submitted>
Sourcepub fn verify(
self,
valid: bool,
) -> Result<BandwidthProofState<Verified>, BandwidthProofState<Rejected>>
pub fn verify( self, valid: bool, ) -> Result<BandwidthProofState<Verified>, BandwidthProofState<Rejected>>
Verify the proof (transition to Verified or Rejected state).
§Errors
Returns BandwidthProofState<Rejected> if validation fails
Source§impl BandwidthProofState<Verified>
impl BandwidthProofState<Verified>
Sourcepub fn awarded_points(&self) -> u64
pub fn awarded_points(&self) -> u64
Get the awarded points (only available in Verified state).
Trait Implementations§
Source§impl<S: Clone> Clone for BandwidthProofState<S>
impl<S: Clone> Clone for BandwidthProofState<S>
Source§fn clone(&self) -> BandwidthProofState<S>
fn clone(&self) -> BandwidthProofState<S>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<S: Debug> Debug for BandwidthProofState<S>
impl<S: Debug> Debug for BandwidthProofState<S>
Source§impl<'de, S> Deserialize<'de> for BandwidthProofState<S>
impl<'de, S> Deserialize<'de> for BandwidthProofState<S>
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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl<S> Freeze for BandwidthProofState<S>
impl<S> RefUnwindSafe for BandwidthProofState<S>where
S: RefUnwindSafe,
impl<S> Send for BandwidthProofState<S>where
S: Send,
impl<S> Sync for BandwidthProofState<S>where
S: Sync,
impl<S> Unpin for BandwidthProofState<S>where
S: Unpin,
impl<S> UnwindSafe for BandwidthProofState<S>where
S: UnwindSafe,
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
Mutably borrows from an owned value. Read more