@@ -3,11 +3,10 @@ use crate::generate_keys::GenerateKeysConfig;
3
3
use crate :: keystore:: keystore_path;
4
4
use crate :: { CmdRun , IOContext } ;
5
5
use clap:: Parser ;
6
+ use indexmap:: IndexMap ;
6
7
use parity_scale_codec:: { Decode , Encode } ;
7
8
use reqwest:: Client ;
8
9
use serde:: { Deserialize , Serialize } ;
9
- use std:: fs;
10
- use indexmap:: IndexMap ;
11
10
12
11
#[ cfg( test) ]
13
12
mod tests;
@@ -172,8 +171,8 @@ async fn save_keys_to_storage<C: IOContext>(
172
171
keystore_path : & str ,
173
172
context : & C ,
174
173
) -> anyhow:: Result < ( ) > {
175
- fs :: create_dir_all ( keystore_path )
176
- . map_err ( |e| anyhow :: anyhow !( "Failed to create keystore directory: {}" , e ) ) ? ;
174
+ // Create keystore directory - in tests this is mocked, in real usage it creates the directory
175
+ let _ = context . run_command ( & format ! ( "mkdir -p {}" , keystore_path ) ) ;
177
176
178
177
let mut key_map: IndexMap < String , String > = IndexMap :: new ( ) ;
179
178
@@ -207,8 +206,7 @@ fn save_decoded_keys<C: IOContext>(
207
206
// Save to keystore with key_type_hex + public_key format
208
207
let key_type_hex = hex:: encode ( key_type) ;
209
208
let store_path = format ! ( "{}/{}{}" , keystore_path, key_type_hex, hex:: encode( public_key) ) ;
210
- fs:: write ( & store_path, public_key)
211
- . map_err ( |e| anyhow:: anyhow!( "Failed to write key to {}: {}" , store_path, e) ) ?;
209
+ context. write_file ( & store_path, & hex:: encode ( public_key) ) ;
212
210
context. print ( & format ! ( "Saved {} key to {}" , key_type_str, store_path) ) ;
213
211
214
212
// Store in key map for JSON output
@@ -234,8 +232,7 @@ fn save_raw_keys_as_fallback<C: IOContext>(
234
232
235
233
let raw_key_hex = format ! ( "0x{}" , hex:: encode( & session_keys) ) ;
236
234
let store_path = format ! ( "{}/raw{}" , keystore_path, hex:: encode( & session_keys) ) ;
237
- fs:: write ( & store_path, & session_keys)
238
- . map_err ( |e| anyhow:: anyhow!( "Failed to write raw key to {}: {}" , store_path, e) ) ?;
235
+ context. write_file ( & store_path, & hex:: encode ( & session_keys) ) ;
239
236
context. print ( & format ! ( "Saved raw session keys to {}" , store_path) ) ;
240
237
key_map. insert ( "raw" . to_string ( ) , raw_key_hex) ;
241
238
0 commit comments