bright_lightning/lnd/models/
invoice_request.rs

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
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LndInvoiceRequest {
    form: String,
}
impl LndInvoiceRequest {
    pub fn from_body(body: LndInvoiceRequestBody) -> Self {
        Self {
            form: body.to_string(),
        }
    }
    pub fn new(amount: u64) -> Self {
        let body = LndInvoiceRequestBody {
            value: amount.to_string(),
            memo: None,
        };
        Self {
            form: body.to_string(),
        }
    }
}
impl ToString for LndInvoiceRequest {
    fn to_string(&self) -> String {
        serde_json::to_string(self).unwrap()
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LndInvoiceRequestBody {
    pub value: String,
    pub memo: Option<String>,
}
impl Default for LndInvoiceRequestBody {
    fn default() -> Self {
        Self {
            value: "".to_string(),
            memo: None,
        }
    }
}
impl ToString for LndInvoiceRequestBody {
    fn to_string(&self) -> String {
        serde_json::to_string(self).unwrap()
    }
}
impl LndInvoiceRequestBody {
    pub fn new(value: String, memo: Option<String>) -> Self {
        Self { value, memo }
    }
}