mod swap_in;
mod swap_out;
use bitcoin::secp256k1::SecretKey;
use super::{
config::{ChainConfig, Config},
observe::Observed,
record::{Fund, Status, SwapRecord, Timestamp},
};
use crate::{
swap_script::{Side, Terms},
utxo::SwapUtxo,
};
#[derive(Clone, Debug)]
pub enum Action {
Send(Message),
Spend(Spend),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Message {
Cancel,
RefundKey,
Preimage,
}
#[derive(Clone, Debug)]
pub enum Spend {
Claim {
utxo: SwapUtxo,
path: Path,
fee_rate: f64,
replaces: Option<String>,
},
}
#[derive(Clone, Debug)]
pub enum Path {
Keypath { server_privkey: SecretKey },
Preimage,
}
#[derive(Clone, Debug)]
pub struct Decision {
pub action: Option<Action>,
pub status: Status,
}
pub fn decide(
record: &SwapRecord,
terms: &Terms,
observed: &Observed,
config: &Config,
chain_config: &ChainConfig,
) -> Decision {
match terms.side {
Side::Source => swap_in::decide(record, terms, observed, config, chain_config),
Side::Dest => swap_out::decide(record, terms, observed, config, chain_config),
}
}
pub fn funds(
record: &SwapRecord,
terms: &Terms,
observed: &Observed,
chain_config: &ChainConfig,
status: &Status,
) -> Vec<Fund> {
match terms.side {
Side::Source => swap_in::funds(record, terms, observed, chain_config, status),
Side::Dest => Vec::new(),
}
}
fn funding_deadline(record: &SwapRecord, config: &Config) -> Timestamp {
record.started_at + config.funding_timeout.as_secs()
}