@@ -57,7 +57,7 @@ use crate::util::dyn_signer::{
5757use crate :: util:: logger:: { Logger , Record } ;
5858#[ cfg( feature = "std" ) ]
5959use crate :: util:: mut_global:: MutGlobal ;
60- use crate :: util:: persist:: { KVStoreSync , MonitorName } ;
60+ use crate :: util:: persist:: { KVStore , KVStoreSync , MonitorName } ;
6161use crate :: util:: ser:: { Readable , ReadableArgs , Writeable , Writer } ;
6262use crate :: util:: test_channel_signer:: { EnforcementState , TestChannelSigner } ;
6363
@@ -84,7 +84,10 @@ use crate::io;
8484use crate :: prelude:: * ;
8585use crate :: sign:: { EntropySource , NodeSigner , RandomBytes , Recipient , SignerProvider } ;
8686use crate :: sync:: { Arc , Mutex } ;
87+ use alloc:: boxed:: Box ;
88+ use core:: future:: Future ;
8789use core:: mem;
90+ use core:: pin:: Pin ;
8891use core:: sync:: atomic:: { AtomicBool , AtomicUsize , Ordering } ;
8992use core:: time:: Duration ;
9093
@@ -863,10 +866,8 @@ impl TestStore {
863866 let persisted_bytes = Mutex :: new ( new_hash_map ( ) ) ;
864867 Self { persisted_bytes, read_only }
865868 }
866- }
867869
868- impl KVStoreSync for TestStore {
869- fn read (
870+ fn read_internal (
870871 & self , primary_namespace : & str , secondary_namespace : & str , key : & str ,
871872 ) -> io:: Result < Vec < u8 > > {
872873 let persisted_lock = self . persisted_bytes . lock ( ) . unwrap ( ) ;
@@ -888,7 +889,7 @@ impl KVStoreSync for TestStore {
888889 }
889890 }
890891
891- fn write (
892+ fn write_internal (
892893 & self , primary_namespace : & str , secondary_namespace : & str , key : & str , buf : Vec < u8 > ,
893894 ) -> io:: Result < ( ) > {
894895 if self . read_only {
@@ -911,7 +912,7 @@ impl KVStoreSync for TestStore {
911912 Ok ( ( ) )
912913 }
913914
914- fn remove (
915+ fn remove_internal (
915916 & self , primary_namespace : & str , secondary_namespace : & str , key : & str , _lazy : bool ,
916917 ) -> io:: Result < ( ) > {
917918 if self . read_only {
@@ -935,7 +936,9 @@ impl KVStoreSync for TestStore {
935936 Ok ( ( ) )
936937 }
937938
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 > > {
939942 let mut persisted_lock = self . persisted_bytes . lock ( ) . unwrap ( ) ;
940943
941944 let prefixed = if secondary_namespace. is_empty ( ) {
@@ -950,6 +953,57 @@ impl KVStoreSync for TestStore {
950953 }
951954}
952955
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+
9531007unsafe impl Sync for TestStore { }
9541008unsafe impl Send for TestStore { }
9551009
0 commit comments