|
5 | 5 | // http://opensource.org/licenses/MIT>, at your option. You may not use this file except in |
6 | 6 | // accordance with one or both of these licenses. |
7 | 7 |
|
| 8 | +use std::boxed::Box; |
| 9 | +use std::future::Future; |
8 | 10 | #[cfg(test)] |
9 | 11 | use std::panic::RefUnwindSafe; |
| 12 | +use std::pin::Pin; |
10 | 13 | use std::sync::Arc; |
11 | 14 | use std::time::Duration; |
12 | 15 |
|
13 | 16 | use bitcoin::hashes::{sha256, Hash, HashEngine, Hmac, HmacEngine}; |
14 | 17 | use lightning::io::{self, Error, ErrorKind}; |
15 | | -use lightning::util::persist::KVStoreSync; |
| 18 | +use lightning::util::persist::{KVStore, KVStoreSync}; |
16 | 19 | use prost::Message; |
17 | 20 | use rand::RngCore; |
18 | 21 | use vss_client::client::VssClient; |
@@ -83,6 +86,50 @@ impl KVStoreSync for VssStore { |
83 | 86 | } |
84 | 87 | } |
85 | 88 |
|
| 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 | + |
86 | 133 | struct VssStoreInner { |
87 | 134 | client: VssClient<CustomRetryPolicy>, |
88 | 135 | store_id: String, |
|
0 commit comments