diff --git a/coordinator/src/admin.rs b/coordinator/src/admin.rs index 82f52f12f..80d3f7136 100644 --- a/coordinator/src/admin.rs +++ b/coordinator/src/admin.rs @@ -18,6 +18,7 @@ use commons::CollaborativeRevertCoordinatorRequest; use commons::LegacyCollaborativeRevertCoordinatorRequest; use dlc_manager::channel::Channel; use dlc_manager::contract::Contract; +use dlc_manager::Storage; use lightning::chain::chaininterface::ConfirmationTarget; use lightning_invoice::Bolt11Invoice; use ln_dlc_node::node::NodeInfo; @@ -557,6 +558,49 @@ pub async fn close_channel( Ok(()) } +#[derive(Debug, Deserialize)] +pub struct DeleteDlcChannel { + #[serde(default, deserialize_with = "empty_string_as_none")] + i_know_what_i_am_doing: Option, +} + +/// This function deletes a DLC channel from our database irreversible! +/// If you want to close a channel instead, use `close_channel` +#[instrument(skip_all, err(Debug))] +pub async fn delete_dlc_channels( + Path(channel_id_string): Path, + State(state): State>, + Query(params): Query, +) -> Result<(), AppError> { + if !params.i_know_what_i_am_doing.unwrap_or_default() { + let error_message = + "Looks like you don't know what you are doing! Go and ask your supervisor for help!"; + tracing::warn!(error_message); + return Err(AppError::BadRequest(error_message.to_string())); + } + + let channel_id = parse_dlc_channel_id(&channel_id_string) + .map_err(|_| AppError::BadRequest("Provided channel ID was invalid".to_string()))?; + + tracing::info!(channel_id = %channel_id_string, "Deleting dlc channel"); + + state + .node + .inner + .dlc_storage + .delete_channel(&channel_id) + .map_err(|e| { + AppError::InternalServerError(format!( + "Could not delete dlc_channel with id {} due to {:?}", + channel_id_string, e + )) + })?; + + tracing::info!(channel_id = %channel_id_string, "Deleted dlc channel"); + + Ok(()) +} + #[instrument(skip_all, err(Debug))] pub async fn force_close_ln_dlc_channel( Path(channel_id_string): Path, diff --git a/coordinator/src/routes.rs b/coordinator/src/routes.rs index c4cb700ff..be4060de4 100644 --- a/coordinator/src/routes.rs +++ b/coordinator/src/routes.rs @@ -1,6 +1,7 @@ use crate::admin::close_channel; use crate::admin::collaborative_revert; use crate::admin::connect_to_peer; +use crate::admin::delete_dlc_channels; use crate::admin::force_close_ln_dlc_channel; use crate::admin::get_balance; use crate::admin::get_fee_rate_estimation; @@ -164,6 +165,10 @@ pub fn router( .route("/api/admin/peers", get(list_peers)) .route("/api/admin/send_payment/:invoice", post(send_payment)) .route("/api/admin/dlc_channels", get(list_dlc_channels)) + .route( + "/api/admin/dlc_channels/:channel_id", + delete(delete_dlc_channels), + ) .route("/api/admin/transactions", get(list_on_chain_transactions)) .route("/api/admin/sign/:msg", get(sign_message)) .route("/api/admin/connect", post(connect_to_peer))