Skip to content

Commit ff48a27

Browse files
committed
Introduce ALiquidityManager trait
.. in order to make handling generics easier, just as we do with `AChannelManager`, `AOnionMessenger`, etc.
1 parent a6ce072 commit ff48a27

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

lightning-liquidity/src/manager.rs

+39
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,45 @@ pub struct LiquidityClientConfig {
6464
pub lsps2_client_config: Option<LSPS2ClientConfig>,
6565
}
6666

67+
/// A trivial trait which describes any [`LiquidityManager`].
68+
///
69+
/// This is not exported to bindings users as general cover traits aren't useful in other
70+
/// languages.
71+
pub trait ALiquidityManager {
72+
/// A type implementing [`EntropySource`]
73+
type EntropySource: EntropySource + ?Sized;
74+
/// A type that may be dereferenced to [`Self::EntropySource`].
75+
type ES: Deref<Target = Self::EntropySource> + Clone;
76+
/// A type implementing [`AChannelManager`]
77+
type AChannelManager: AChannelManager + ?Sized;
78+
/// A type that may be dereferenced to [`Self::ChannelManager`].
79+
type CM: Deref<Target = Self::AChannelManager> + Clone;
80+
/// A type implementing [`Filter`].
81+
type Filter: Filter + ?Sized;
82+
/// A type that may be dereferenced to [`Self::Filter`].
83+
type C: Deref<Target = Self::Filter> + Clone;
84+
/// Returns a reference to the actual [`LiquidityManager`] object.
85+
fn get_lm(&self) -> &LiquidityManager<Self::ES, Self::CM, Self::C>;
86+
}
87+
88+
impl<ES: Deref + Clone, CM: Deref + Clone, C: Deref + Clone> ALiquidityManager
89+
for LiquidityManager<ES, CM, C>
90+
where
91+
ES::Target: EntropySource,
92+
CM::Target: AChannelManager,
93+
C::Target: Filter,
94+
{
95+
type EntropySource = ES::Target;
96+
type ES = ES;
97+
type AChannelManager = CM::Target;
98+
type CM = CM;
99+
type Filter = C::Target;
100+
type C = C;
101+
fn get_lm(&self) -> &LiquidityManager<ES, CM, C> {
102+
self
103+
}
104+
}
105+
67106
/// The main interface into LSP functionality.
68107
///
69108
/// Should be used as a [`CustomMessageHandler`] for your [`PeerManager`]'s [`MessageHandler`].

0 commit comments

Comments
 (0)