pub trait HoprDbTicketOperations {
type Error: Error + Send + Sync + 'static;
// Required methods
fn stream_tickets<'c, 'async_trait, S, I>(
&'c self,
selectors: I,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = RedeemableTicket> + Send + 'c>>, Self::Error>> + Send + 'async_trait>>
where 'c: 'async_trait,
S: 'async_trait + Into<TicketSelector>,
I: 'async_trait + IntoIterator<Item = S> + Send,
Self: 'async_trait;
fn insert_ticket<'life0, 'async_trait>(
&'life0 self,
ticket: RedeemableTicket,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn mark_tickets_as<'life0, 'async_trait, S, I>(
&'life0 self,
selectors: I,
mark_as: TicketMarker,
) -> Pin<Box<dyn Future<Output = Result<usize, Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
S: 'async_trait + Into<TicketSelector> + Send,
I: 'async_trait + IntoIterator<Item = S> + Send,
Self: 'async_trait;
fn mark_unsaved_ticket_rejected<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
issuer: &'life1 Address,
ticket: &'life2 Ticket,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait;
fn update_ticket_states_and_fetch<'a, 'async_trait, S, I>(
&'a self,
selectors: I,
new_state: AcknowledgedTicketStatus,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = RedeemableTicket> + Send + 'a>>, Self::Error>> + Send + 'async_trait>>
where 'a: 'async_trait,
S: 'async_trait + Into<TicketSelector>,
I: 'async_trait + IntoIterator<Item = S> + Send,
Self: 'async_trait;
fn update_ticket_states<'life0, 'async_trait, S, I>(
&'life0 self,
selectors: I,
new_state: AcknowledgedTicketStatus,
) -> Pin<Box<dyn Future<Output = Result<usize, Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
S: 'async_trait + Into<TicketSelector>,
I: 'async_trait + IntoIterator<Item = S> + Send,
Self: 'async_trait;
fn get_ticket_statistics<'life0, 'async_trait>(
&'life0 self,
channel_id: Option<HashBase<CoreWrapper<Keccak256Core>>>,
) -> Pin<Box<dyn Future<Output = Result<ChannelTicketStatistics, Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn reset_ticket_statistics<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn get_tickets_value<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 HashBase<CoreWrapper<Keccak256Core>>,
epoch: u32,
) -> Pin<Box<dyn Future<Output = Result<Balance<WxHOPR>, Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn get_or_create_outgoing_ticket_index<'life0, 'life1, 'async_trait>(
&'life0 self,
channel_id: &'life1 HashBase<CoreWrapper<Keccak256Core>>,
epoch: u32,
) -> Pin<Box<dyn Future<Output = Result<Option<u64>, Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn update_outgoing_ticket_index<'life0, 'life1, 'async_trait>(
&'life0 self,
channel_id: &'life1 HashBase<CoreWrapper<Keccak256Core>>,
epoch: u32,
index: u64,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn remove_outgoing_ticket_index<'life0, 'life1, 'async_trait>(
&'life0 self,
channel_id: &'life1 HashBase<CoreWrapper<Keccak256Core>>,
epoch: u32,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
}Expand description
Database operations for tickets.
The redeemable winning tickets enter the DB via [HoprDb::insert_ticket] and can only leave the DB
when marked via HoprDbTicketOperations::mark_tickets_as
The overall value of tickets in the DB and of those that left the DB is tracked
via the ChannelTicketStatistics by calling the HoprDbTicketOperations::get_ticket_statistics.
The statistics can also track tickets that were rejected before entering the DB,
which can be done via HoprDbTicketOperations::mark_unsaved_ticket_rejected.
NOTE: tickets that are not winning are NOT considered as rejected. Non-winning tickets are therefore not tracked in any statistics, also for performance reasons.
Required Associated Types§
Required Methods§
Sourcefn stream_tickets<'c, 'async_trait, S, I>(
&'c self,
selectors: I,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = RedeemableTicket> + Send + 'c>>, Self::Error>> + Send + 'async_trait>>where
'c: 'async_trait,
S: 'async_trait + Into<TicketSelector>,
I: 'async_trait + IntoIterator<Item = S> + Send,
Self: 'async_trait,
fn stream_tickets<'c, 'async_trait, S, I>(
&'c self,
selectors: I,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = RedeemableTicket> + Send + 'c>>, Self::Error>> + Send + 'async_trait>>where
'c: 'async_trait,
S: 'async_trait + Into<TicketSelector>,
I: 'async_trait + IntoIterator<Item = S> + Send,
Self: 'async_trait,
Retrieve acknowledged winning tickets, according to the given selectors.
If no selector is given, streams tickets in all channels.
Sourcefn insert_ticket<'life0, 'async_trait>(
&'life0 self,
ticket: RedeemableTicket,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn insert_ticket<'life0, 'async_trait>(
&'life0 self,
ticket: RedeemableTicket,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Inserts a new winning ticket into the DB.
Returns an error if the ticket already exists.
Sourcefn mark_tickets_as<'life0, 'async_trait, S, I>(
&'life0 self,
selectors: I,
mark_as: TicketMarker,
) -> Pin<Box<dyn Future<Output = Result<usize, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
S: 'async_trait + Into<TicketSelector> + Send,
I: 'async_trait + IntoIterator<Item = S> + Send,
Self: 'async_trait,
fn mark_tickets_as<'life0, 'async_trait, S, I>(
&'life0 self,
selectors: I,
mark_as: TicketMarker,
) -> Pin<Box<dyn Future<Output = Result<usize, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
S: 'async_trait + Into<TicketSelector> + Send,
I: 'async_trait + IntoIterator<Item = S> + Send,
Self: 'async_trait,
Marks tickets as the given TicketMarker, removing them from the DB and updating the
ticket statistics for each ticket’s channel.
Returns the number of marked tickets.
Sourcefn mark_unsaved_ticket_rejected<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
issuer: &'life1 Address,
ticket: &'life2 Ticket,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn mark_unsaved_ticket_rejected<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
issuer: &'life1 Address,
ticket: &'life2 Ticket,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Updates the ticket statistics according to the fact that the given ticket has been rejected by the packet processing pipeline.
This ticket is not yet stored in the ticket DB; therefore, only the statistics in the corresponding channel are updated, and the overall unrealized value in the respective channel does not change.
Sourcefn update_ticket_states_and_fetch<'a, 'async_trait, S, I>(
&'a self,
selectors: I,
new_state: AcknowledgedTicketStatus,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = RedeemableTicket> + Send + 'a>>, Self::Error>> + Send + 'async_trait>>where
'a: 'async_trait,
S: 'async_trait + Into<TicketSelector>,
I: 'async_trait + IntoIterator<Item = S> + Send,
Self: 'async_trait,
fn update_ticket_states_and_fetch<'a, 'async_trait, S, I>(
&'a self,
selectors: I,
new_state: AcknowledgedTicketStatus,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = RedeemableTicket> + Send + 'a>>, Self::Error>> + Send + 'async_trait>>where
'a: 'async_trait,
S: 'async_trait + Into<TicketSelector>,
I: 'async_trait + IntoIterator<Item = S> + Send,
Self: 'async_trait,
Updates the state of the tickets matching the given selectors.
The operation should prevent any concurrent changes to the tickets before the stream is fully consumed.
Returns the updated tickets in the new state.
Sourcefn update_ticket_states<'life0, 'async_trait, S, I>(
&'life0 self,
selectors: I,
new_state: AcknowledgedTicketStatus,
) -> Pin<Box<dyn Future<Output = Result<usize, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
S: 'async_trait + Into<TicketSelector>,
I: 'async_trait + IntoIterator<Item = S> + Send,
Self: 'async_trait,
fn update_ticket_states<'life0, 'async_trait, S, I>(
&'life0 self,
selectors: I,
new_state: AcknowledgedTicketStatus,
) -> Pin<Box<dyn Future<Output = Result<usize, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
S: 'async_trait + Into<TicketSelector>,
I: 'async_trait + IntoIterator<Item = S> + Send,
Self: 'async_trait,
Updates state of the tickets matching the given selector.
Sourcefn get_ticket_statistics<'life0, 'async_trait>(
&'life0 self,
channel_id: Option<HashBase<CoreWrapper<Keccak256Core>>>,
) -> Pin<Box<dyn Future<Output = Result<ChannelTicketStatistics, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn get_ticket_statistics<'life0, 'async_trait>(
&'life0 self,
channel_id: Option<HashBase<CoreWrapper<Keccak256Core>>>,
) -> Pin<Box<dyn Future<Output = Result<ChannelTicketStatistics, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Retrieves the ticket statistics for the given channel.
If no channel is given, it retrieves aggregate ticket statistics for all channels.
Sourcefn reset_ticket_statistics<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn reset_ticket_statistics<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Resets the ticket statistics about neglected, rejected, and redeemed tickets.
Sourcefn get_tickets_value<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 HashBase<CoreWrapper<Keccak256Core>>,
epoch: u32,
) -> Pin<Box<dyn Future<Output = Result<Balance<WxHOPR>, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn get_tickets_value<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 HashBase<CoreWrapper<Keccak256Core>>,
epoch: u32,
) -> Pin<Box<dyn Future<Output = Result<Balance<WxHOPR>, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Counts the total value of tickets matching the channel.
Returns the total ticket value.
Sourcefn get_or_create_outgoing_ticket_index<'life0, 'life1, 'async_trait>(
&'life0 self,
channel_id: &'life1 HashBase<CoreWrapper<Keccak256Core>>,
epoch: u32,
) -> Pin<Box<dyn Future<Output = Result<Option<u64>, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn get_or_create_outgoing_ticket_index<'life0, 'life1, 'async_trait>(
&'life0 self,
channel_id: &'life1 HashBase<CoreWrapper<Keccak256Core>>,
epoch: u32,
) -> Pin<Box<dyn Future<Output = Result<Option<u64>, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Gets the index of the next outgoing ticket for the given channel.
If such an entry does not exist, it is initialized with 0 and None is returned.
Sourcefn update_outgoing_ticket_index<'life0, 'life1, 'async_trait>(
&'life0 self,
channel_id: &'life1 HashBase<CoreWrapper<Keccak256Core>>,
epoch: u32,
index: u64,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn update_outgoing_ticket_index<'life0, 'life1, 'async_trait>(
&'life0 self,
channel_id: &'life1 HashBase<CoreWrapper<Keccak256Core>>,
epoch: u32,
index: u64,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Stores the ticket index of the next outgoing ticket for the given channel.
Does nothing if the entry for the given channel and epoch does not exist.
Returns an error if the given index is less than the current index in the DB.
Sourcefn remove_outgoing_ticket_index<'life0, 'life1, 'async_trait>(
&'life0 self,
channel_id: &'life1 HashBase<CoreWrapper<Keccak256Core>>,
epoch: u32,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn remove_outgoing_ticket_index<'life0, 'life1, 'async_trait>(
&'life0 self,
channel_id: &'life1 HashBase<CoreWrapper<Keccak256Core>>,
epoch: u32,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Removes the outgoing ticket index for the given channel and epoch.
Does nothing if the value did not exist
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.