BandwidthProofBuilder

Struct BandwidthProofBuilder 

Source
pub struct BandwidthProofBuilder { /* private fields */ }
Expand description

Builder for BandwidthProof.

Implementations§

Source§

impl BandwidthProofBuilder

Source

pub fn new() -> Self

Create a new builder.

§Example
use chie_shared::types::bandwidth::BandwidthProofBuilder;

let proof = BandwidthProofBuilder::new()
    .content_cid("bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi")
    .chunk_index(0)
    .bytes_transferred(262_144)
    .provider_peer_id("12D3KooWProviderPeerID")
    .requester_peer_id("12D3KooWRequesterPeerID")
    .provider_public_key(vec![1u8; 32])
    .requester_public_key(vec![2u8; 32])
    .provider_signature(vec![3u8; 64])
    .requester_signature(vec![4u8; 64])
    .challenge_nonce(vec![5u8; 32])
    .chunk_hash(vec![6u8; 32])
    .timestamps(1000, 1100)
    .build()
    .expect("Failed to build bandwidth proof");

assert_eq!(proof.bytes_transferred, 262_144);
assert_eq!(proof.latency_ms, 100);
assert!(proof.is_valid());
assert_eq!(proof.bandwidth_bps(), 2_621_440.0);
Source

pub fn session_id(self, id: Uuid) -> Self

Set the session ID (auto-generated if not set).

Source

pub fn content_cid(self, cid: impl Into<String>) -> Self

Set the content CID.

Source

pub fn chunk_index(self, index: u64) -> Self

Set the chunk index.

Source

pub fn bytes_transferred(self, bytes: Bytes) -> Self

Set bytes transferred.

Source

pub fn provider_peer_id(self, peer_id: impl Into<String>) -> Self

Set provider peer ID.

Source

pub fn requester_peer_id(self, peer_id: impl Into<String>) -> Self

Set requester peer ID.

Source

pub fn provider_public_key(self, key: impl Into<Vec<u8>>) -> Self

Set provider public key.

Source

pub fn requester_public_key(self, key: impl Into<Vec<u8>>) -> Self

Set requester public key.

Source

pub fn provider_signature(self, sig: impl Into<Vec<u8>>) -> Self

Set provider signature.

Source

pub fn requester_signature(self, sig: impl Into<Vec<u8>>) -> Self

Set requester signature.

Source

pub fn challenge_nonce(self, nonce: impl Into<Vec<u8>>) -> Self

Set challenge nonce.

Source

pub fn chunk_hash(self, hash: impl Into<Vec<u8>>) -> Self

Set chunk hash.

Source

pub fn timestamps(self, start_ms: i64, end_ms: i64) -> Self

Set timestamps.

Source

pub fn latency_ms(self, latency: u32) -> Self

Set latency directly (overrides calculated from timestamps).

Source

pub fn build(self) -> Result<BandwidthProof, &'static str>

Build the BandwidthProof.

§Errors

Returns an error if required fields are missing:

  • content_cid
  • provider_peer_id
  • requester_peer_id
  • provider_public_key
  • requester_public_key

Trait Implementations§

Source§

impl Debug for BandwidthProofBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BandwidthProofBuilder

Source§

fn default() -> BandwidthProofBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.