pub struct TicketBuilder { /* private fields */ }
Expand description
Builder for Ticket and VerifiedTicket.
A new builder is created via TicketBuilder::default or TicketBuilder::zero_hop.
Input validation is performed upon calling TicketBuilder::build, TicketBuilder::build_signed and TicketBuilder::build_verified.
Implementations§
Source§impl TicketBuilder
impl TicketBuilder
Sourcepub fn direction(self, source: &Address, destination: &Address) -> Self
pub fn direction(self, source: &Address, destination: &Address) -> Self
Sets channel id based on the source
and destination
.
This, TicketBuilder::channel_id or TicketBuilder::addresses must be set.
Sourcepub fn addresses<T: Into<Address>, U: Into<Address>>(
self,
source: T,
destination: U,
) -> Self
pub fn addresses<T: Into<Address>, U: Into<Address>>( self, source: T, destination: U, ) -> Self
Sets channel id based on the source
and destination
.
This, TicketBuilder::channel_id or TicketBuilder::direction must be set.
Sourcepub fn channel_id(self, channel_id: Hash) -> Self
pub fn channel_id(self, channel_id: Hash) -> Self
Sets the channel id. This, TicketBuilder::addresses or TicketBuilder::direction must be set.
Sourcepub fn amount<T: Into<U256>>(self, amount: T) -> Self
pub fn amount<T: Into<U256>>(self, amount: T) -> Self
Sets the ticket amount. This or TicketBuilder::balance must be set and be less or equal to 10^25.
Sourcepub fn balance(self, balance: HoprBalance) -> Self
pub fn balance(self, balance: HoprBalance) -> Self
Sets the ticket amount as HOPR balance. This or TicketBuilder::amount must be set and be less or equal to 10^25.
Sourcepub fn index(self, index: u64) -> Self
pub fn index(self, index: u64) -> Self
Sets the ticket index. Must be less or equal to 2^48. Defaults to 0.
Sourcepub fn index_offset(self, index_offset: u32) -> Self
pub fn index_offset(self, index_offset: u32) -> Self
Sets the index offset. Must be greater or equal 1. Defaults to 1.
Sourcepub fn channel_epoch(self, channel_epoch: u32) -> Self
pub fn channel_epoch(self, channel_epoch: u32) -> Self
Sets the channel epoch. Must be less or equal to 2^24. Defaults to 1.
Sourcepub fn win_prob(self, win_prob: WinningProbability) -> Self
pub fn win_prob(self, win_prob: WinningProbability) -> Self
Sets the ticket winning probability. Defaults to 1.0
Sourcepub fn challenge(self, challenge: EthereumChallenge) -> Self
pub fn challenge(self, challenge: EthereumChallenge) -> Self
Sets the [EthereumChallenge] for the Proof of Relay. Must be set.
Sourcepub fn signature(self, signature: Signature) -> Self
pub fn signature(self, signature: Signature) -> Self
Set the signature of this ticket.
Defaults to None
.
Sourcepub fn build_signed(
self,
signer: &ChainKeypair,
domain_separator: &Hash,
) -> Result<VerifiedTicket>
pub fn build_signed( self, signer: &ChainKeypair, domain_separator: &Hash, ) -> Result<VerifiedTicket>
Validates all inputs and builds the VerifiedTicket by signing the ticket data with the given key. Fails if signature was previously set.
Sourcepub fn build_verified(self, hash: Hash) -> Result<VerifiedTicket>
pub fn build_verified(self, hash: Hash) -> Result<VerifiedTicket>
Validates all inputs and builds the VerifiedTicket by assuming the previously
set signature is valid and belongs to the given ticket hash
.
It does not check whether hash
matches the input data nor that the signature verifies
the given hash.
Trait Implementations§
Source§impl Clone for TicketBuilder
impl Clone for TicketBuilder
Source§fn clone(&self) -> TicketBuilder
fn clone(&self) -> TicketBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for TicketBuilder
impl Debug for TicketBuilder
Source§impl Default for TicketBuilder
impl Default for TicketBuilder
Source§impl From<&Ticket> for TicketBuilder
impl From<&Ticket> for TicketBuilder
Auto Trait Implementations§
impl Freeze for TicketBuilder
impl RefUnwindSafe for TicketBuilder
impl Send for TicketBuilder
impl Sync for TicketBuilder
impl Unpin for TicketBuilder
impl UnwindSafe for TicketBuilder
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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