]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add a `lightning-types` dependency to `lightning-invoice`
authorMatt Corallo <git@bluematt.me>
Fri, 9 Aug 2024 01:13:25 +0000 (01:13 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 13 Aug 2024 12:54:59 +0000 (12:54 +0000)
`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.

lightning-invoice/Cargo.toml
lightning-invoice/src/de.rs
lightning-invoice/src/lib.rs

index 94b3071676a36f57d31abb81a47706750896d962..0f5f464b83a988a3577e6ce4760ad9ab07c558ba 100644 (file)
@@ -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 }
index bd9f4a5f6dedcf2b15502f821a6951a92ec5e99f..be1a21aa25f73b613fd01c401bce804da324a790 100644 (file)
@@ -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,
index 2df015d1a08f59cb97b26825821385ffc08f2e1a..0784911fc6147845a2cb08b72fd35d04fd8c0099 100644 (file)
@@ -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;