From: Matt Corallo Date: Fri, 9 Aug 2024 01:13:25 +0000 (+0000) Subject: Add a `lightning-types` dependency to `lightning-invoice` X-Git-Tag: v0.0.124-beta~14^2~4 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=1eba737f442fba62ce25a34b2a857d6b9df484fc;p=rust-lightning Add a `lightning-types` dependency to `lightning-invoice` `lightning-invoice` currently has a dependency on the entire `lightning` crate just because it wants to use some of the useful types from it. This is obviously backwards and leads to some awkwardness like the BOLT 11 invoice signing API in the `lightning` crate taking a `[u5]` rather than a `Bolt11Invoice`. This takes tees us up for the final step, adding a `lightning-types` dependency to `lightning-invoice` and using it for imports rather than the `lightning` crate. --- diff --git a/lightning-invoice/Cargo.toml b/lightning-invoice/Cargo.toml index 94b307167..0f5f464b8 100644 --- a/lightning-invoice/Cargo.toml +++ b/lightning-invoice/Cargo.toml @@ -21,6 +21,7 @@ std = ["bitcoin/std", "lightning/std", "bech32/std"] [dependencies] bech32 = { version = "0.9.1", default-features = false } +lightning-types = { version = "0.1", path = "../lightning-types", default-features = false } lightning = { version = "0.0.123-beta", path = "../lightning", default-features = false } secp256k1 = { version = "0.28.0", default-features = false, features = ["recovery", "alloc"] } serde = { version = "1.0.118", optional = true } diff --git a/lightning-invoice/src/de.rs b/lightning-invoice/src/de.rs index bd9f4a5f6..be1a21aa2 100644 --- a/lightning-invoice/src/de.rs +++ b/lightning-invoice/src/de.rs @@ -14,9 +14,8 @@ use bitcoin::{PubkeyHash, ScriptHash, WitnessVersion}; use bitcoin::hashes::Hash; use bitcoin::hashes::sha256; use crate::prelude::*; -use lightning::ln::types::PaymentSecret; -use lightning::routing::gossip::RoutingFees; -use lightning::routing::router::{RouteHint, RouteHintHop}; +use lightning_types::payment::PaymentSecret; +use lightning_types::routing::{RoutingFees, RouteHint, RouteHintHop}; use secp256k1::ecdsa::{RecoveryId, RecoverableSignature}; use secp256k1::PublicKey; @@ -918,8 +917,7 @@ mod test { #[test] fn test_parse_route() { - use lightning::routing::gossip::RoutingFees; - use lightning::routing::router::{RouteHint, RouteHintHop}; + use lightning_types::routing::{RoutingFees, RouteHint, RouteHintHop}; use crate::PrivateRoute; use bech32::FromBase32; @@ -974,7 +972,7 @@ mod test { #[test] fn test_payment_secret_and_features_de_and_ser() { - use lightning::ln::features::Bolt11InvoiceFeatures; + use lightning_types::features::Bolt11InvoiceFeatures; use secp256k1::ecdsa::{RecoveryId, RecoverableSignature}; use crate::TaggedField::*; use crate::{SiPrefix, SignedRawBolt11Invoice, Bolt11InvoiceSignature, RawBolt11Invoice, RawHrp, RawDataPart, diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index 2df015d1a..0784911fc 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -30,6 +30,7 @@ pub mod utils; extern crate bech32; #[macro_use] extern crate lightning; +extern crate lightning_types; extern crate secp256k1; extern crate alloc; #[cfg(any(test, feature = "std"))] @@ -44,7 +45,7 @@ use bech32::u5; use bitcoin::{Address, Network, PubkeyHash, ScriptHash, WitnessProgram, WitnessVersion}; use bitcoin::address::Payload; use bitcoin::hashes::{Hash, sha256}; -use lightning::ln::features::Bolt11InvoiceFeatures; +use lightning_types::features::Bolt11InvoiceFeatures; use lightning::util::invoice::construct_invoice_preimage; use secp256k1::PublicKey; @@ -64,12 +65,10 @@ use core::str; use serde::{Deserialize, Deserializer,Serialize, Serializer, de::Error}; #[doc(no_inline)] -pub use lightning::ln::types::PaymentSecret; +pub use lightning_types::payment::PaymentSecret; #[doc(no_inline)] -pub use lightning::routing::router::{RouteHint, RouteHintHop}; -#[doc(no_inline)] -pub use lightning::routing::gossip::RoutingFees; -use lightning::util::string::UntrustedString; +pub use lightning_types::routing::{RoutingFees, RouteHint, RouteHintHop}; +use lightning_types::string::UntrustedString; mod de; mod ser; @@ -161,7 +160,7 @@ pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = 18; /// use secp256k1::Secp256k1; /// use secp256k1::SecretKey; /// -/// use lightning::ln::types::PaymentSecret; +/// use lightning_types::payment::PaymentSecret; /// /// use lightning_invoice::{Currency, InvoiceBuilder}; /// @@ -1877,14 +1876,14 @@ mod test { #[test] fn test_check_feature_bits() { use crate::TaggedField::*; - use lightning::ln::features::Bolt11InvoiceFeatures; + use lightning_types::features::Bolt11InvoiceFeatures; use secp256k1::Secp256k1; use secp256k1::SecretKey; use crate::{Bolt11Invoice, RawBolt11Invoice, RawHrp, RawDataPart, Currency, Sha256, PositiveTimestamp, Bolt11SemanticError}; let private_key = SecretKey::from_slice(&[42; 32]).unwrap(); - let payment_secret = lightning::ln::types::PaymentSecret([21; 32]); + let payment_secret = lightning_types::payment::PaymentSecret([21; 32]); let invoice_template = RawBolt11Invoice { hrp: RawHrp { currency: Currency::Bitcoin, @@ -1998,7 +1997,7 @@ mod test { #[test] fn test_builder_fail() { use crate::*; - use lightning::routing::router::RouteHintHop; + use lightning_types::routing::RouteHintHop; use std::iter::FromIterator; use secp256k1::PublicKey; @@ -2052,7 +2051,7 @@ mod test { #[test] fn test_builder_ok() { use crate::*; - use lightning::routing::router::RouteHintHop; + use lightning_types::routing::RouteHintHop; use secp256k1::Secp256k1; use secp256k1::{SecretKey, PublicKey}; use std::time::Duration;