Skip to content

Commit

Permalink
Merge pull request #230 from tnull/2024-01-upgrade-uniffi-to-0.26
Browse files Browse the repository at this point in the history
Upgrade UniFFI to 0.26.0
  • Loading branch information
tnull committed Feb 2, 2024
2 parents c755eee + 9026795 commit e335f0b
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 75 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ futures = "0.3"
tokio = { version = "1", default-features = false, features = [ "rt-multi-thread", "time", "sync" ] }
esplora-client = { version = "0.6", default-features = false }
libc = "0.2"
uniffi = { version = "0.25.1", features = ["build"], optional = true }
uniffi = { version = "0.26.0", features = ["build"], optional = true }

[target.'cfg(vss)'.dependencies]
vss-client = "0.2"
Expand All @@ -92,7 +92,7 @@ electrsd = { version = "0.26.0", features = ["legacy"] }
clightningrpc = { version = "0.3.0-beta.8", default-features = false }

[build-dependencies]
uniffi = { version = "0.25.1", features = ["build"], optional = true }
uniffi = { version = "0.26.0", features = ["build"], optional = true }

[profile.release]
panic = "abort"
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ LDK Node is a self-custodial Lightning node in library form. Its central goal is
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.

```rust
use ldk_node::{Builder, Network};
use ldk_node::Builder;
use ldk_node::lightning_invoice::Bolt11Invoice;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::bitcoin::Network;
use std::str::FromStr;

fn main() {
Expand Down
6 changes: 3 additions & 3 deletions bindings/kotlin/ldk-node-android/lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repositories {
}

android {
compileSdk = 31
compileSdk = 33

defaultConfig {
minSdk = 21
Expand All @@ -41,7 +41,7 @@ android {
}

dependencies {
implementation("net.java.dev.jna:jna:5.8.0@aar")
implementation("net.java.dev.jna:jna:5.12.0@aar")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7")
implementation("androidx.appcompat:appcompat:1.4.0")
implementation("androidx.core:core-ktx:1.7.0")
Expand All @@ -50,7 +50,7 @@ dependencies {
androidTestImplementation("com.github.tony19:logback-android:2.0.0")
androidTestImplementation("androidx.test.ext:junit:1.1.3")
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
androidTestImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1")
androidTestImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
androidTestImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}

Expand Down
2 changes: 1 addition & 1 deletion bindings/kotlin/ldk-node-jvm/lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ dependencies {
// Use the Kotlin JDK 8 standard library.
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

implementation("net.java.dev.jna:jna:5.8.0")
implementation("net.java.dev.jna:jna:5.12.0")
}

tasks.named<Test>("test") {
Expand Down
1 change: 1 addition & 0 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ enum PaymentStatus {
"Failed",
};

[NonExhaustive]
enum Network {
"Bitcoin",
"Testnet",
Expand Down
2 changes: 1 addition & 1 deletion bindings/uniffi-bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
uniffi = { version = "0.25.1", features = ["cli"] }
uniffi = { version = "0.26.0", features = ["cli"] }
2 changes: 1 addition & 1 deletion scripts/uniffi_bindgen_generate_kotlin_android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-android
CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target x86_64-linux-android || exit 1
CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --profile release-smaller --features uniffi --target armv7-linux-androideabi || exit 1
CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target aarch64-linux-android || exit 1
$UNIFFI_BINDGEN_BIN generate bindings/ldk_node.udl --language kotlin -o "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/kotlin || exit 1
$UNIFFI_BINDGEN_BIN generate bindings/ldk_node.udl --language kotlin --config uniffi-android.toml -o "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/kotlin || exit 1

JNI_LIB_DIR="$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/jniLibs/
mkdir -p $JNI_LIB_DIR/x86_64 || exit 1
Expand Down
6 changes: 3 additions & 3 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::peer_store::PeerStore;
use crate::sweep::OutputSweeper;
use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
ChainMonitor, ChannelManager, FakeMessageRouter, GossipSync, KeysManager, Network,
NetworkGraph, OnionMessenger, PeerManager,
ChainMonitor, ChannelManager, FakeMessageRouter, GossipSync, KeysManager, NetworkGraph,
OnionMessenger, PeerManager,
};
use crate::wallet::Wallet;
use crate::LogLevel;
Expand Down Expand Up @@ -49,7 +49,7 @@ use bdk::template::Bip84;

use bip39::Mnemonic;

use bitcoin::BlockHash;
use bitcoin::{BlockHash, Network};

#[cfg(any(vss, vss_test))]
use bitcoin::bip32::ChildNumber;
Expand Down
12 changes: 7 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
//! [`send_payment`], etc.:
//!
//! ```no_run
//! use ldk_node::{Builder, Network};
//! use ldk_node::Builder;
//! use ldk_node::lightning_invoice::Bolt11Invoice;
//! use ldk_node::lightning::ln::msgs::SocketAddress;
//! use ldk_node::bitcoin::Network;
//! use ldk_node::bitcoin::secp256k1::PublicKey;
//! use std::str::FromStr;
//!
Expand Down Expand Up @@ -122,7 +123,7 @@ use types::{
Broadcaster, ChainMonitor, ChannelManager, FeeEstimator, KeysManager, NetworkGraph,
PeerManager, Router, Scorer, Sweeper, Wallet,
};
pub use types::{ChannelDetails, Network, PeerDetails, UserChannelId};
pub use types::{ChannelDetails, PeerDetails, UserChannelId};

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

