pub struct Ticket {
pub channel_id: Hash,
pub amount: HoprBalance,
pub index: u64,
pub index_offset: u32,
pub encoded_win_prob: EncodedWinProb,
pub channel_epoch: u32,
pub challenge: EthereumChallenge,
pub signature: Option<Signature>,
}
Expand description
Contains the overall description of a ticket with a signature.
This structure is not considered verified, unless the Ticket::verify or Ticket::sign methods are called.
§Ticket state machine
See the entire state machine describing the relations of different ticket types below:
Fields§
§channel_id: Hash
Channel ID. See generate_channel_id for how this value is generated.
amount: HoprBalance
Amount of HOPR tokens this ticket is worth. Always between 0 and 2^92.
index: u64
Ticket index. Always between 0 and 2^48.
index_offset: u32
Ticket index offset. Always between 1 and 2^32. For normal tickets this is always equal to 1, for aggregated this is always > 1.
encoded_win_prob: EncodedWinProb
Encoded winning probability represented via 56-bit number.
channel_epoch: u32
Epoch of the channel this ticket belongs to. Always between 0 and 2^24.
challenge: EthereumChallenge
Represent the Proof of Relay challenge encoded as an Ethereum address.
signature: Option<Signature>
ECDSA secp256k1 signature of all the above values.
Implementations§
Source§impl Ticket
impl Ticket
Sourcepub fn get_hash(&self, domain_separator: &Hash) -> Hash
pub fn get_hash(&self, domain_separator: &Hash) -> Hash
Computes Ethereum signature hash of the ticket, must be equal to on-chain computation
Sourcepub fn sign(
self,
signing_key: &ChainKeypair,
domain_separator: &Hash,
) -> VerifiedTicket
pub fn sign( self, signing_key: &ChainKeypair, domain_separator: &Hash, ) -> VerifiedTicket
Signs the ticket using the given private key, turning this ticket into VerifiedTicket. If a signature was already present, it will be replaced.
Sourcepub fn verify(
self,
issuer: &Address,
domain_separator: &Hash,
) -> Result<VerifiedTicket, Box<Ticket>>
pub fn verify( self, issuer: &Address, domain_separator: &Hash, ) -> Result<VerifiedTicket, Box<Ticket>>
Verifies the signature of this ticket, turning this ticket into VerifiedTicket
.
If the verification fails, Self
is returned in the error.
This is done by recovering the signer from the signature and verifying that it matches
the given issuer
argument. This is possible due this specific instantiation of the ECDSA
over the secp256k1 curve.
The operation can fail if a public key cannot be recovered from the ticket signature.
Sourcepub fn is_aggregated(&self) -> bool
pub fn is_aggregated(&self) -> bool
Returns true if this ticket aggregates multiple tickets.
Sourcepub fn win_prob(&self) -> WinningProbability
pub fn win_prob(&self) -> WinningProbability
Returns the decoded winning probability of the ticket
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Ticket
impl<'de> Deserialize<'de> for Ticket
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>,
Source§impl From<&Ticket> for TicketBuilder
impl From<&Ticket> for TicketBuilder
Source§impl From<Ticket> for TicketBuilder
impl From<Ticket> for TicketBuilder
Source§impl Ord for Ticket
impl Ord for Ticket
Source§impl PartialOrd for Ticket
impl PartialOrd for Ticket
impl Eq for Ticket
impl StructuralPartialEq for Ticket
Auto Trait Implementations§
impl Freeze for Ticket
impl RefUnwindSafe for Ticket
impl Send for Ticket
impl Sync for Ticket
impl Unpin for Ticket
impl UnwindSafe for Ticket
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§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§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.