pub struct TicketBuilder { /* private fields */ }Expand description
Builder for the 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 counterparty<A: Into<Address>>(self, counterparty: A) -> Self
pub fn counterparty<A: Into<Address>>(self, counterparty: A) -> Self
Sets the counterparty (recipient) of the ticket.
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 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: Challenge) -> Self
pub fn challenge(self, challenge: Challenge) -> Self
Sets the [Challenge] for the Proof of Relay, converting it to [EthereumChallenge] first.
Either this method or [Ticket::eth_challenge] must be called.
Sourcepub fn eth_challenge(self, challenge: EthereumChallenge) -> Self
pub fn eth_challenge(self, challenge: EthereumChallenge) -> Self
Sets the [EthereumChallenge] for the Proof of Relay.
Either this method or Ticket::challenge must be called.
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 more