bright-ln-models 0.1.0

Models for the working with LND nodes
Documentation
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LndPaymentRequest {
    payment_request: String,  // String
    timeout_seconds: i32,     // Int32
    fee_limit_sat: String,    // Int64
    allow_self_payment: bool, // Bool
}
impl LndPaymentRequest {
    #[must_use]
    pub const fn new(
        payment_request: String,
        timeout_seconds: i32,
        fee_limit_sat: String,
        allow_self_payment: bool,
    ) -> Self {
        Self {
            payment_request,
            timeout_seconds,
            fee_limit_sat,
            allow_self_payment,
        }
    }
}

impl std::str::FromStr for LndPaymentRequest {
    type Err = serde_json::Error;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        serde_json::from_str(s)
    }
}
impl TryFrom<LndPaymentRequest> for String {
    type Error = serde_json::Error;

    fn try_from(value: LndPaymentRequest) -> Result<Self, Self::Error> {
        serde_json::to_string(&value)
    }
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum InvoicePaymentState {
    #[serde(rename = "IN_FLIGHT")]
    InFlight,
    #[serde(rename = "SUCCEEDED")]
    Succeeded,
    #[serde(rename = "FAILED")]
    Failed,
    #[serde(rename = "INITIATED")]
    Initiaited,
}
impl std::str::FromStr for InvoicePaymentState {
    type Err = serde_json::Error;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        serde_json::from_str(s)
    }
}
impl AsRef<str> for InvoicePaymentState {
    fn as_ref(&self) -> &str {
        match self {
            Self::InFlight => "IN_FLIGHT",
            Self::Succeeded => "SUCCEEDED",
            Self::Failed => "FAILED",
            Self::Initiaited => "INITIATED",
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LndPaymentResponse {
    payment_preimage: String,
    status: InvoicePaymentState,
}
impl LndPaymentResponse {
    #[must_use]
    pub fn preimage(&self) -> String {
        self.payment_preimage.clone()
    }
    #[must_use]
    pub fn status(&self) -> InvoicePaymentState {
        self.status.clone()
    }
}
impl std::str::FromStr for LndPaymentResponse {
    type Err = serde_json::Error;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        serde_json::from_str(s)
    }
}
impl TryFrom<LndPaymentResponse> for String {
    type Error = serde_json::Error;
    fn try_from(value: LndPaymentResponse) -> Result<Self, Self::Error> {
        serde_json::to_string(&value)
    }
}