@@ -78,6 +78,9 @@ enum Commands {
7878 Start {
7979 #[ arg( value_enum, default_value_t = StartTarget :: All ) ]
8080 target : StartTarget ,
81+ /// Cleans up the local environment before starting the services
82+ #[ arg( long, default_value_t = false ) ]
83+ clean : bool ,
8184 } ,
8285 /// Stops a specific bridge component. The component can be either the network, bridge, demo or all. Default is all
8386 Stop {
@@ -276,10 +279,12 @@ async fn main() {
276279 ) ;
277280 }
278281 }
279- Commands :: Start { target } => {
282+ Commands :: Start { target, clean } => {
280283 let project_config = config:: get_config ( ) ;
281284 let project_root_path = Path :: new ( & project_config. project_root ) ;
282285
286+ let mut cardano_current_epoch = 0 ;
287+
283288 if target == StartTarget :: Network || target == StartTarget :: All {
284289 // Start the local Cardano network and its services
285290 match start_local_cardano_network ( & project_root_path) . await {
@@ -289,26 +294,26 @@ async fn main() {
289294 error
290295 ) ) ,
291296 }
292-
293- let mut cardano_current_epoch = 0 ;
294297 // Start Mithril if needed
295- match start_mithril ( & project_root_path) . await {
296- Ok ( current_epoch) => {
297- cardano_current_epoch = current_epoch;
298- logger:: log ( "✅ Mithril up and running" )
299- }
300- Err ( error) => {
301- network_down_with_error ( & format ! ( "❌ Failed to start Mithril: {}" , error) )
298+ if target == StartTarget :: All {
299+ match start_mithril ( & project_root_path) . await {
300+ Ok ( current_epoch) => {
301+ cardano_current_epoch = current_epoch;
302+ logger:: log ( "✅ Mithril up and running" )
303+ }
304+ Err ( error) => network_down_with_error ( & format ! (
305+ "❌ Failed to start Mithril: {}" ,
306+ error
307+ ) ) ,
302308 }
309+ } else {
310+ // Wait for Mithril to start reading the immutable cardano node files
311+ match wait_and_start_mithril_genesis ( & project_root_path, cardano_current_epoch) {
312+ Ok ( _) => logger:: log ( "✅ Immutable Cardano node files have been created, and Mithril is working as expected" ) ,
313+ Err ( error) => {
314+ network_down_with_error ( & format ! ( "❌ Mithril failed to read the immutable cardano node files: {}" , error) )
315+ } }
303316 }
304-
305- // Wait for Mithril to start reading the immutable cardano node files
306- match wait_and_start_mithril_genesis ( & project_root_path, cardano_current_epoch) {
307- Ok ( _) => logger:: log ( "✅ Immutable Cardano node files have been created, and Mithril is working as expected" ) ,
308- Err ( error) => {
309- network_down_with_error ( & format ! ( "❌ Mithril failed to read the immutable cardano node files: {}" , error) )
310- } }
311-
312317 logger:: log ( "\n ✅ Cardano Network started successfully" ) ;
313318 }
314319
@@ -323,7 +328,7 @@ async fn main() {
323328 ) ) ;
324329
325330 // Deploy Contracts
326- match deploy_contracts ( & project_root_path) . await {
331+ match deploy_contracts ( & project_root_path, clean ) . await {
327332 Ok ( _) => logger:: log ( "✅ Cardano Scripts correcty deployed" ) ,
328333 Err ( error) => bridge_down_with_error ( & format ! (
329334 "❌ Failed to deploy Cardano Scripts: {}" ,
@@ -341,7 +346,7 @@ async fn main() {
341346 ) ) ;
342347
343348 // Start gateway
344- match start_gateway ( project_root_path. join ( "cardano/gateway" ) . as_path ( ) ) {
349+ match start_gateway ( project_root_path. join ( "cardano/gateway" ) . as_path ( ) , clean ) {
345350 Ok ( _) => logger:: log ( "✅ Gateway started successfully" ) ,
346351 Err ( error) => {
347352 bridge_down_with_error ( & format ! ( "❌ Failed to start gateway: {}" , error) )
@@ -353,6 +358,14 @@ async fn main() {
353358 "addr_test1vz8nzrmel9mmmu97lm06uvm55cj7vny6dxjqc0y0efs8mtqsd8r5m" ,
354359 ) ;
355360 logger:: log ( & format ! ( "Final balance {}" , & balance. to_string( ) . as_str( ) ) ) ;
361+ if target == StartTarget :: All {
362+ match wait_and_start_mithril_genesis ( & project_root_path, cardano_current_epoch) {
363+ Ok ( _) => logger:: log ( "✅ Immutable Cardano node files have been created, and Mithril is working as expected" ) ,
364+ Err ( error) => {
365+ network_down_with_error ( & format ! ( "❌ Mithril failed to read the immutable cardano node files: {}" , error) )
366+ }
367+ }
368+ }
356369 }
357370 }
358371 }
0 commit comments