Skip to content

Commit deee704

Browse files
committed
Implement KVStore for VssStore
We implement the async `KVStore` trait for `VssStore`.
1 parent 9d08b27 commit deee704

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

src/io/vss_store.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
66
// accordance with one or both of these licenses.
77

8+
use std::boxed::Box;
9+
use std::future::Future;
810
#[cfg(test)]
911
use std::panic::RefUnwindSafe;
12+
use std::pin::Pin;
1013
use std::sync::Arc;
1114
use std::time::Duration;
1215

1316
use bitcoin::hashes::{sha256, Hash, HashEngine, Hmac, HmacEngine};
1417
use lightning::io::{self, Error, ErrorKind};
15-
use lightning::util::persist::KVStoreSync;
18+
use lightning::util::persist::{KVStore, KVStoreSync};
1619
use prost::Message;
1720
use rand::RngCore;
1821
use vss_client::client::VssClient;
@@ -83,6 +86,50 @@ impl KVStoreSync for VssStore {
8386
}
8487
}
8588

89+
impl KVStore for VssStore {
90+
fn read(
91+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
92+
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, io::Error>> + Send>> {
93+
let primary_namespace = primary_namespace.to_string();
94+
let secondary_namespace = secondary_namespace.to_string();
95+
let key = key.to_string();
96+
let inner = Arc::clone(&self.inner);
97+
Box::pin(async move {
98+
inner.read_internal(&primary_namespace, &secondary_namespace, &key).await
99+
})
100+
}
101+
fn write(
102+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
103+
) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + Send>> {
104+
let primary_namespace = primary_namespace.to_string();
105+
let secondary_namespace = secondary_namespace.to_string();
106+
let key = key.to_string();
107+
let inner = Arc::clone(&self.inner);
108+
Box::pin(async move {
109+
inner.write_internal(&primary_namespace, &secondary_namespace, &key, buf).await
110+
})
111+
}
112+
fn remove(
113+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool,
114+
) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + Send>> {
115+
let primary_namespace = primary_namespace.to_string();
116+
let secondary_namespace = secondary_namespace.to_string();
117+
let key = key.to_string();
118+
let inner = Arc::clone(&self.inner);
119+
Box::pin(async move {
120+
inner.remove_internal(&primary_namespace, &secondary_namespace, &key, lazy).await
121+
})
122+
}
123+
fn list(
124+
&self, primary_namespace: &str, secondary_namespace: &str,
125+
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, io::Error>> + Send>> {
126+
let primary_namespace = primary_namespace.to_string();
127+
let secondary_namespace = secondary_namespace.to_string();
128+
let inner = Arc::clone(&self.inner);
129+
Box::pin(async move { inner.list_internal(&primary_namespace, &secondary_namespace).await })
130+
}
131+
}
132+
86133
struct VssStoreInner {
87134
client: VssClient<CustomRetryPolicy>,
88135
store_id: String,

0 commit comments

Comments
 (0)