1- //! Object-safe wrapper around ldk-node's `KVStore` + `KVStoreSync` traits .
1+ //! Object-safe wrapper around ldk-node's async `KVStore` trait .
22//!
33//! `lightning`'s `KVStore` returns `impl Future` from its methods, which makes the trait not
4- //! object-safe — orange-sdk can't share a backend across components as `Arc<dyn KVStore>`. The
5- //! supertrait `SyncAndAsyncKVStore` that ldk-node exposes inherits the same problem, and even
6- //! if it didn't, no `Deref` blanket impl exists for `KVStoreSync`, so `Arc<...>` doesn't satisfy
7- //! it on its own.
4+ //! object-safe — orange-sdk can't share a backend across components as `Arc<dyn KVStore>`.
85//!
9- //! This module defines `DynStore`, an object-safe trait covering both sync and async kv
10- //! methods (async ones return boxed futures), with a blanket impl over any concrete type that
11- //! implements `KVStore + KVStoreSync`. The whole crate stores backends as
12- //! `Arc<dyn DynStore>`; conversion to a value ldk-node accepts happens at the call site
13- //! through a thin newtype that delegates both traits back to `DynStore`.
6+ //! This module defines `DynStore`, an object-safe trait covering the kv methods (returning
7+ //! boxed futures), with a blanket impl over any concrete type that implements `KVStore`. The
8+ //! whole crate stores backends as `Arc<dyn DynStore>`; conversion to a value ldk-node accepts
9+ //! happens at the call site through a thin newtype that delegates back to `DynStore`.
1410
1511use std:: future:: Future ;
1612use std:: pin:: Pin ;
1713use std:: sync:: Arc ;
1814
1915use ldk_node:: lightning:: io;
20- use ldk_node:: lightning:: util:: persist:: { KVStore , KVStoreSync } ;
16+ use ldk_node:: lightning:: util:: persist:: KVStore ;
2117
22- /// Object-safe view of a `KVStore + KVStoreSync ` backend. Async methods return boxed
23- /// futures so the trait can be used through `dyn`.
18+ /// Object-safe view of a `KVStore` backend. Async methods return boxed futures so the trait
19+ /// can be used through `dyn`.
2420pub ( crate ) trait DynStore : Send + Sync + ' static {
2521 fn read_async (
2622 & self , primary_namespace : & str , secondary_namespace : & str , key : & str ,
@@ -37,27 +33,11 @@ pub(crate) trait DynStore: Send + Sync + 'static {
3733 fn list_async (
3834 & self , primary_namespace : & str , secondary_namespace : & str ,
3935 ) -> Pin < Box < dyn Future < Output = Result < Vec < String > , io:: Error > > + Send + ' static > > ;
40-
41- fn read_sync (
42- & self , primary_namespace : & str , secondary_namespace : & str , key : & str ,
43- ) -> Result < Vec < u8 > , io:: Error > ;
44-
45- fn write_sync (
46- & self , primary_namespace : & str , secondary_namespace : & str , key : & str , buf : Vec < u8 > ,
47- ) -> Result < ( ) , io:: Error > ;
48-
49- fn remove_sync (
50- & self , primary_namespace : & str , secondary_namespace : & str , key : & str , lazy : bool ,
51- ) -> Result < ( ) , io:: Error > ;
52-
53- fn list_sync (
54- & self , primary_namespace : & str , secondary_namespace : & str ,
55- ) -> Result < Vec < String > , io:: Error > ;
5636}
5737
5838impl < T > DynStore for T
5939where
60- T : KVStore + KVStoreSync + Send + Sync + ' static ,
40+ T : KVStore + Send + Sync + ' static ,
6141{
6242 fn read_async (
6343 & self , p : & str , s : & str , k : & str ,
@@ -82,33 +62,12 @@ where
8262 ) -> Pin < Box < dyn Future < Output = Result < Vec < String > , io:: Error > > + Send + ' static > > {
8363 Box :: pin ( <T as KVStore >:: list ( self , p, s) )
8464 }
85-
86- fn read_sync ( & self , p : & str , s : & str , k : & str ) -> Result < Vec < u8 > , io:: Error > {
87- <T as KVStoreSync >:: read ( self , p, s, k)
88- }
89-
90- fn write_sync ( & self , p : & str , s : & str , k : & str , buf : Vec < u8 > ) -> Result < ( ) , io:: Error > {
91- <T as KVStoreSync >:: write ( self , p, s, k, buf)
92- }
93-
94- fn remove_sync ( & self , p : & str , s : & str , k : & str , lazy : bool ) -> Result < ( ) , io:: Error > {
95- <T as KVStoreSync >:: remove ( self , p, s, k, lazy)
96- }
97-
98- fn list_sync ( & self , p : & str , s : & str ) -> Result < Vec < String > , io:: Error > {
99- <T as KVStoreSync >:: list ( self , p, s)
100- }
10165}
10266
103- // Make `Arc<dyn DynStore>` itself implement `KVStore` + `KVStoreSync` so the same handle
104- // orange-sdk shares internally can be handed to ldk-node's `build_with_store`. We give it
105- // `KVStore::read` etc. by forwarding to the boxed-future variants on the trait, and the
106- // sync trait by forwarding to the sync variants.
107- //
108- // Note: we impl on `dyn DynStore` (which is local), not `Arc` directly — that gives us
109- // `&dyn DynStore: KVStore + KVStoreSync` and, via lightning's `Deref` blanket impl for
110- // `KVStore`, `Arc<dyn DynStore>: KVStore`. For `KVStoreSync` (no `Deref` blanket exists)
111- // callers wrap the `Arc` in `LdkNodeStore` below before handing it to ldk-node.
67+ // Make `dyn DynStore` itself implement `KVStore` so the same handle orange-sdk shares
68+ // internally can be handed to ldk-node's `build_with_store`. We forward to the boxed-future
69+ // variants on the trait. Via lightning's `Deref` blanket impl for `KVStore`, this gives us
70+ // `Arc<dyn DynStore>: KVStore` too.
11271impl KVStore for dyn DynStore {
11372 fn read (
11473 & self , p : & str , s : & str , k : & str ,
@@ -132,24 +91,9 @@ impl KVStore for dyn DynStore {
13291 }
13392}
13493
135- impl KVStoreSync for dyn DynStore {
136- fn read ( & self , p : & str , s : & str , k : & str ) -> Result < Vec < u8 > , io:: Error > {
137- self . read_sync ( p, s, k)
138- }
139- fn write ( & self , p : & str , s : & str , k : & str , buf : Vec < u8 > ) -> Result < ( ) , io:: Error > {
140- self . write_sync ( p, s, k, buf)
141- }
142- fn remove ( & self , p : & str , s : & str , k : & str , lazy : bool ) -> Result < ( ) , io:: Error > {
143- self . remove_sync ( p, s, k, lazy)
144- }
145- fn list ( & self , p : & str , s : & str ) -> Result < Vec < String > , io:: Error > {
146- self . list_sync ( p, s)
147- }
148- }
149-
15094/// Cloneable handle wrapping `Arc<dyn DynStore>` that satisfies ldk-node's
151- /// `SyncAndAsyncKVStore + Send + Sync + 'static` bound on `build_with_store`. Both trait
152- /// impls just forward to the underlying `dyn DynStore`.
95+ /// `KVStore + Send + Sync + 'static` bound on `build_with_store`. The trait impl just
96+ /// forwards to the underlying `dyn DynStore`.
15397#[ derive( Clone ) ]
15498pub ( crate ) struct LdkNodeStore ( pub ( crate ) Arc < dyn DynStore > ) ;
15599
@@ -175,18 +119,3 @@ impl KVStore for LdkNodeStore {
175119 self . 0 . list_async ( p, s)
176120 }
177121}
178-
179- impl KVStoreSync for LdkNodeStore {
180- fn read ( & self , p : & str , s : & str , k : & str ) -> Result < Vec < u8 > , io:: Error > {
181- self . 0 . read_sync ( p, s, k)
182- }
183- fn write ( & self , p : & str , s : & str , k : & str , buf : Vec < u8 > ) -> Result < ( ) , io:: Error > {
184- self . 0 . write_sync ( p, s, k, buf)
185- }
186- fn remove ( & self , p : & str , s : & str , k : & str , lazy : bool ) -> Result < ( ) , io:: Error > {
187- self . 0 . remove_sync ( p, s, k, lazy)
188- }
189- fn list ( & self , p : & str , s : & str ) -> Result < Vec < String > , io:: Error > {
190- self . 0 . list_sync ( p, s)
191- }
192- }
0 commit comments