Skip to content

Commit

Permalink
feat: get encoded channel monitors
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Sep 23, 2024
1 parent 955b763 commit 1514d33
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
7 changes: 7 additions & 0 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ interface Node {
[Throws=NodeError]
string sign_message([ByRef]sequence<u8> msg);
boolean verify_signature([ByRef]sequence<u8> msg, [ByRef]string sig, [ByRef]PublicKey pkey);
[Throws=NodeError]
sequence<KeyValue> get_encoded_channel_monitors();
};

interface Bolt11Payment {
Expand Down Expand Up @@ -424,6 +426,11 @@ dictionary TlvEntry {
sequence<u8> value;
};

dictionary KeyValue {
string key;
sequence<u8> value;
};

interface NetworkGraph {
sequence<u64> list_channels();
ChannelInfo? channel(u64 short_channel_id);
Expand Down
25 changes: 24 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ use types::{
Broadcaster, BumpTransactionEventHandler, ChainMonitor, ChannelManager, DynStore, FeeEstimator,
Graph, KeysManager, PeerManager, Router, Scorer, Sweeper, Wallet,
};
pub use types::{ChannelDetails, ChannelType, PeerDetails, TlvEntry, UserChannelId};
pub use types::{ChannelDetails, ChannelType, KeyValue, PeerDetails, TlvEntry, UserChannelId};

use logger::{log_error, log_info, log_trace, FilesystemLogger, Logger};

Expand Down Expand Up @@ -1539,6 +1539,29 @@ impl Node {
self.payment_store.remove(&payment_id)
}

/// Alby: Return encoded channel monitors for a recovery of last resort
pub fn get_encoded_channel_monitors(&self) -> Result<Vec<KeyValue>, Error> {
let channel_monitor_store = Arc::clone(&self.kv_store);
let channel_monitor_logger = Arc::clone(&self.logger);
// TODO: error handling
let keys = channel_monitor_store.list("monitors", "").unwrap_or_else(|e| {
log_error!(channel_monitor_logger, "Failed to get monitor keys: {}", e);
return Vec::new();
});
let mut entries = Vec::new();

for key in keys {
// TODO: error handling
let value = channel_monitor_store.read("monitors", "", &key).unwrap_or_else(|e| {
log_error!(channel_monitor_logger, "Failed to get monitor value: {}", e);
return Vec::new();
});
entries.push(KeyValue { key, value })
}

return Ok(entries);
}

/// Retrieves an overview of all known balances.
pub fn list_balances(&self) -> BalanceDetails {
let cur_anchor_reserve_sats =
Expand Down
9 changes: 9 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,12 @@ impl_writeable_tlv_based!(TlvEntry, {
(0, r#type, required),
(1, value, required),
});

/// KeyValue from LDK node DB
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct KeyValue {
/// Key.
pub key: String,
/// Serialized value.
pub value: Vec<u8>,
}

0 comments on commit 1514d33

Please sign in to comment.