@@ -405,18 +405,18 @@ pub async fn close_channel(
405
405
}
406
406
407
407
#[ derive( Debug , Deserialize ) ]
408
- pub struct DeleteDlcChannel {
408
+ pub struct Confirmation {
409
409
#[ serde( default , deserialize_with = "empty_string_as_none" ) ]
410
410
i_know_what_i_am_doing : Option < bool > ,
411
411
}
412
412
413
413
/// This function deletes a DLC channel from our database irreversible!
414
414
/// If you want to close a channel instead, use `close_channel`
415
415
#[ instrument( skip_all, err( Debug ) ) ]
416
- pub async fn delete_dlc_channels (
416
+ pub async fn delete_dlc_channel (
417
417
Path ( channel_id_string) : Path < String > ,
418
418
State ( state) : State < Arc < AppState > > ,
419
- Query ( params) : Query < DeleteDlcChannel > ,
419
+ Query ( params) : Query < Confirmation > ,
420
420
) -> Result < ( ) , AppError > {
421
421
if !params. i_know_what_i_am_doing . unwrap_or_default ( ) {
422
422
let error_message =
@@ -447,6 +447,50 @@ pub async fn delete_dlc_channels(
447
447
Ok ( ( ) )
448
448
}
449
449
450
+ /// This function attempts to roll back a DLC channel to the last stable state!
451
+ /// The action is irreversible, only use if you know what you are doing!
452
+ #[ instrument( skip_all, err( Debug ) ) ]
453
+ pub async fn roll_back_dlc_channel (
454
+ Path ( channel_id_string) : Path < String > ,
455
+ State ( state) : State < Arc < AppState > > ,
456
+ Query ( params) : Query < Confirmation > ,
457
+ ) -> Result < ( ) , AppError > {
458
+ if !params. i_know_what_i_am_doing . unwrap_or_default ( ) {
459
+ let error_message =
460
+ "Looks like you don't know what you are doing! Go and ask your supervisor for help!" ;
461
+ tracing:: warn!( error_message) ;
462
+ return Err ( AppError :: BadRequest ( error_message. to_string ( ) ) ) ;
463
+ }
464
+
465
+ let channel_id = parse_dlc_channel_id ( & channel_id_string)
466
+ . map_err ( |_| AppError :: BadRequest ( "Provided channel ID was invalid" . to_string ( ) ) ) ?;
467
+
468
+ tracing:: info!( channel_id = %channel_id_string, "Attempting to roll back dlc channel to last stable state" ) ;
469
+
470
+ let channel = state
471
+ . node
472
+ . inner
473
+ . get_dlc_channel_by_id ( & channel_id)
474
+ . map_err ( |e| AppError :: BadRequest ( format ! ( "Couldn't find channel. {e:#}" ) ) ) ?;
475
+ if let Channel :: Signed ( signed_channel) = channel {
476
+ state
477
+ . node
478
+ . inner
479
+ . roll_back_channel ( & signed_channel)
480
+ . map_err ( |e| {
481
+ AppError :: InternalServerError ( format ! ( "Failed to roll back channel. {e:#}" ) )
482
+ } ) ?
483
+ } else {
484
+ return Err ( AppError :: BadRequest (
485
+ "It's only possible to rollback a channel in state signed" . to_string ( ) ,
486
+ ) ) ;
487
+ }
488
+
489
+ tracing:: info!( channel_id = %channel_id_string, "Rolled back dlc channel" ) ;
490
+
491
+ Ok ( ( ) )
492
+ }
493
+
450
494
#[ instrument( skip_all, err( Debug ) ) ]
451
495
pub async fn sign_message (
452
496
Path ( msg) : Path < String > ,
0 commit comments