33 config:: Command ,
44 signer:: { GuardianKey , Signer , GUARDIAN_KEY_ARMORED_BLOCK , STANDARD_ARMOR_LINE_HEADER } ,
55 } ,
6+ anyhow:: Context ,
67 api_client:: { ApiClient , Observation } ,
78 borsh:: BorshDeserialize ,
89 clap:: Parser ,
@@ -215,27 +216,27 @@ async fn get_signer(run_options: config::RunOptions) -> anyhow::Result<Arc<dyn S
215216 }
216217}
217218
218- async fn run ( run_options : config:: RunOptions ) {
219+ async fn run ( run_options : config:: RunOptions ) -> anyhow :: Result < ( ) > {
219220 let signer = get_signer ( run_options. clone ( ) )
220221 . await
221- . expect ( "Failed to create signer" ) ;
222+ . context ( "Failed to create signer" ) ? ;
222223 let client = PubsubClient :: new ( & run_options. pythnet_url )
223224 . await
224- . expect ( "Invalid WebSocket URL" ) ;
225+ . context ( "Invalid WebSocket URL" ) ? ;
225226 drop ( client) ; // Drop the client to avoid holding the connection open
226227 let accumulator_address = Pubkey :: from_str ( "G9LV2mp9ua1znRAfYwZz5cPiJMAbo1T6mbjdQsDZuMJg" )
227- . expect ( "Invalid accumulator address" ) ;
228+ . context ( "Invalid accumulator address" ) ? ;
228229 let wormhole_pid =
229- Pubkey :: from_str ( & run_options. wormhole_pid ) . expect ( "Invalid Wormhole program ID" ) ;
230+ Pubkey :: from_str ( & run_options. wormhole_pid ) . context ( "Invalid Wormhole program ID" ) ? ;
230231 let api_clients: Vec < ApiClient > = run_options
231232 . server_urls
232233 . into_iter ( )
233- . map ( |server_url| {
234- ApiClient :: try_new ( server_url, None ) . expect ( "Failed to create API client" )
235- } )
236- . collect ( ) ;
234+ . map ( |server_url| ApiClient :: try_new ( server_url, None ) )
235+ . collect :: < anyhow:: Result < Vec < _ > > > ( ) ?;
237236
238- let ( pubkey, pubkey_evm) = signer. get_public_key ( ) . expect ( "Failed to get public key" ) ;
237+ let ( pubkey, pubkey_evm) = signer
238+ . get_public_key ( )
239+ . context ( "Failed to get public key" ) ?;
239240 let evm_encded_public_key = format ! ( "0x{}" , hex:: encode( pubkey_evm) ) ;
240241 tracing:: info!(
241242 public_key = ?pubkey,
@@ -260,7 +261,7 @@ async fn run(run_options: config::RunOptions) {
260261}
261262
262263#[ tokio:: main]
263- async fn main ( ) {
264+ async fn main ( ) -> anyhow :: Result < ( ) > {
264265 // Initialize a Tracing Subscriber
265266 let fmt_builder = tracing_subscriber:: fmt ( )
266267 . with_file ( false )
@@ -272,24 +273,26 @@ async fn main() {
272273 // Use the compact formatter if we're in a terminal, otherwise use the JSON formatter.
273274 if std:: io:: stderr ( ) . is_terminal ( ) {
274275 tracing:: subscriber:: set_global_default ( fmt_builder. compact ( ) . finish ( ) )
275- . expect ( "Failed to set global default subscriber" ) ;
276+ . context ( "Failed to set global default subscriber" ) ? ;
276277 } else {
277278 tracing:: subscriber:: set_global_default ( fmt_builder. json ( ) . finish ( ) )
278- . expect ( "Failed to set global default subscriber" ) ;
279+ . context ( "Failed to set global default subscriber" ) ? ;
279280 }
280281
281282 // Parse the command line arguments with StructOpt, will exit automatically on `--help` or
282283 // with invalid arguments.
283284 match Command :: parse ( ) {
284- Command :: Run ( run_options) => run ( run_options) . await ,
285+ Command :: Run ( run_options) => run ( run_options) . await ? ,
285286 Command :: GenerateKey ( opts) => {
286287 let secp = Secp256k1 :: new ( ) ;
287288 let mut rng = OsRng ;
288289
289290 // Generate keypair (secret + public key)
290291 let ( secret_key, _) = secp. generate_keypair ( & mut rng) ;
291292 let signer = signer:: FileSigner { secret_key } ;
292- let ( pubkey, pubkey_evm) = signer. get_public_key ( ) . expect ( "Failed to get public key" ) ;
293+ let ( pubkey, pubkey_evm) = signer
294+ . get_public_key ( )
295+ . context ( "Failed to get public key" ) ?;
293296
294297 let guardian_key = GuardianKey {
295298 data : secret_key. secret_bytes ( ) . to_vec ( ) ,
@@ -300,24 +303,25 @@ async fn main() {
300303 Kind :: SecretKey ,
301304 vec ! [ ( "PublicKey" , format!( "0x{}" , hex:: encode( pubkey_evm) ) ) ] ,
302305 )
303- . expect ( "Failed to create writer" ) ;
306+ . context ( "Failed to create writer" ) ? ;
304307 writer
305308 . write_all ( guardian_key. encode_to_vec ( ) . as_slice ( ) )
306- . expect ( "Failed to write GuardianKey to writer" ) ;
307- let buffer = writer. finalize ( ) . expect ( "Failed to finalize writer" ) ;
309+ . context ( "Failed to write GuardianKey to writer" ) ? ;
310+ let buffer = writer. finalize ( ) . context ( "Failed to finalize writer" ) ? ;
308311 let armored_string =
309- String :: from_utf8 ( buffer) . expect ( "Failed to convert buffer to string" ) ;
312+ String :: from_utf8 ( buffer) . context ( "Failed to convert buffer to string" ) ? ;
310313 let armored_string =
311314 armored_string. replace ( STANDARD_ARMOR_LINE_HEADER , GUARDIAN_KEY_ARMORED_BLOCK ) ;
312315
313- fs:: write ( & opts. output_path , armored_string)
314- . expect ( "Failed to write GuardianKey to file" ) ;
316+ fs:: write ( & opts. output_path , armored_string) . context ( "Failed to write key to file" ) ?;
315317
316318 tracing:: info!( "Generated secret key at: {}" , opts. output_path) ;
317319 tracing:: info!( "Public key: {}" , pubkey) ;
318320 tracing:: info!( "EVM encoded public key: 0x{}" , hex:: encode( pubkey_evm) ) ;
319321 }
320322 }
323+
324+ Ok ( ( ) )
321325}
322326
323327#[ cfg( test) ]
0 commit comments