use std::collections::BTreeMap;
use bitcoin::secp256k1::schnorr::Signature;
use bitcoin::secp256k1::XOnlyPublicKey;
use lnpbp::chain::Chain;
use psbt::Psbt;
use crate::bifrost::{ChannelId, ChannelProposal, ProtocolName};
use crate::bolt;
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
#[derive(NetworkEncode, NetworkDecode)]
pub enum CommonFeeAlgo {
ByCoordinator,
SharedFee,
}
#[derive(Clone, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
#[derive(NetworkEncode, NetworkDecode)]
#[display("type: {channel_type:#x}, timestamp: {timestamp}")]
pub struct ChannelParams {
pub channel_type: u64,
pub chain: Chain,
pub parent_channel: Option<ChannelId>,
pub fee_algo: CommonFeeAlgo,
pub timestamp: chrono::DateTime<chrono::Utc>,
pub peer_timeout: u32,
pub funding_timeout: Option<u32>,
}
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
#[display(lowercase)]
pub enum ChannelState {
Proposed,
Accepted,
Finalized,
Active,
Reorg,
Paused,
Closing,
Abandoned,
}
#[derive(Clone, PartialOrd, Eq, PartialEq, Debug)]
pub struct PreChannel {
pub channel_id: ChannelId,
pub coordinator_node: XOnlyPublicKey,
pub channel_params: ChannelParams,
pub proposal: ChannelProposal,
pub finalized_at: Option<chrono::DateTime<chrono::Utc>>,
}
#[derive(Clone, PartialOrd, Eq, PartialEq, Debug, Display)]
#[derive(NetworkEncode, NetworkDecode)]
#[display("propose_channel(...)")]
pub struct ProposeChannel {
pub params: ChannelParams,
pub proposal: ChannelProposal,
pub pending: Vec<XOnlyPublicKey>,
pub accepted: BTreeMap<XOnlyPublicKey, Signature>,
}
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Debug, Display)]
#[derive(NetworkEncode, NetworkDecode)]
#[display("accept_channel({channel_id}, ...)")]
pub struct AcceptChannel {
pub channel_id: ChannelId,
pub updated_proposal: ChannelProposal,
pub signatures: BTreeMap<XOnlyPublicKey, Signature>,
}
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Debug, Display)]
#[derive(NetworkEncode, NetworkDecode)]
#[display("finalize_channel({channel_id}, ...)")]
pub struct FinalizeChannel {
pub channel_id: ChannelId,
pub proposal: ChannelProposal,
}
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
#[derive(NetworkEncode, NetworkDecode)]
#[display("move_channel({legacy_channel_id})")]
pub struct MoveChannel {
pub legacy_channel_id: bolt::ChannelId,
}
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
#[derive(NetworkEncode, NetworkDecode)]
#[display("remove_channel({channel_id})")]
pub struct RemoveChannel {
pub channel_id: ChannelId,
}
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Debug, Display)]
#[derive(NetworkEncode, NetworkDecode)]
#[display("update_channel_status({channel_id}, {new_status}, ...)")]
pub struct UpdateChannelStatus {
pub channel_id: ChannelId,
pub new_status: ChannelStatusUpdate,
pub pending: Vec<XOnlyPublicKey>,
pub accepted: BTreeMap<XOnlyPublicKey, Signature>,
}
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
#[derive(NetworkEncode, NetworkDecode)]
#[display(lowercase)]
pub enum ChannelStatusUpdate {
Ready,
Reorg,
Pause,
}
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Debug, Display)]
#[derive(NetworkEncode, NetworkDecode)]
#[display("upgrade_channel({channel_id}, {protocol}, ...)")]
pub struct UpgradeChannel {
pub channel_id: ChannelId,
pub protocol: ProtocolName,
pub accepted: BTreeMap<XOnlyPublicKey, Signature>,
}
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Debug, Display)]
#[derive(NetworkEncode, NetworkDecode)]
#[display("donwgrade_channel({channel_id}, {protocol}, ...)")]
pub struct DowngradeChannel {
pub channel_id: ChannelId,
pub protocol: ProtocolName,
pub accepted: BTreeMap<XOnlyPublicKey, Signature>,
}
#[derive(Clone, PartialEq, Eq, Debug, Display)]
#[derive(NetworkEncode, NetworkDecode)]
#[display("close_channel({channel_id}, ...)")]
pub struct CloseChannel {
pub channel_id: ChannelId,
pub closing_tx: Psbt,
pub accepted: BTreeMap<XOnlyPublicKey, Signature>,
}