@@ -3,7 +3,7 @@ use std::io::Read;
3
3
use std:: sync:: Arc ;
4
4
use std:: { error:: Error , io} ;
5
5
6
- use super :: * ;
6
+ use crate :: io :: get_namespace_and_key_from_prefixed ;
7
7
use crate :: KVStore ;
8
8
use lightning:: util:: persist:: KVStorePersister ;
9
9
use lightning:: util:: ser:: Writeable ;
@@ -14,22 +14,17 @@ use vss_client::types::{
14
14
DeleteObjectRequest , GetObjectRequest , KeyValue , ListKeyVersionsRequest , PutObjectRequest ,
15
15
} ;
16
16
17
- /// Implements [KVStore] and [KVStorePersister] for VSS using [VssClient].
18
- ///
19
- /// A [`KVStore`] implementation that writes to and reads from VSS using [VssClient].
20
- ///
21
- /// Learn more about Versioned Storage Service (VSS) [here](https://github.com/lightningdevkit/vss-server/blob/main/README.md).
22
- pub struct VssKVStore {
17
+ /// A [`KVStore`] implementation that writes to and reads from a [VSS](https://github.com/lightningdevkit/vss-server/blob/main/README.md) backend.
18
+ pub struct VssStore {
23
19
client : VssClient ,
24
20
store_id : String ,
25
- runtime : Arc < Runtime > ,
21
+ runtime : Runtime ,
26
22
}
27
23
28
- impl VssKVStore {
24
+ impl VssStore {
29
25
pub ( crate ) fn new ( base_url : & str , store_id : String ) -> Self {
30
26
let client = VssClient :: new ( base_url) ;
31
- let runtime =
32
- Arc :: new ( tokio:: runtime:: Builder :: new_multi_thread ( ) . enable_all ( ) . build ( ) . unwrap ( ) ) ;
27
+ let runtime = tokio:: runtime:: Builder :: new_multi_thread ( ) . enable_all ( ) . build ( ) . unwrap ( ) ;
33
28
Self { client, store_id, runtime }
34
29
}
35
30
@@ -71,7 +66,7 @@ impl VssKVStore {
71
66
}
72
67
}
73
68
74
- impl KVStore for VssKVStore {
69
+ impl KVStore for VssStore {
75
70
type Reader = Cursor < Vec < u8 > > ;
76
71
77
72
fn read ( & self , namespace : & str , key : & str ) -> io:: Result < Self :: Reader > {
@@ -148,18 +143,19 @@ impl KVStore for VssKVStore {
148
143
}
149
144
}
150
145
151
- impl KVStorePersister for VssKVStore {
146
+ impl KVStorePersister for VssStore {
152
147
fn persist < W : Writeable > ( & self , prefixed_key : & str , object : & W ) -> io:: Result < ( ) > {
153
- self . write ( "" , & prefixed_key, & object. encode ( ) ) ?;
148
+ let ( namespace, key) = self . split_key ( prefixed_key) ;
149
+ self . write ( & namespace, & key, & object. encode ( ) ) ?;
154
150
Ok ( ( ) )
155
151
}
156
152
}
157
153
158
154
#[ cfg( test) ]
159
155
mod tests {
160
156
use super :: * ;
157
+ use crate :: io:: do_read_write_remove_list_persist;
161
158
use crate :: test:: utils:: random_storage_path;
162
-
163
159
use proptest:: prelude:: * ;
164
160
proptest ! {
165
161
#[ test]
@@ -168,11 +164,11 @@ mod tests {
168
164
if vss_base_url. is_ok( )
169
165
{
170
166
let rand_store_id = random_storage_path( ) ;
171
- let vss_store = VssKVStore :: new( & vss_base_url. unwrap( ) , rand_store_id) ;
167
+ let vss_store = VssStore :: new( & vss_base_url. unwrap( ) , rand_store_id) ;
172
168
173
169
do_read_write_remove_list_persist( & data, & vss_store) ;
174
170
} else{
175
- eprintln!( "** SKIPPING `VssKVStore ` test-suite since environment variable `TEST_VSS_BASE_URL` is not set **" ) ;
171
+ eprintln!( "** SKIPPING `VssStore ` test-suite since environment variable `TEST_VSS_BASE_URL` is not set **" ) ;
176
172
}
177
173
}
178
174
}
0 commit comments