2024-09-01 05:55:04 +00:00
|
|
|
use core::marker::PhantomData;
|
|
|
|
|
|
|
|
use group::GroupEncoding;
|
|
|
|
|
2024-09-02 20:09:52 +00:00
|
|
|
use serai_primitives::{Coin, Amount};
|
2024-09-01 05:55:04 +00:00
|
|
|
|
|
|
|
use serai_db::{Get, DbTxn, create_db};
|
|
|
|
|
|
|
|
use primitives::ReceivedOutput;
|
|
|
|
use scanner::{ScannerFeed, KeyFor, OutputFor};
|
|
|
|
|
|
|
|
create_db! {
|
|
|
|
TransactionChainingScheduler {
|
2024-09-02 20:09:52 +00:00
|
|
|
OperatingCosts: (coin: Coin) -> Amount,
|
2024-09-01 05:55:04 +00:00
|
|
|
SerializedOutputs: (key: &[u8], coin: Coin) -> Vec<u8>,
|
2024-09-02 20:09:52 +00:00
|
|
|
// We should be immediately able to schedule the fulfillment of payments, yet this may not be
|
|
|
|
// possible if we're in the middle of a multisig rotation (as our output set will be split)
|
|
|
|
SerializedQueuedPayments: (key: &[u8]) > Vec<u8>,
|
2024-09-01 05:55:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) struct Db<S: ScannerFeed>(PhantomData<S>);
|
|
|
|
impl<S: ScannerFeed> Db<S> {
|
2024-09-02 20:09:52 +00:00
|
|
|
pub(crate) fn operating_costs(getter: &impl Get, coin: Coin) -> Amount {
|
|
|
|
OperatingCosts::get(getter, coin).unwrap_or(Amount(0))
|
|
|
|
}
|
|
|
|
pub(crate) fn set_operating_costs(txn: &mut impl DbTxn, coin: Coin, amount: Amount) {
|
|
|
|
OperatingCosts::set(txn, coin, &amount)
|
|
|
|
}
|
|
|
|
|
2024-09-01 05:55:04 +00:00
|
|
|
pub(crate) fn outputs(
|
|
|
|
getter: &impl Get,
|
|
|
|
key: KeyFor<S>,
|
|
|
|
coin: Coin,
|
|
|
|
) -> Option<Vec<OutputFor<S>>> {
|
|
|
|
let buf = SerializedOutputs::get(getter, key.to_bytes().as_ref(), coin)?;
|
|
|
|
let mut buf = buf.as_slice();
|
|
|
|
|
|
|
|
let mut res = Vec::with_capacity(buf.len() / 128);
|
|
|
|
while !buf.is_empty() {
|
|
|
|
res.push(OutputFor::<S>::read(&mut buf).unwrap());
|
|
|
|
}
|
|
|
|
Some(res)
|
|
|
|
}
|
|
|
|
pub(crate) fn set_outputs(
|
|
|
|
txn: &mut impl DbTxn,
|
|
|
|
key: KeyFor<S>,
|
|
|
|
coin: Coin,
|
|
|
|
outputs: &[OutputFor<S>],
|
|
|
|
) {
|
|
|
|
let mut buf = Vec::with_capacity(outputs.len() * 128);
|
|
|
|
for output in outputs {
|
|
|
|
output.write(&mut buf).unwrap();
|
|
|
|
}
|
|
|
|
SerializedOutputs::set(txn, key.to_bytes().as_ref(), coin, &buf);
|
|
|
|
}
|
|
|
|
pub(crate) fn del_outputs(txn: &mut impl DbTxn, key: KeyFor<S>, coin: Coin) {
|
|
|
|
SerializedOutputs::del(txn, key.to_bytes().as_ref(), coin);
|
|
|
|
}
|
2024-09-02 20:09:52 +00:00
|
|
|
|
|
|
|
pub(crate) fn queued_payments(
|
|
|
|
getter: &impl Get,
|
|
|
|
key: KeyFor<S>,
|
|
|
|
) -> Option<Vec<Payment<S>>> {
|
|
|
|
todo!("TODO")
|
|
|
|
}
|
|
|
|
pub(crate) fn set_queued_payments(txn: &mut impl DbTxn, key: KeyFor<S>, queued: Vec<Payment<S>>) {
|
|
|
|
todo!("TODO")
|
|
|
|
}
|
|
|
|
pub(crate) fn del_outputs(txn: &mut impl DbTxn, key: KeyFor<S>) {
|
|
|
|
SerializedQueuedPayments::del(txn, key.to_bytes().as_ref());
|
|
|
|
}
|
2024-09-01 05:55:04 +00:00
|
|
|
}
|