use core::fmt::Debug; use std::io; use ciphersuite::Ciphersuite; use serai_client::primitives::{NetworkId, Balance}; use crate::{networks::Network, Db, Payment, Plan}; pub(crate) mod utxo; pub(crate) mod smart_contract; pub trait SchedulerAddendum: Send + Clone + PartialEq + Debug { fn read(reader: &mut R) -> io::Result; fn write(&self, writer: &mut W) -> io::Result<()>; } impl SchedulerAddendum for () { fn read(_: &mut R) -> io::Result { Ok(()) } fn write(&self, _: &mut W) -> io::Result<()> { Ok(()) } } pub trait Scheduler: Sized + Clone + PartialEq + Debug { type Addendum: SchedulerAddendum; /// Check if this Scheduler is empty. fn empty(&self) -> bool; /// Create a new Scheduler. fn new( txn: &mut D::Transaction<'_>, key: ::G, network: NetworkId, ) -> Self; /// Load a Scheduler from the DB. fn from_db( db: &D, key: ::G, network: NetworkId, ) -> io::Result; /// Check if a branch is usable. fn can_use_branch(&self, balance: Balance) -> bool; /// Schedule a series of outputs/payments. fn schedule( &mut self, txn: &mut D::Transaction<'_>, utxos: Vec, payments: Vec>, key_for_any_change: ::G, force_spend: bool, ) -> Vec>; /// Consume all payments still pending within this Scheduler, without scheduling them. fn consume_payments(&mut self, txn: &mut D::Transaction<'_>) -> Vec>; /// Note a branch output as having been created, with the amount it was actually created with, /// or not having been created due to being too small. fn created_output( &mut self, txn: &mut D::Transaction<'_>, expected: u64, actual: Option, ); /// Refund a specific output. fn refund_plan( &mut self, txn: &mut D::Transaction<'_>, output: N::Output, refund_to: N::Address, ) -> Plan; /// Shim the forwarding Plan as necessary to obtain a fee estimate. /// /// If this Scheduler is for a Network which requires forwarding, this must return Some with a /// plan with identical fee behavior. If forwarding isn't necessary, returns None. fn shim_forward_plan(output: N::Output, to: ::G) -> Option>; /// Forward a specific output to the new multisig. /// /// Returns None if no forwarding is necessary. Must return Some if forwarding is necessary. fn forward_plan( &mut self, txn: &mut D::Transaction<'_>, output: N::Output, to: ::G, ) -> Option>; }