Skip to content

Commit 523900f

Browse files
committed
WIP Implement KVStore for VssStore
We implement the async `KVStore` trait for `VssStore`.
1 parent 0686ece commit 523900f

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

src/io/vss_store.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::runtime::Runtime;
1010

1111
use bitcoin::hashes::{sha256, Hash, HashEngine, Hmac, HmacEngine};
1212
use lightning::io::{self, Error, ErrorKind};
13-
use lightning::util::persist::KVStoreSync;
13+
use lightning::util::persist::{KVStore, KVStoreSync};
1414
use prost::Message;
1515
use rand::RngCore;
1616
#[cfg(test)]
@@ -31,6 +31,10 @@ use vss_client::util::retry::{
3131
};
3232
use vss_client::util::storable_builder::{EntropySource, StorableBuilder};
3333

34+
use std::boxed::Box;
35+
use std::future::Future;
36+
use std::pin::Pin;
37+
3438
type CustomRetryPolicy = FilteredRetryPolicy<
3539
JitteredRetryPolicy<
3640
MaxTotalDelayRetryPolicy<MaxAttemptsRetryPolicy<ExponentialBackoffRetryPolicy<VssError>>>,
@@ -82,6 +86,50 @@ impl KVStoreSync for VssStore {
8286
}
8387
}
8488

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+
85133
struct VssStoreInner {
86134
client: VssClient<CustomRetryPolicy>,
87135
store_id: String,

0 commit comments

Comments
 (0)