@@ -13,10 +13,12 @@ use rgb_lib::ContractId;
1313
1414pub ( crate ) const RGB_PRIMARY_NS : & str = "rgb" ;
1515pub ( crate ) const RGB_CHANNEL_INFO_NS : & str = "channel_info" ;
16+ pub ( crate ) const RGB_CHANNEL_INFO_PENDING_NS : & str = "channel_info_pending" ;
1617pub ( crate ) const RGB_PAYMENT_INFO_INBOUND_NS : & str = "payment_info_inbound" ;
1718pub ( crate ) const RGB_PAYMENT_INFO_OUTBOUND_NS : & str = "payment_info_outbound" ;
1819pub ( crate ) const RGB_TRANSFER_INFO_NS : & str = "transfer_info" ;
1920pub ( crate ) const RGB_CONSIGNMENT_NS : & str = "consignment" ;
21+ pub ( crate ) const RGB_WALLET_CONFIG_NS : & str = "wallet_config" ;
2022
2123pub ( crate ) trait RgbKvStoreExt {
2224 fn write_config ( & self , key : & str , value : & str ) ;
@@ -39,18 +41,14 @@ pub(crate) trait RgbKvStoreExt {
3941 fn remove_rgb_consignment ( & self , txid : & str ) -> Result < ( ) , io:: Error > ;
4042}
4143
42- fn pending_suffix ( pending : bool ) -> & ' static str {
44+ fn channel_namespace ( pending : bool ) -> & ' static str {
4345 if pending {
44- "pending"
46+ RGB_CHANNEL_INFO_PENDING_NS
4547 } else {
46- "final"
48+ RGB_CHANNEL_INFO_NS
4749 }
4850}
4951
50- fn channel_key ( channel_id : & str , pending : bool ) -> String {
51- format ! ( "{channel_id}:{}" , pending_suffix( pending) )
52- }
53-
5452fn payment_key ( payment_hash : & PaymentHash , pending : bool ) -> String {
5553 let hash = payment_hash. 0 . as_hex ( ) . to_string ( ) ;
5654 if pending {
@@ -62,29 +60,29 @@ fn payment_key(payment_hash: &PaymentHash, pending: bool) -> String {
6260
6361impl < T : KVStoreSync + ?Sized > RgbKvStoreExt for T {
6462 fn write_config ( & self , key : & str , value : & str ) {
65- let _ = self . write ( "" , "" , key, value. as_bytes ( ) . to_vec ( ) ) ;
63+ let _ = self . write (
64+ RGB_PRIMARY_NS ,
65+ RGB_WALLET_CONFIG_NS ,
66+ key,
67+ value. as_bytes ( ) . to_vec ( ) ,
68+ ) ;
6669 }
6770
6871 fn read_rgb_channel_info ( & self , channel_id : & str , pending : bool ) -> Result < RgbInfo , io:: Error > {
69- let key = channel_key ( channel_id, pending) ;
70- let bytes = self . read ( RGB_PRIMARY_NS , RGB_CHANNEL_INFO_NS , & key) ?;
71- serde_json:: from_slice ( & bytes) . map_err ( |e| {
72- io:: Error :: new (
73- io:: ErrorKind :: InvalidData ,
74- format ! ( "invalid RGB channel info: {e}" ) ,
75- )
76- } )
72+ let namespace = channel_namespace ( pending) ;
73+ let bytes = self . read ( RGB_PRIMARY_NS , namespace, channel_id) ?;
74+ bincode:: deserialize ( & bytes) . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: InvalidData , e) )
7775 }
7876
7977 fn write_rgb_channel_info ( & self , channel_id : & str , rgb_info : & RgbInfo , pending : bool ) {
80- let key = channel_key ( channel_id , pending) ;
81- let bytes = serde_json :: to_vec ( rgb_info) . expect ( "valid RGB channel info" ) ;
82- let _ = self . write ( RGB_PRIMARY_NS , RGB_CHANNEL_INFO_NS , & key , bytes) ;
78+ let namespace = channel_namespace ( pending) ;
79+ let bytes = bincode :: serialize ( rgb_info) . expect ( "valid RGB channel info" ) ;
80+ let _ = self . write ( RGB_PRIMARY_NS , namespace , channel_id , bytes) ;
8381 }
8482
8583 fn remove_rgb_channel_info ( & self , channel_id : & str , pending : bool ) -> Result < ( ) , io:: Error > {
86- let key = channel_key ( channel_id , pending) ;
87- self . remove ( RGB_PRIMARY_NS , RGB_CHANNEL_INFO_NS , & key , false )
84+ let namespace = channel_namespace ( pending) ;
85+ self . remove ( RGB_PRIMARY_NS , namespace , channel_id , false )
8886 }
8987
9088 fn read_rgb_payment_info (
@@ -99,12 +97,7 @@ impl<T: KVStoreSync + ?Sized> RgbKvStoreExt for T {
9997 } ;
10098 let key = payment_key ( payment_hash, false ) ;
10199 let bytes = self . read ( RGB_PRIMARY_NS , ns, & key) ?;
102- serde_json:: from_slice ( & bytes) . map_err ( |e| {
103- io:: Error :: new (
104- io:: ErrorKind :: InvalidData ,
105- format ! ( "invalid RGB payment info: {e}" ) ,
106- )
107- } )
100+ bincode:: deserialize ( & bytes) . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: InvalidData , e) )
108101 }
109102
110103 fn write_rgb_payment_info (
@@ -119,23 +112,14 @@ impl<T: KVStoreSync + ?Sized> RgbKvStoreExt for T {
119112 RGB_PAYMENT_INFO_OUTBOUND_NS
120113 } ;
121114 let key = payment_key ( payment_hash, pending) ;
122- let bytes = serde_json:: to_vec ( payment_info) . map_err ( |e| {
123- io:: Error :: new (
124- io:: ErrorKind :: InvalidData ,
125- format ! ( "invalid RGB payment info: {e}" ) ,
126- )
127- } ) ?;
115+ let bytes = bincode:: serialize ( payment_info)
116+ . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: InvalidData , e) ) ?;
128117 self . write ( RGB_PRIMARY_NS , ns, & key, bytes)
129118 }
130119
131120 fn read_rgb_transfer_info ( & self , txid : & str ) -> Result < TransferInfo , io:: Error > {
132121 let bytes = self . read ( RGB_PRIMARY_NS , RGB_TRANSFER_INFO_NS , txid) ?;
133- serde_json:: from_slice ( & bytes) . map_err ( |e| {
134- io:: Error :: new (
135- io:: ErrorKind :: InvalidData ,
136- format ! ( "invalid RGB transfer info: {e}" ) ,
137- )
138- } )
122+ bincode:: deserialize ( & bytes) . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: InvalidData , e) )
139123 }
140124
141125 fn read_rgb_consignment ( & self , txid : & str ) -> Result < Vec < u8 > , io:: Error > {
0 commit comments