Skip to content

Commit 9026795

Browse files
committed
Drop Network newtype again
We previously (re-)introduced a newtype with the most-recent `rust-bitcoin` update as it added the `non_exhaustive` attribute to the `Network` enum. However, we can now drop this newtype again as UniFFI 0.26.0 added support for `non_exhaustive` enums.
1 parent 3345ade commit 9026795

File tree

7 files changed

+17
-67
lines changed

7 files changed

+17
-67
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ LDK Node is a self-custodial Lightning node in library form. Its central goal is
1313
The primary abstraction of the library is the [`Node`][api_docs_node], which can be retrieved by setting up and configuring a [`Builder`][api_docs_builder] to your liking and calling one of the `build` methods. `Node` can then be controlled via commands such as `start`, `stop`, `connect_open_channel`, `send_payment`, etc.
1414

1515
```rust
16-
use ldk_node::{Builder, Network};
16+
use ldk_node::Builder;
1717
use ldk_node::lightning_invoice::Bolt11Invoice;
1818
use ldk_node::lightning::ln::msgs::SocketAddress;
1919
use ldk_node::bitcoin::secp256k1::PublicKey;
20+
use ldk_node::bitcoin::Network;
2021
use std::str::FromStr;
2122

2223
fn main() {

bindings/ldk_node.udl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ enum PaymentStatus {
165165
"Failed",
166166
};
167167

168+
[NonExhaustive]
168169
enum Network {
169170
"Bitcoin",
170171
"Testnet",

src/builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::peer_store::PeerStore;
99
use crate::sweep::OutputSweeper;
1010
use crate::tx_broadcaster::TransactionBroadcaster;
1111
use crate::types::{
12-
ChainMonitor, ChannelManager, FakeMessageRouter, GossipSync, KeysManager, Network,
13-
NetworkGraph, OnionMessenger, PeerManager,
12+
ChainMonitor, ChannelManager, FakeMessageRouter, GossipSync, KeysManager, NetworkGraph,
13+
OnionMessenger, PeerManager,
1414
};
1515
use crate::wallet::Wallet;
1616
use crate::LogLevel;
@@ -49,7 +49,7 @@ use bdk::template::Bip84;
4949

5050
use bip39::Mnemonic;
5151

52-
use bitcoin::BlockHash;
52+
use bitcoin::{BlockHash, Network};
5353

5454
#[cfg(any(vss, vss_test))]
5555
use bitcoin::bip32::ChildNumber;

src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
//! [`send_payment`], etc.:
2727
//!
2828
//! ```no_run
29-
//! use ldk_node::{Builder, Network};
29+
//! use ldk_node::Builder;
3030
//! use ldk_node::lightning_invoice::Bolt11Invoice;
3131
//! use ldk_node::lightning::ln::msgs::SocketAddress;
32+
//! use ldk_node::bitcoin::Network;
3233
//! use ldk_node::bitcoin::secp256k1::PublicKey;
3334
//! use std::str::FromStr;
3435
//!
@@ -122,7 +123,7 @@ use types::{
122123
Broadcaster, ChainMonitor, ChannelManager, FeeEstimator, KeysManager, NetworkGraph,
123124
PeerManager, Router, Scorer, Sweeper, Wallet,
124125
};
125-
pub use types::{ChannelDetails, Network, PeerDetails, UserChannelId};
126+
pub use types::{ChannelDetails, PeerDetails, UserChannelId};
126127

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

@@ -148,7 +149,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
148149
use bitcoin::hashes::Hash;
149150
use bitcoin::secp256k1::PublicKey;
150151

151-
use bitcoin::{Address, Txid};
152+
use bitcoin::{Address, Network, Txid};
152153

153154
use rand::Rng;
154155

