switchgear_service/lnurl/pay/
state.rs

1use crate::axum::extract::host::AllowedHosts;
2use crate::axum::extract::scheme::Scheme;
3use axum::extract::FromRef;
4use std::collections::HashSet;
5use switchgear_service_api::balance::LnBalancer;
6use switchgear_service_api::offer::OfferProvider;
7
8#[derive(Debug, Clone)]
9pub struct LnUrlPayState<O, B> {
10    partitions: HashSet<String>,
11    scheme: Scheme,
12    offer_provider: O,
13    balancer: B,
14    invoice_expiry: u64,
15    allowed_hosts: AllowedHosts,
16    comment_allowed: Option<u32>,
17    bech32_qr_scale: usize,
18    bech32_qr_light: u8,
19    bech32_qr_dark: u8,
20}
21
22impl<O, B> FromRef<LnUrlPayState<O, B>> for Scheme {
23    fn from_ref(input: &LnUrlPayState<O, B>) -> Self {
24        input.scheme.clone()
25    }
26}
27
28impl<O, B> FromRef<LnUrlPayState<O, B>> for AllowedHosts {
29    fn from_ref(input: &LnUrlPayState<O, B>) -> Self {
30        input.allowed_hosts.clone()
31    }
32}
33
34impl<O, B> LnUrlPayState<O, B>
35where
36    O: OfferProvider + Clone,
37    B: LnBalancer,
38{
39    #[allow(clippy::too_many_arguments)]
40    pub fn new(
41        partitions: HashSet<String>,
42        offer_provider: O,
43        balancer: B,
44        invoice_expiry: u64,
45        scheme: Scheme,
46        allowed_hosts: HashSet<String>,
47        comment_allowed: Option<u32>,
48        bech32_qr_scale: usize,
49        bech32_qr_light: u8,
50        bech32_qr_dark: u8,
51    ) -> Self {
52        Self {
53            partitions,
54            offer_provider,
55            balancer,
56            invoice_expiry,
57            scheme,
58            allowed_hosts: AllowedHosts(allowed_hosts),
59            comment_allowed,
60            bech32_qr_scale,
61            bech32_qr_light,
62            bech32_qr_dark,
63        }
64    }
65
66    pub fn offer_provider(&self) -> &O {
67        &self.offer_provider
68    }
69
70    pub fn balancer(&self) -> &B {
71        &self.balancer
72    }
73
74    pub fn invoice_expiry(&self) -> u64 {
75        self.invoice_expiry
76    }
77
78    pub fn partitions(&self) -> &HashSet<String> {
79        &self.partitions
80    }
81
82    pub fn comment_allowed(&self) -> Option<u32> {
83        self.comment_allowed
84    }
85
86    pub fn bech32_qr_scale(&self) -> usize {
87        self.bech32_qr_scale
88    }
89
90    pub fn bech32_qr_light(&self) -> u8 {
91        self.bech32_qr_light
92    }
93
94    pub fn bech32_qr_dark(&self) -> u8 {
95        self.bech32_qr_dark
96    }
97}