diff --git a/bindings/ldk_node.udl b/bindings/ldk_node.udl index ca8c12f3..4b69fd03 100644 --- a/bindings/ldk_node.udl +++ b/bindings/ldk_node.udl @@ -92,6 +92,8 @@ interface Node { boolean verify_signature([ByRef]sequence msg, [ByRef]string sig, [ByRef]PublicKey pkey); [Throws=NodeError] sequence get_encoded_channel_monitors(); + [Throws=NodeError] + void restore_encoded_channel_monitors(sequence monitors); void force_close_all_channels_without_broadcasting_txn(); }; diff --git a/src/lib.rs b/src/lib.rs index 219d21de..d12c4f50 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1556,7 +1556,6 @@ impl Node { let mut entries = Vec::new(); for key in keys { - // TODO: error handling let value = channel_monitor_store.read("monitors", "", &key).map_err(|e| { log_error!(channel_monitor_logger, "Failed to get monitor value: {}", e); Error::ConnectionFailed @@ -1567,6 +1566,23 @@ impl Node { return Ok(entries); } + /// Alby: Restore encoded channel monitors for a recovery of last resort + pub fn restore_encoded_channel_monitors(&self, monitors: Vec) -> Result<(), Error> { + let channel_monitor_store = Arc::clone(&self.kv_store); + let channel_monitor_logger = Arc::clone(&self.logger); + + for monitor in monitors { + channel_monitor_store.write("monitors", "", &monitor.key, &monitor.value).map_err( + |e| { + log_error!(channel_monitor_logger, "Failed to restore monitor: {}", e); + Error::ConnectionFailed + }, + )?; + } + + return Ok(()); + } + /// Retrieves an overview of all known balances. pub fn list_balances(&self) -> BalanceDetails { let cur_anchor_reserve_sats =