@@ -57,7 +57,7 @@ use crate::util::dyn_signer::{
57
57
use crate :: util:: logger:: { Logger , Record } ;
58
58
#[ cfg( feature = "std" ) ]
59
59
use crate :: util:: mut_global:: MutGlobal ;
60
- use crate :: util:: persist:: { KVStoreSync , MonitorName } ;
60
+ use crate :: util:: persist:: { KVStore , KVStoreSync , MonitorName } ;
61
61
use crate :: util:: ser:: { Readable , ReadableArgs , Writeable , Writer } ;
62
62
use crate :: util:: test_channel_signer:: { EnforcementState , TestChannelSigner } ;
63
63
@@ -84,7 +84,10 @@ use crate::io;
84
84
use crate :: prelude:: * ;
85
85
use crate :: sign:: { EntropySource , NodeSigner , RandomBytes , Recipient , SignerProvider } ;
86
86
use crate :: sync:: { Arc , Mutex } ;
87
+ use alloc:: boxed:: Box ;
88
+ use core:: future:: Future ;
87
89
use core:: mem;
90
+ use core:: pin:: Pin ;
88
91
use core:: sync:: atomic:: { AtomicBool , AtomicUsize , Ordering } ;
89
92
use core:: time:: Duration ;
90
93
@@ -863,10 +866,8 @@ impl TestStore {
863
866
let persisted_bytes = Mutex :: new ( new_hash_map ( ) ) ;
864
867
Self { persisted_bytes, read_only }
865
868
}
866
- }
867
869
868
- impl KVStoreSync for TestStore {
869
- fn read (
870
+ fn read_internal (
870
871
& self , primary_namespace : & str , secondary_namespace : & str , key : & str ,
871
872
) -> io:: Result < Vec < u8 > > {
872
873
let persisted_lock = self . persisted_bytes . lock ( ) . unwrap ( ) ;
@@ -888,7 +889,7 @@ impl KVStoreSync for TestStore {
888
889
}
889
890
}
890
891
891
- fn write (
892
+ fn write_internal (
892
893
& self , primary_namespace : & str , secondary_namespace : & str , key : & str , buf : Vec < u8 > ,
893
894
) -> io:: Result < ( ) > {
894
895
if self . read_only {
@@ -911,7 +912,7 @@ impl KVStoreSync for TestStore {
911
912
Ok ( ( ) )
912
913
}
913
914
914
- fn remove (
915
+ fn remove_internal (
915
916
& self , primary_namespace : & str , secondary_namespace : & str , key : & str , _lazy : bool ,
916
917
) -> io:: Result < ( ) > {
917
918
if self . read_only {
@@ -935,7 +936,9 @@ impl KVStoreSync for TestStore {
935
936
Ok ( ( ) )
936
937
}
937
938
938
- fn list ( & self , primary_namespace : & str , secondary_namespace : & str ) -> io:: Result < Vec < String > > {
939
+ fn list_internal (
940
+ & self , primary_namespace : & str , secondary_namespace : & str ,
941
+ ) -> io:: Result < Vec < String > > {
939
942
let mut persisted_lock = self . persisted_bytes . lock ( ) . unwrap ( ) ;
940
943
941
944
let prefixed = if secondary_namespace. is_empty ( ) {
@@ -950,6 +953,57 @@ impl KVStoreSync for TestStore {
950
953
}
951
954
}
952
955
956
+ impl KVStore for TestStore {
957
+ fn read (
958
+ & self , primary_namespace : & str , secondary_namespace : & str , key : & str ,
959
+ ) -> Pin < Box < dyn Future < Output = Result < Vec < u8 > , io:: Error > > + ' static + Send > > {
960
+ let res = self . read_internal ( & primary_namespace, & secondary_namespace, & key) ;
961
+ Box :: pin ( async move { res } )
962
+ }
963
+ fn write (
964
+ & self , primary_namespace : & str , secondary_namespace : & str , key : & str , buf : Vec < u8 > ,
965
+ ) -> Pin < Box < dyn Future < Output = Result < ( ) , io:: Error > > + ' static + Send > > {
966
+ let res = self . write_internal ( & primary_namespace, & secondary_namespace, & key, buf) ;
967
+ Box :: pin ( async move { res } )
968
+ }
969
+ fn remove (
970
+ & self , primary_namespace : & str , secondary_namespace : & str , key : & str , lazy : bool ,
971
+ ) -> Pin < Box < dyn Future < Output = Result < ( ) , io:: Error > > + ' static + Send > > {
972
+ let res = self . remove_internal ( & primary_namespace, & secondary_namespace, & key, lazy) ;
973
+ Box :: pin ( async move { res } )
974
+ }
975
+ fn list (
976
+ & self , primary_namespace : & str , secondary_namespace : & str ,
977
+ ) -> Pin < Box < dyn Future < Output = Result < Vec < String > , io:: Error > > + ' static + Send > > {
978
+ let res = self . list_internal ( primary_namespace, secondary_namespace) ;
979
+ Box :: pin ( async move { res } )
980
+ }
981
+ }
982
+
983
+ impl KVStoreSync for TestStore {
984
+ fn read (
985
+ & self , primary_namespace : & str , secondary_namespace : & str , key : & str ,
986
+ ) -> io:: Result < Vec < u8 > > {
987
+ self . read_internal ( primary_namespace, secondary_namespace, key)
988
+ }
989
+
990
+ fn write (
991
+ & self , primary_namespace : & str , secondary_namespace : & str , key : & str , buf : Vec < u8 > ,
992
+ ) -> io:: Result < ( ) > {
993
+ self . write_internal ( primary_namespace, secondary_namespace, key, buf)
994
+ }
995
+
996
+ fn remove (
997
+ & self , primary_namespace : & str , secondary_namespace : & str , key : & str , lazy : bool ,
998
+ ) -> io:: Result < ( ) > {
999
+ self . remove_internal ( primary_namespace, secondary_namespace, key, lazy)
1000
+ }
1001
+
1002
+ fn list ( & self , primary_namespace : & str , secondary_namespace : & str ) -> io:: Result < Vec < String > > {
1003
+ self . list_internal ( primary_namespace, secondary_namespace)
1004
+ }
1005
+ }
1006
+
953
1007
unsafe impl Sync for TestStore { }
954
1008
unsafe impl Send for TestStore { }
955
1009
0 commit comments