Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get encoded channel monitors #49

Merged
merged 7 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
rolznz marked this conversation as resolved.
Show resolved Hide resolved
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>,
}
Loading