1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::fmt;
/// This is an enum representing the status of a channel on the Lightning Network.
#[derive(Debug, Clone, Deserialize, Serialize)]
pub enum ChannelStatus {
/// The channel is online and ready to send and receive funds.
#[serde(rename = "OK")]
Ok,
/// The channel has been created, but the Bitcoin transaction that initiates it still needs to be confirmed on the Bitcoin blockchain.
#[serde(rename = "PENDING")]
Pending,
/// The channel is not available, likely because the peer is not online.
#[serde(rename = "OFFLINE")]
Offline,
/// The channel is behaving properly, but its remote balance is much higher than its local balance so it is not balanced properly for sending funds out.
#[serde(rename = "UNBALANCED_FOR_SEND")]
UnbalancedForSend,
/// The channel is behaving properly, but its remote balance is much lower than its local balance so it is not balanced properly for receiving funds.
#[serde(rename = "UNBALANCED_FOR_RECEIVE")]
UnbalancedForReceive,
/// The channel has been closed. Information about the channel is still available for historical purposes but the channel cannot be used anymore.
#[serde(rename = "CLOSED")]
Closed,
/// Something unexpected happened and we cannot determine the status of this channel. Please try again later or contact the support.
#[serde(rename = "ERROR")]
Error,
}
impl From<ChannelStatus> for Value {
fn from(val: ChannelStatus) -> Self {
Value::from(val.to_string())
}
}
impl fmt::Display for ChannelStatus {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Ok => write!(f, "OK"),
Self::Pending => write!(f, "PENDING"),
Self::Offline => write!(f, "OFFLINE"),
Self::UnbalancedForSend => write!(f, "UNBALANCED_FOR_SEND"),
Self::UnbalancedForReceive => write!(f, "UNBALANCED_FOR_RECEIVE"),
Self::Closed => write!(f, "CLOSED"),
Self::Error => write!(f, "ERROR"),
}
}
}