@@ -47,60 +47,60 @@ impl StorageManager {
4747 }
4848
4949 /// Store a block header
50- pub fn store_header ( & self , height : u64 , hash : & [ u8 ] , header : & [ u8 ] ) -> Result < ( ) , rocksdb :: Error > {
50+ pub fn store_header ( & self , height : u64 , hash : & [ u8 ] , header : & [ u8 ] ) -> Result < ( ) , String > {
5151 let cf = self . db . cf_handle ( CF_HEADERS )
52- . ok_or_else ( || rocksdb :: Error :: new ( "Column family not found". to_string ( ) ) ) ?;
53-
52+ . ok_or_else ( || "Headers column family not found". to_string ( ) ) ?;
53+
5454 let mut batch = WriteBatch :: default ( ) ;
5555 // Store by height
5656 batch. put_cf ( cf, height. to_be_bytes ( ) , header) ;
5757 // Store by hash
5858 batch. put_cf ( cf, hash, header) ;
5959 // Update chain index
6060 let index_cf = self . db . cf_handle ( CF_CHAIN_INDEX )
61- . ok_or_else ( || rocksdb :: Error :: new ( "Column family not found". to_string ( ) ) ) ?;
61+ . ok_or_else ( || "Chain index column family not found". to_string ( ) ) ?;
6262 batch. put_cf ( index_cf, b"latest_height" , height. to_be_bytes ( ) ) ;
6363 batch. put_cf ( index_cf, b"latest_hash" , hash) ;
64-
65- self . db . write ( batch)
64+
65+ self . db . write ( batch) . map_err ( |e| e . to_string ( ) )
6666 }
6767
6868 /// Store a full block
69- pub fn store_block ( & self , hash : & [ u8 ] , block : & [ u8 ] ) -> Result < ( ) , rocksdb :: Error > {
69+ pub fn store_block ( & self , hash : & [ u8 ] , block : & [ u8 ] ) -> Result < ( ) , String > {
7070 let cf = self . db . cf_handle ( CF_BLOCKS )
71- . ok_or_else ( || rocksdb :: Error :: new ( "Column family not found". to_string ( ) ) ) ?;
72- self . db . put_cf ( cf, hash, block)
71+ . ok_or_else ( || "Blocks column family not found". to_string ( ) ) ?;
72+ self . db . put_cf ( cf, hash, block) . map_err ( |e| e . to_string ( ) )
7373 }
7474
7575 /// Get block by hash
76- pub fn get_block ( & self , hash : & [ u8 ] ) -> Result < Option < Vec < u8 > > , rocksdb :: Error > {
76+ pub fn get_block ( & self , hash : & [ u8 ] ) -> Result < Option < Vec < u8 > > , String > {
7777 let cf = self . db . cf_handle ( CF_BLOCKS )
78- . ok_or_else ( || rocksdb :: Error :: new ( "Column family not found". to_string ( ) ) ) ?;
79- self . db . get_cf ( cf, hash)
78+ . ok_or_else ( || "Blocks column family not found". to_string ( ) ) ?;
79+ self . db . get_cf ( cf, hash) . map_err ( |e| e . to_string ( ) )
8080 }
8181
8282 /// Get header by height
83- pub fn get_header_by_height ( & self , height : u64 ) -> Result < Option < Vec < u8 > > , rocksdb :: Error > {
83+ pub fn get_header_by_height ( & self , height : u64 ) -> Result < Option < Vec < u8 > > , String > {
8484 let cf = self . db . cf_handle ( CF_HEADERS )
85- . ok_or_else ( || rocksdb :: Error :: new ( "Column family not found". to_string ( ) ) ) ?;
86- self . db . get_cf ( cf, height. to_be_bytes ( ) )
85+ . ok_or_else ( || "Headers column family not found". to_string ( ) ) ?;
86+ self . db . get_cf ( cf, height. to_be_bytes ( ) ) . map_err ( |e| e . to_string ( ) )
8787 }
8888
8989 /// Get header by hash
90- pub fn get_header_by_hash ( & self , hash : & [ u8 ] ) -> Result < Option < Vec < u8 > > , rocksdb :: Error > {
90+ pub fn get_header_by_hash ( & self , hash : & [ u8 ] ) -> Result < Option < Vec < u8 > > , String > {
9191 let cf = self . db . cf_handle ( CF_HEADERS )
92- . ok_or_else ( || rocksdb :: Error :: new ( "Column family not found". to_string ( ) ) ) ?;
93- self . db . get_cf ( cf, hash)
92+ . ok_or_else ( || "Headers column family not found". to_string ( ) ) ?;
93+ self . db . get_cf ( cf, hash) . map_err ( |e| e . to_string ( ) )
9494 }
9595
9696 /// Get latest chain height
97- pub fn get_latest_height ( & self ) -> Result < Option < u64 > , rocksdb :: Error > {
97+ pub fn get_latest_height ( & self ) -> Result < Option < u64 > , String > {
9898 let cf = self . db . cf_handle ( CF_CHAIN_INDEX )
99- . ok_or_else ( || rocksdb :: Error :: new ( "Column family not found". to_string ( ) ) ) ?;
100- if let Some ( bytes) = self . db . get_cf ( cf, b"latest_height" ) ? {
99+ . ok_or_else ( || "Chain index column family not found". to_string ( ) ) ?;
100+ if let Some ( bytes) = self . db . get_cf ( cf, b"latest_height" ) . map_err ( |e| e . to_string ( ) ) ? {
101101 let height = u64:: from_be_bytes (
102102 bytes. as_slice ( ) . try_into ( )
103- . map_err ( |_| rocksdb :: Error :: new ( "Invalid height data" . to_string ( ) ) ) ?
103+ . map_err ( |_| "Invalid height data" . to_string ( ) ) ?
104104 ) ;
105105 Ok ( Some ( height) )
106106 } else {
@@ -109,70 +109,72 @@ impl StorageManager {
109109 }
110110
111111 /// Store account state
112- pub fn store_account ( & self , address : & [ u8 ] , account : & Account ) -> Result < ( ) , rocksdb :: Error > {
112+ pub fn store_account ( & self , address : & [ u8 ] , account : & Account ) -> Result < ( ) , String > {
113113 let cf = self . db . cf_handle ( CF_ACCOUNTS )
114- . ok_or_else ( || rocksdb :: Error :: new ( "Column family not found". to_string ( ) ) ) ?;
114+ . ok_or_else ( || "Accounts column family not found". to_string ( ) ) ?;
115115 let data = bincode:: serialize ( account)
116- . map_err ( |e| rocksdb :: Error :: new ( format ! ( "Serialization error: {}" , e) ) ) ?;
117- self . db . put_cf ( cf, address, data)
116+ . map_err ( |e| format ! ( "Serialization error: {}" , e) ) ?;
117+ self . db . put_cf ( cf, address, data) . map_err ( |e| e . to_string ( ) )
118118 }
119119
120120 /// Get account state
121- pub fn get_account ( & self , address : & [ u8 ] ) -> Result < Option < Account > , rocksdb :: Error > {
121+ pub fn get_account ( & self , address : & [ u8 ] ) -> Result < Option < Account > , String > {
122122 let cf = self . db . cf_handle ( CF_ACCOUNTS )
123- . ok_or_else ( || rocksdb :: Error :: new ( "Column family not found". to_string ( ) ) ) ?;
124- if let Some ( data) = self . db . get_cf ( cf, address) ? {
123+ . ok_or_else ( || "Accounts column family not found". to_string ( ) ) ?;
124+ if let Some ( data) = self . db . get_cf ( cf, address) . map_err ( |e| e . to_string ( ) ) ? {
125125 Ok ( bincode:: deserialize ( & data) . ok ( ) )
126126 } else {
127127 Ok ( None )
128128 }
129129 }
130130
131131 /// Store bond state
132- pub fn store_bond ( & self , miner_id : & [ u8 ] , bond : & BondState ) -> Result < ( ) , rocksdb :: Error > {
132+ pub fn store_bond ( & self , miner_id : & [ u8 ] , bond : & BondState ) -> Result < ( ) , String > {
133133 let cf = self . db . cf_handle ( CF_BONDS )
134- . ok_or_else ( || rocksdb :: Error :: new ( "Column family not found". to_string ( ) ) ) ?;
134+ . ok_or_else ( || "Bonds column family not found". to_string ( ) ) ?;
135135 let data = bincode:: serialize ( bond)
136- . map_err ( |e| rocksdb :: Error :: new ( format ! ( "Serialization error: {}" , e) ) ) ?;
137- self . db . put_cf ( cf, miner_id, data)
136+ . map_err ( |e| format ! ( "Serialization error: {}" , e) ) ?;
137+ self . db . put_cf ( cf, miner_id, data) . map_err ( |e| e . to_string ( ) )
138138 }
139139
140140 /// Get bond state
141- pub fn get_bond ( & self , miner_id : & [ u8 ] ) -> Result < Option < BondState > , rocksdb :: Error > {
141+ pub fn get_bond ( & self , miner_id : & [ u8 ] ) -> Result < Option < BondState > , String > {
142142 let cf = self . db . cf_handle ( CF_BONDS )
143- . ok_or_else ( || rocksdb :: Error :: new ( "Column family not found". to_string ( ) ) ) ?;
144- if let Some ( data) = self . db . get_cf ( cf, miner_id) ? {
143+ . ok_or_else ( || "Bonds column family not found". to_string ( ) ) ?;
144+ if let Some ( data) = self . db . get_cf ( cf, miner_id) . map_err ( |e| e . to_string ( ) ) ? {
145145 Ok ( bincode:: deserialize ( & data) . ok ( ) )
146146 } else {
147147 Ok ( None )
148148 }
149149 }
150150
151151 /// Store state root for a given height
152- pub fn store_state_root ( & self , height : u64 , root : & [ u8 ] ) -> Result < ( ) , rocksdb :: Error > {
152+ pub fn store_state_root ( & self , height : u64 , root : & [ u8 ] ) -> Result < ( ) , String > {
153153 let cf = self . db . cf_handle ( CF_STATE_ROOTS )
154- . ok_or_else ( || rocksdb :: Error :: new ( "Column family not found". to_string ( ) ) ) ?;
155- self . db . put_cf ( cf, height. to_be_bytes ( ) , root)
154+ . ok_or_else ( || "State roots column family not found". to_string ( ) ) ?;
155+ self . db . put_cf ( cf, height. to_be_bytes ( ) , root) . map_err ( |e| e . to_string ( ) )
156156 }
157157
158158 /// Get state root for a given height
159- pub fn get_state_root ( & self , height : u64 ) -> Result < Option < Vec < u8 > > , rocksdb :: Error > {
159+ pub fn get_state_root ( & self , height : u64 ) -> Result < Option < Vec < u8 > > , String > {
160160 let cf = self . db . cf_handle ( CF_STATE_ROOTS )
161- . ok_or_else ( || rocksdb :: Error :: new ( "Column family not found". to_string ( ) ) ) ?;
162- self . db . get_cf ( cf, height. to_be_bytes ( ) )
161+ . ok_or_else ( || "State roots column family not found". to_string ( ) ) ?;
162+ self . db . get_cf ( cf, height. to_be_bytes ( ) ) . map_err ( |e| e . to_string ( ) )
163163 }
164164
165165 /// Prune old blocks (keep last N blocks)
166- pub fn prune_old_blocks ( & self , keep_last : u64 ) -> Result < ( ) , rocksdb :: Error > {
166+ pub fn prune_old_blocks ( & self , keep_last : u64 ) -> Result < ( ) , String > {
167167 let latest = self . get_latest_height ( ) ?. unwrap_or ( 0 ) ;
168168 if latest <= keep_last {
169169 return Ok ( ( ) ) ;
170170 }
171-
171+
172172 let prune_until = latest - keep_last;
173- let cf = self . db . cf_handle ( CF_BLOCKS )
174- . ok_or_else ( || rocksdb:: Error :: new ( "Column family not found" . to_string ( ) ) ) ?;
175-
173+
174+ // Verify blocks column family exists
175+ self . db . cf_handle ( CF_BLOCKS )
176+ . ok_or_else ( || "Blocks column family not found" . to_string ( ) ) ?;
177+
176178 // This is a simplified version - in production would iterate and delete
177179 for height in 0 ..prune_until {
178180 if let Some ( header_data) = self . get_header_by_height ( height) ? {
@@ -181,7 +183,7 @@ impl StorageManager {
181183 let _ = header_data;
182184 }
183185 }
184-
186+
185187 Ok ( ( ) )
186188 }
187189
0 commit comments