Expand All @@ -148,7 +149,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
use bitcoin::hashes::Hash;
use bitcoin::secp256k1::PublicKey;

use bitcoin::{Address, Txid};
use bitcoin::{Address, Network, Txid};

use rand::Rng;

Expand Down Expand Up @@ -1494,7 +1495,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
fn receive_payment_inner(
&self, amount_msat: Option<u64>, description: &str, expiry_secs: u32,
) -> Result<Bolt11Invoice, Error> {
let currency = Currency::from(bitcoin::Network::from(self.config.network));
let currency = Currency::from(self.config.network);
let keys_manager = Arc::clone(&self.keys_manager);
let invoice = match lightning_invoice::utils::create_invoice_from_channelmanager(
&self.channel_manager,
Expand Down Expand Up @@ -1547,7 +1548,8 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
///
/// For example, you could retrieve all stored outbound payments as follows:
/// ```
/// # use ldk_node::{Builder, Config, Network, PaymentDirection};
/// # use ldk_node::{Builder, Config, PaymentDirection};
/// # use ldk_node::bitcoin::Network;
/// # let mut config = Config::default();
/// # config.network = Network::Regtest;
/// # config.storage_dir_path = "/tmp/ldk_node_test/".to_string();
Expand Down
54 changes: 0 additions & 54 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ use lightning_transaction_sync::EsploraSyncClient;
use bitcoin::secp256k1::{self, PublicKey, Secp256k1};
use bitcoin::OutPoint;

use std::fmt;
use std::str::FromStr;
use std::sync::{Arc, Mutex, RwLock};

pub(crate) type ChainMonitor<K> = chainmonitor::ChainMonitor<
Expand Down Expand Up @@ -139,58 +137,6 @@ pub(crate) type Sweeper<K> = OutputSweeper<
Arc<FilesystemLogger>,
>;

/// The cryptocurrency network to act on.
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Debug)]
pub enum Network {
/// Mainnet Bitcoin.
Bitcoin,
/// Bitcoin's testnet network.
Testnet,
/// Bitcoin's signet network.
Signet,
/// Bitcoin's regtest network.
Regtest,
}

impl TryFrom<bitcoin::Network> for Network {
type Error = ();

fn try_from(network: bitcoin::Network) -> Result<Self, Self::Error> {
match network {
bitcoin::Network::Bitcoin => Ok(Self::Bitcoin),
bitcoin::Network::Testnet => Ok(Self::Testnet),
bitcoin::Network::Signet => Ok(Self::Signet),
bitcoin::Network::Regtest => Ok(Self::Regtest),
_ => Err(()),
}
}
}

impl From<Network> for bitcoin::Network {
fn from(network: Network) -> Self {
match network {
Network::Bitcoin => bitcoin::Network::Bitcoin,
Network::Testnet => bitcoin::Network::Testnet,
Network::Signet => bitcoin::Network::Signet,
Network::Regtest => bitcoin::Network::Regtest,
}
}
}

impl fmt::Display for Network {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
bitcoin::Network::from(*self).fmt(f)
}
}

impl FromStr for Network {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
bitcoin::Network::from_str(s).map_err(|_| ())?.try_into()
}
}

/// A local, potentially user-provided, identifier of a channel.
///
/// By default, this will be randomly generated for the user to ensure local uniqueness.
Expand Down
4 changes: 2 additions & 2 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

use ldk_node::io::sqlite_store::SqliteStore;
use ldk_node::{
Builder, Config, Event, LogLevel, Network, Node, NodeError, PaymentDirection, PaymentStatus,
Builder, Config, Event, LogLevel, Node, NodeError, PaymentDirection, PaymentStatus,
};

use lightning::ln::msgs::SocketAddress;
use lightning::util::persist::KVStore;
use lightning::util::test_utils::TestStore;
use lightning_persister::fs_store::FilesystemStore;

use bitcoin::{Address, Amount, OutPoint, Txid};
use bitcoin::{Address, Amount, Network, OutPoint, Txid};

use bitcoincore_rpc::bitcoincore_rpc_json::AddressType;
use bitcoincore_rpc::Client as BitcoindClient;
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use common::{
setup_node, setup_two_nodes, wait_for_tx, TestSyncStore,
};

use ldk_node::{Builder, Event, Network, NodeError};
use ldk_node::{Builder, Event, NodeError};

use bitcoin::Amount;
use bitcoin::{Amount, Network};

use std::sync::Arc;

Expand Down
3 changes: 3 additions & 0 deletions uniffi-android.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[bindings.kotlin]
android = true
android_cleaner = true

0 comments on commit e335f0b

Please sign in to comment.