Trait TicketManagement
pub trait TicketManagement {
type Error: Error + Send + Sync + 'static;
// Required methods
fn redeem_stream<C>(
&self,
client: C,
channel_id: HashBase<CoreWrapper<Keccak256Core>>,
min_amount: Option<Balance<WxHOPR>>,
) -> Result<impl Stream<Item = Result<RedemptionResult, Self::Error>> + Send, Self::Error>
where C: ChainWriteTicketOperations + Send + Sync + 'static;
fn neglect_tickets(
&self,
channel_id: &HashBase<CoreWrapper<Keccak256Core>>,
max_ticket_index: Option<u64>,
) -> Result<Vec<VerifiedTicket>, Self::Error>;
fn ticket_stats(
&self,
channel_id: Option<&HashBase<CoreWrapper<Keccak256Core>>>,
) -> Result<ChannelStats, Self::Error>;
}Expand description
API for managing winning (redeemable) tickets in incoming channels.
The redeemable tickets are typically organized in a queue ordered by their
TicketId. There are 3 possible ways how a redeemable ticket can be
extracted (removed) from the queue:
- Successful on-chain redemption (happens due to a successful on-chain redemption operation).
- Unsuccessful on-chain redemption (rejection happens due to a failed on-chain redemption operation).
- Neglection without trying to redeem it on-chain (can happen for various reasons, e.g.: a channel being closed prior to a ticket being redeemed, low-value ticket … etc.). Extracting tickets from the queue should not be possible via any other means than the 3 above, and this is what is reflected by this trait.
The state of the individual channels can be observed via ChannelStats.
Required Associated Types§
Required Methods§
fn redeem_stream<C>(
&self,
client: C,
channel_id: HashBase<CoreWrapper<Keccak256Core>>,
min_amount: Option<Balance<WxHOPR>>,
) -> Result<impl Stream<Item = Result<RedemptionResult, Self::Error>> + Send, Self::Error>
fn redeem_stream<C>( &self, client: C, channel_id: HashBase<CoreWrapper<Keccak256Core>>, min_amount: Option<Balance<WxHOPR>>, ) -> Result<impl Stream<Item = Result<RedemptionResult, Self::Error>> + Send, Self::Error>
Creates a stream that tries to redeem individual winning tickets from the given channel in the correct order.
All errors that are due to tickets being invalid (found to be unredeemable) are handled by returning a
RedemptionResult::RejectedOnChain, rejected from the queue, and the stream continues with the next
redeemable ticket in that channel.
If min_amount is specified and tickets are found to be below this value, the ticket is handled by returning
RedemptionResult::ValueTooLow, gets neglected from the queue, and the stream continues with the next
redeemable ticket.
The stream terminates if there’s a processing error (passing the error via the stream), the ticket that
triggered the error remains in the queue and can be attempted to be redeemed once redeem_stream is called
again.
fn neglect_tickets(
&self,
channel_id: &HashBase<CoreWrapper<Keccak256Core>>,
max_ticket_index: Option<u64>,
) -> Result<Vec<VerifiedTicket>, Self::Error>
fn neglect_tickets( &self, channel_id: &HashBase<CoreWrapper<Keccak256Core>>, max_ticket_index: Option<u64>, ) -> Result<Vec<VerifiedTicket>, Self::Error>
Neglects tickets in the given channel up to the max_ticket_index (inclusive, or all tickets if None).
Returns the vector of neglected tickets.
If this function is called while a redemption stream is active on the same channel and the ticket index range overlaps with the range of redeemed tickets, the neglection will take precedence over the redemption stream. This means the stream will terminate earlier because the tickets that were not redeemed will be neglected.
fn ticket_stats(
&self,
channel_id: Option<&HashBase<CoreWrapper<Keccak256Core>>>,
) -> Result<ChannelStats, Self::Error>
fn ticket_stats( &self, channel_id: Option<&HashBase<CoreWrapper<Keccak256Core>>>, ) -> Result<ChannelStats, Self::Error>
Returns the ChannelStats for the given channel, or cumulative stats for all channels if None.
Usually the stats could be non-persistent, but it is a choice of the implementation.
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.
Implementations on Foreign Types§
§impl<'a, T> TicketManagement for &'a Twhere
T: 'a + TicketManagement + ?Sized,
impl<'a, T> TicketManagement for &'a Twhere
T: 'a + TicketManagement + ?Sized,
type Error = <T as TicketManagement>::Error
fn redeem_stream<C>( &self, client: C, channel_id: HashBase<CoreWrapper<Keccak256Core>>, min_amount: Option<Balance<WxHOPR>>, ) -> Result<impl Stream<Item = Result<RedemptionResult, <&'a T as TicketManagement>::Error>> + Send, <&'a T as TicketManagement>::Error>
fn neglect_tickets( &self, channel_id: &HashBase<CoreWrapper<Keccak256Core>>, max_ticket_index: Option<u64>, ) -> Result<Vec<VerifiedTicket>, <&'a T as TicketManagement>::Error>
fn ticket_stats( &self, channel_id: Option<&HashBase<CoreWrapper<Keccak256Core>>>, ) -> Result<ChannelStats, <&'a T as TicketManagement>::Error>
Source§impl<S> TicketManagement for HoprTicketManager<S, <S as TicketQueueStore>::Queue>where
S: TicketQueueStore + Send + Sync + 'static,
<S as TicketQueueStore>::Queue: Send + Sync + 'static,
impl<S> TicketManagement for HoprTicketManager<S, <S as TicketQueueStore>::Queue>where
S: TicketQueueStore + Send + Sync + 'static,
<S as TicketQueueStore>::Queue: Send + Sync + 'static,
Source§fn redeem_stream<C>(
&self,
chain: C,
channel_id: HashBase<CoreWrapper<Keccak256Core>>,
min_amount: Option<Balance<WxHOPR>>,
) -> Result<impl Stream<Item = Result<RedemptionResult, <HoprTicketManager<S, <S as TicketQueueStore>::Queue> as TicketManagement>::Error>> + Send, <HoprTicketManager<S, <S as TicketQueueStore>::Queue> as TicketManagement>::Error>
fn redeem_stream<C>( &self, chain: C, channel_id: HashBase<CoreWrapper<Keccak256Core>>, min_amount: Option<Balance<WxHOPR>>, ) -> Result<impl Stream<Item = Result<RedemptionResult, <HoprTicketManager<S, <S as TicketQueueStore>::Queue> as TicketManagement>::Error>> + Send, <HoprTicketManager<S, <S as TicketQueueStore>::Queue> as TicketManagement>::Error>
Creates a stream that redeems tickets in-order one by one in the given channel,
using the given ChainWriteTicketOperations on-chain client
implementation.
If min_redeem_value is given, all the tickets that are lower than the given value are neglected in the
process.
If there’s already an existing redeem stream for the channel, an error is returned without creating a new stream.
The stream terminates when there are no more tickets to process in the queue, or an error is encountered.
Source§fn neglect_tickets(
&self,
channel_id: &HashBase<CoreWrapper<Keccak256Core>>,
up_to_index: Option<u64>,
) -> Result<Vec<VerifiedTicket>, TicketManagerError>
fn neglect_tickets( &self, channel_id: &HashBase<CoreWrapper<Keccak256Core>>, up_to_index: Option<u64>, ) -> Result<Vec<VerifiedTicket>, TicketManagerError>
Removes all the tickets in the given ChannelId, optionally only up to the given ticket index (inclusive).
If the up_to_index is given and lower than the lowest index of an unredeemed ticket in the queue,
the function does nothing.
If there’s ticket redemption ongoing in the same channel and the neglection intersects with the redeemed range, the redemption will be cut short, with remaining unredeemed tickets neglected.
Source§fn ticket_stats(
&self,
channel: Option<&HashBase<CoreWrapper<Keccak256Core>>>,
) -> Result<ChannelStats, TicketManagerError>
fn ticket_stats( &self, channel: Option<&HashBase<CoreWrapper<Keccak256Core>>>, ) -> Result<ChannelStats, TicketManagerError>
Computes statistics for the given channel or for all channels if None is given.
If the given channel does not exist, it returns zero statistics instead of an error.
Apart from unredeemed_value, the statistics are not persistent.