@@ -1494,7 +1495,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
14941495
fn receive_payment_inner(
14951496
&self, amount_msat: Option<u64>, description: &str, expiry_secs: u32,
14961497
) -> Result<Bolt11Invoice, Error> {
1497-
let currency = Currency::from(bitcoin::Network::from(self.config.network));
1498+
let currency = Currency::from(self.config.network);
14981499
let keys_manager = Arc::clone(&self.keys_manager);
14991500
let invoice = match lightning_invoice::utils::create_invoice_from_channelmanager(
15001501
&self.channel_manager,
@@ -1547,7 +1548,8 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
15471548
///
15481549
/// For example, you could retrieve all stored outbound payments as follows:
15491550
/// ```
1550-
/// # use ldk_node::{Builder, Config, Network, PaymentDirection};
1551+
/// # use ldk_node::{Builder, Config, PaymentDirection};
1552+
/// # use ldk_node::bitcoin::Network;
15511553
/// # let mut config = Config::default();
15521554
/// # config.network = Network::Regtest;
15531555
/// # config.storage_dir_path = "/tmp/ldk_node_test/".to_string();

src/types.rs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ use lightning_transaction_sync::EsploraSyncClient;
2121
use bitcoin::secp256k1::{self, PublicKey, Secp256k1};
2222
use bitcoin::OutPoint;
2323

24-
use std::fmt;
25-
use std::str::FromStr;
2624
use std::sync::{Arc, Mutex, RwLock};
2725

2826
pub(crate) type ChainMonitor<K> = chainmonitor::ChainMonitor<
@@ -139,58 +137,6 @@ pub(crate) type Sweeper<K> = OutputSweeper<
139137
Arc<FilesystemLogger>,
140138
>;
141139

142-
/// The cryptocurrency network to act on.
143-
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Debug)]
144-
pub enum Network {
145-
/// Mainnet Bitcoin.
146-
Bitcoin,
147-
/// Bitcoin's testnet network.
148-
Testnet,
149-
/// Bitcoin's signet network.
150-
Signet,
151-
/// Bitcoin's regtest network.
152-
Regtest,
153-
}
154-
155-
impl TryFrom<bitcoin::Network> for Network {
156-
type Error = ();
157-
158-
fn try_from(network: bitcoin::Network) -> Result<Self, Self::Error> {
159-
match network {
160-
bitcoin::Network::Bitcoin => Ok(Self::Bitcoin),
161-
bitcoin::Network::Testnet => Ok(Self::Testnet),
162-
bitcoin::Network::Signet => Ok(Self::Signet),
163-
bitcoin::Network::Regtest => Ok(Self::Regtest),
164-
_ => Err(()),
165-
}
166-
}
167-
}
168-
169-
impl From<Network> for bitcoin::Network {
170-
fn from(network: Network) -> Self {
171-
match network {
172-
Network::Bitcoin => bitcoin::Network::Bitcoin,
173-
Network::Testnet => bitcoin::Network::Testnet,
174-
Network::Signet => bitcoin::Network::Signet,
175-
Network::Regtest => bitcoin::Network::Regtest,
176-
}
177-
}
178-
}
179-
180-
impl fmt::Display for Network {
181-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
182-
bitcoin::Network::from(*self).fmt(f)
183-
}
184-
}
185-
186-
impl FromStr for Network {
187-
type Err = ();
188-
189-
fn from_str(s: &str) -> Result<Self, Self::Err> {
190-
bitcoin::Network::from_str(s).map_err(|_| ())?.try_into()
191-
}
192-
}
193-
194140
/// A local, potentially user-provided, identifier of a channel.
195141
///
196142
/// By default, this will be randomly generated for the user to ensure local uniqueness.

tests/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
use ldk_node::io::sqlite_store::SqliteStore;
55
use ldk_node::{
6-
Builder, Config, Event, LogLevel, Network, Node, NodeError, PaymentDirection, PaymentStatus,
6+
Builder, Config, Event, LogLevel, Node, NodeError, PaymentDirection, PaymentStatus,
77
};
88

99
use lightning::ln::msgs::SocketAddress;
1010
use lightning::util::persist::KVStore;
1111
use lightning::util::test_utils::TestStore;
1212
use lightning_persister::fs_store::FilesystemStore;
1313

14-
use bitcoin::{Address, Amount, OutPoint, Txid};
14+
use bitcoin::{Address, Amount, Network, OutPoint, Txid};
1515

1616
use bitcoincore_rpc::bitcoincore_rpc_json::AddressType;
1717
use bitcoincore_rpc::Client as BitcoindClient;

tests/integration_tests_rust.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use common::{
66
setup_node, setup_two_nodes, wait_for_tx, TestSyncStore,
77
};
88

9-
use ldk_node::{Builder, Event, Network, NodeError};
9+
use ldk_node::{Builder, Event, NodeError};
1010

11-
use bitcoin::Amount;
11+
use bitcoin::{Amount, Network};
1212

1313
use std::sync::Arc;
1414

0 commit comments

Comments
 (0)