Skip to content

Commit

Permalink
Merge pull request #133 from valentinewallace/2024-04-0.0.123
Browse files Browse the repository at this point in the history
Update to LDK 0.0.123
  • Loading branch information
tnull committed May 29, 2024
2 parents e6dd91c + c394d2f commit 0071c38
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 76 deletions.
29 changes: 14 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
lightning = { version = "0.0.121", features = ["max_level_trace"] }
lightning-block-sync = { version = "0.0.121", features = [ "rpc-client", "tokio" ] }
lightning-invoice = { version = "0.29.0" }
lightning-net-tokio = { version = "0.0.121" }
lightning-persister = { version = "0.0.121" }
lightning-background-processor = { version = "0.0.121", features = [ "futures" ] }
lightning-rapid-gossip-sync = { version = "0.0.121" }
lightning = { version = "0.0.123", features = ["max_level_trace"] }
lightning-block-sync = { version = "0.0.123", features = [ "rpc-client", "tokio" ] }
lightning-invoice = { version = "0.31.0" }
lightning-net-tokio = { version = "0.0.123" }
lightning-persister = { version = "0.0.123" }
lightning-background-processor = { version = "0.0.123", features = [ "futures" ] }
lightning-rapid-gossip-sync = { version = "0.0.123" }

base64 = "0.13.0"
bitcoin = "0.30.2"
Expand Down
9 changes: 9 additions & 0 deletions src/bitcoind_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use bitcoin::{Network, OutPoint, TxOut, WPubkeyHash};
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
use lightning::events::bump_transaction::{Utxo, WalletSource};
use lightning::log_error;
use lightning::sign::ChangeDestinationSource;
use lightning::util::logger::Logger;
use lightning_block_sync::http::HttpEndpoint;
use lightning_block_sync::rpc::RpcClient;
Expand Down Expand Up @@ -317,6 +318,14 @@ impl BroadcasterInterface for BitcoindClient {
}
}

impl ChangeDestinationSource for BitcoindClient {
fn get_change_destination_script(&self) -> Result<ScriptBuf, ()> {
tokio::task::block_in_place(move || {
Ok(self.handle.block_on(async move { self.get_new_address().await.script_pubkey() }))
})
}
}

impl WalletSource for BitcoindClient {
fn list_confirmed_utxos(&self) -> Result<Vec<Utxo>, ()> {
let utxos = tokio::task::block_in_place(move || {
Expand Down
17 changes: 8 additions & 9 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ pub(crate) fn poll_for_user_input(
);
},
"getoffer" => {
let offer_builder = channel_manager.create_offer_builder(String::new());
let offer_builder = channel_manager.create_offer_builder();
if let Err(e) = offer_builder {
println!("ERROR: Failed to initiate offer building: {:?}", e);
continue;
Expand Down Expand Up @@ -603,14 +603,14 @@ fn node_info(channel_manager: &Arc<ChannelManager>, peer_manager: &Arc<PeerManag
println!("\t\t num_usable_channels: {}", chans.iter().filter(|c| c.is_usable).count());
let local_balance_msat = chans.iter().map(|c| c.balance_msat).sum::<u64>();
println!("\t\t local_balance_msat: {}", local_balance_msat);
println!("\t\t num_peers: {}", peer_manager.get_peer_node_ids().len());
println!("\t\t num_peers: {}", peer_manager.list_peers().len());
println!("\t}},");
}

fn list_peers(peer_manager: Arc<PeerManager>) {
println!("\t{{");
for (pubkey, _) in peer_manager.get_peer_node_ids() {
println!("\t\t pubkey: {}", pubkey);
for peer_details in peer_manager.list_peers() {
println!("\t\t pubkey: {}", peer_details.counterparty_node_id);
}
println!("\t}},");
}
Expand Down Expand Up @@ -701,8 +701,8 @@ fn list_payments(
pub(crate) async fn connect_peer_if_necessary(
pubkey: PublicKey, peer_addr: SocketAddr, peer_manager: Arc<PeerManager>,
) -> Result<(), ()> {
for (node_pubkey, _) in peer_manager.get_peer_node_ids() {
if node_pubkey == pubkey {
for peer_details in peer_manager.list_peers() {
if peer_details.counterparty_node_id == pubkey {
return Ok(());
}
}
Expand All @@ -725,7 +725,7 @@ pub(crate) async fn do_connect_peer(
_ = &mut connection_closed_future => return Err(()),
_ = tokio::time::sleep(Duration::from_millis(10)) => {},
};
if peer_manager.get_peer_node_ids().iter().find(|(id, _)| *id == pubkey).is_some() {
if peer_manager.peer_by_node_id(&pubkey).is_some() {
return Ok(());
}
}
Expand All @@ -747,8 +747,7 @@ fn do_disconnect_peer(
}

//check the pubkey matches a valid connected peer
let peers = peer_manager.get_peer_node_ids();
if !peers.iter().any(|(pk, _)| &pubkey == pk) {
if peer_manager.peer_by_node_id(&pubkey).is_none() {
println!("Error: Could not find peer {}", pubkey);
return Err(());
}
Expand Down
Loading

0 comments on commit 0071c38

Please sign in to comment.