diff --git a/lightning/src/blinded_path/mod.rs b/lightning/src/blinded_path/mod.rs index 29caafa4a4f..7f4cfe2e300 100644 --- a/lightning/src/blinded_path/mod.rs +++ b/lightning/src/blinded_path/mod.rs @@ -121,9 +121,9 @@ pub struct BlindedHop { impl BlindedPath { /// Create a one-hop blinded path for a message. - pub fn one_hop_for_message( - recipient_node_id: PublicKey, entropy_source: &ES, secp_ctx: &Secp256k1 - ) -> Result { + pub fn one_hop_for_message( + recipient_node_id: PublicKey, entropy_source: ES, secp_ctx: &Secp256k1 + ) -> Result where ES::Target: EntropySource { Self::new_for_message(&[recipient_node_id], entropy_source, secp_ctx) } @@ -132,9 +132,9 @@ impl BlindedPath { /// /// Errors if no hops are provided or if `node_pk`(s) are invalid. // TODO: make all payloads the same size with padding + add dummy hops - pub fn new_for_message( - node_pks: &[PublicKey], entropy_source: &ES, secp_ctx: &Secp256k1 - ) -> Result { + pub fn new_for_message( + node_pks: &[PublicKey], entropy_source: ES, secp_ctx: &Secp256k1 + ) -> Result where ES::Target: EntropySource { if node_pks.is_empty() { return Err(()) } let blinding_secret_bytes = entropy_source.get_secure_random_bytes(); let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted"); @@ -148,10 +148,10 @@ impl BlindedPath { } /// Create a one-hop blinded path for a payment. - pub fn one_hop_for_payment( + pub fn one_hop_for_payment( payee_node_id: PublicKey, payee_tlvs: payment::ReceiveTlvs, min_final_cltv_expiry_delta: u16, - entropy_source: &ES, secp_ctx: &Secp256k1 - ) -> Result<(BlindedPayInfo, Self), ()> { + entropy_source: ES, secp_ctx: &Secp256k1 + ) -> Result<(BlindedPayInfo, Self), ()> where ES::Target: EntropySource { // This value is not considered in pathfinding for 1-hop blinded paths, because it's intended to // be in relation to a specific channel. let htlc_maximum_msat = u64::max_value(); @@ -170,11 +170,11 @@ impl BlindedPath { /// /// [`ForwardTlvs`]: crate::blinded_path::payment::ForwardTlvs // TODO: make all payloads the same size with padding + add dummy hops - pub fn new_for_payment( + pub fn new_for_payment( intermediate_nodes: &[payment::ForwardNode], payee_node_id: PublicKey, payee_tlvs: payment::ReceiveTlvs, htlc_maximum_msat: u64, min_final_cltv_expiry_delta: u16, - entropy_source: &ES, secp_ctx: &Secp256k1 - ) -> Result<(BlindedPayInfo, Self), ()> { + entropy_source: ES, secp_ctx: &Secp256k1 + ) -> Result<(BlindedPayInfo, Self), ()> where ES::Target: EntropySource { let introduction_node = IntroductionNode::NodeId( intermediate_nodes.first().map_or(payee_node_id, |n| n.node_id) ); diff --git a/lightning/src/chain/mod.rs b/lightning/src/chain/mod.rs index 8639e268dff..71b29b672ca 100644 --- a/lightning/src/chain/mod.rs +++ b/lightning/src/chain/mod.rs @@ -52,6 +52,9 @@ impl BestBlock { } /// Returns a `BestBlock` as identified by the given block hash and height. + /// + /// This is not exported to bindings users directly as the bindings auto-generate an + /// equivalent `new`. pub fn new(block_hash: BlockHash, height: u32) -> Self { BestBlock { block_hash, height } } diff --git a/lightning/src/lib.rs b/lightning/src/lib.rs index 3bcd5d72c64..be3da45528b 100644 --- a/lightning/src/lib.rs +++ b/lightning/src/lib.rs @@ -96,6 +96,8 @@ pub use core2::io; #[cfg(not(feature = "std"))] #[doc(hidden)] /// IO utilities public only for use by in-crate macros. These should not be used externally +/// +/// This is not exported to bindings users as it is not intended for public consumption. pub mod io_extras { use core2::io::{self, Read, Write}; @@ -158,6 +160,8 @@ pub mod io_extras { #[cfg(feature = "std")] #[doc(hidden)] /// IO utilities public only for use by in-crate macros. These should not be used externally +/// +/// This is not exported to bindings users as it is not intended for public consumption. mod io_extras { pub fn read_to_end(mut d: D) -> Result, ::std::io::Error> { let mut buf = Vec::new(); diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index d2b7166a503..f751ae7abcf 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -8563,8 +8563,6 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => { /// /// Errors if the parameterized [`Router`] is unable to create a blinded path for the offer. /// - /// This is not exported to bindings users as builder patterns don't map outside of move semantics. - /// /// [`Offer`]: crate::offers::offer::Offer /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest pub fn create_offer_builder(&$self) -> Result<$builder, Bolt12SemanticError> { @@ -8627,8 +8625,6 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => { /// - `amount_msats` is invalid, or /// - the parameterized [`Router`] is unable to create a blinded path for the refund. /// - /// This is not exported to bindings users as builder patterns don't map outside of move semantics. - /// /// [`Refund`]: crate::offers::refund::Refund /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice /// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths diff --git a/lightning/src/ln/onion_payment.rs b/lightning/src/ln/onion_payment.rs index 8293a32021e..20a1e1dbb62 100644 --- a/lightning/src/ln/onion_payment.rs +++ b/lightning/src/ln/onion_payment.rs @@ -26,7 +26,7 @@ use crate::prelude::*; use core::ops::Deref; /// Invalid inbound onion payment. -#[derive(Debug)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct InboundHTLCErr { /// BOLT 4 error code. pub err_code: u16, diff --git a/lightning/src/ln/types.rs b/lightning/src/ln/types.rs index 14774fb5e66..5966b371164 100644 --- a/lightning/src/ln/types.rs +++ b/lightning/src/ln/types.rs @@ -35,8 +35,6 @@ use core::ops::Deref; /// A _temporary_ ID is generated randomly. /// (Later revocation-point-based _v2_ is a possibility.) /// The variety (context) is not stored, it is relevant only at creation. -/// -/// This is not exported to bindings users as we just use [u8; 32] directly. #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct ChannelId(pub [u8; 32]); diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs index 6f907d785c7..ecb0c80061b 100644 --- a/lightning/src/offers/invoice.rs +++ b/lightning/src/offers/invoice.rs @@ -503,6 +503,7 @@ for InvoiceBuilder<'a, DerivedSigningPubkey> { /// /// This is serialized as a TLV stream, which includes TLV records from the originating message. As /// such, it may include unknown, odd TLV records. +#[derive(Clone)] pub struct UnsignedBolt12Invoice { bytes: Vec, contents: InvoiceContents, @@ -697,7 +698,7 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => { /// /// [`Offer`]: crate::offers::offer::Offer /// [`Offer::amount`]: crate::offers::offer::Offer::amount - pub fn amount(&$self) -> Option<&Amount> { + pub fn amount(&$self) -> Option { $contents.amount() } @@ -944,7 +945,7 @@ impl InvoiceContents { } } - fn amount(&self) -> Option<&Amount> { + fn amount(&self) -> Option { match self { InvoiceContents::ForOffer { invoice_request, .. } => invoice_request.inner.offer.amount(), @@ -1545,7 +1546,7 @@ mod tests { assert_eq!(unsigned_invoice.payer_metadata(), &[1; 32]); assert_eq!(unsigned_invoice.offer_chains(), Some(vec![ChainHash::using_genesis_block(Network::Bitcoin)])); assert_eq!(unsigned_invoice.metadata(), None); - assert_eq!(unsigned_invoice.amount(), Some(&Amount::Bitcoin { amount_msats: 1000 })); + assert_eq!(unsigned_invoice.amount(), Some(Amount::Bitcoin { amount_msats: 1000 })); assert_eq!(unsigned_invoice.description(), Some(PrintableString(""))); assert_eq!(unsigned_invoice.offer_features(), Some(&OfferFeatures::empty())); assert_eq!(unsigned_invoice.absolute_expiry(), None); @@ -1589,7 +1590,7 @@ mod tests { assert_eq!(invoice.payer_metadata(), &[1; 32]); assert_eq!(invoice.offer_chains(), Some(vec![ChainHash::using_genesis_block(Network::Bitcoin)])); assert_eq!(invoice.metadata(), None); - assert_eq!(invoice.amount(), Some(&Amount::Bitcoin { amount_msats: 1000 })); + assert_eq!(invoice.amount(), Some(Amount::Bitcoin { amount_msats: 1000 })); assert_eq!(invoice.description(), Some(PrintableString(""))); assert_eq!(invoice.offer_features(), Some(&OfferFeatures::empty())); assert_eq!(invoice.absolute_expiry(), None); diff --git a/lightning/src/offers/invoice_request.rs b/lightning/src/offers/invoice_request.rs index faeef26c82f..f243ea693f2 100644 --- a/lightning/src/offers/invoice_request.rs +++ b/lightning/src/offers/invoice_request.rs @@ -487,6 +487,7 @@ for InvoiceRequestBuilder<'a, 'b, DerivedPayerId, secp256k1::All> { /// /// This is serialized as a TLV stream, which includes TLV records from the originating message. As /// such, it may include unknown, odd TLV records. +#[derive(Clone)] pub struct UnsignedInvoiceRequest { bytes: Vec, contents: InvoiceRequestContents, @@ -1247,7 +1248,7 @@ mod tests { assert_eq!(unsigned_invoice_request.payer_metadata(), &[1; 32]); assert_eq!(unsigned_invoice_request.chains(), vec![ChainHash::using_genesis_block(Network::Bitcoin)]); assert_eq!(unsigned_invoice_request.metadata(), None); - assert_eq!(unsigned_invoice_request.amount(), Some(&Amount::Bitcoin { amount_msats: 1000 })); + assert_eq!(unsigned_invoice_request.amount(), Some(Amount::Bitcoin { amount_msats: 1000 })); assert_eq!(unsigned_invoice_request.description(), Some(PrintableString(""))); assert_eq!(unsigned_invoice_request.offer_features(), &OfferFeatures::empty()); assert_eq!(unsigned_invoice_request.absolute_expiry(), None); @@ -1279,7 +1280,7 @@ mod tests { assert_eq!(invoice_request.payer_metadata(), &[1; 32]); assert_eq!(invoice_request.chains(), vec![ChainHash::using_genesis_block(Network::Bitcoin)]); assert_eq!(invoice_request.metadata(), None); - assert_eq!(invoice_request.amount(), Some(&Amount::Bitcoin { amount_msats: 1000 })); + assert_eq!(invoice_request.amount(), Some(Amount::Bitcoin { amount_msats: 1000 })); assert_eq!(invoice_request.description(), Some(PrintableString(""))); assert_eq!(invoice_request.offer_features(), &OfferFeatures::empty()); assert_eq!(invoice_request.absolute_expiry(), None); diff --git a/lightning/src/offers/offer.rs b/lightning/src/offers/offer.rs index 6df9b30a4ef..5a824b9162f 100644 --- a/lightning/src/offers/offer.rs +++ b/lightning/src/offers/offer.rs @@ -163,10 +163,9 @@ pub struct OfferBuilder<'a, M: MetadataStrategy, T: secp256k1::Signing> { /// /// See [module-level documentation] for usage. /// -/// This is not exported to bindings users as builder patterns don't map outside of move semantics. -/// /// [module-level documentation]: self #[cfg(c_bindings)] +#[derive(Clone)] pub struct OfferWithExplicitMetadataBuilder<'a> { offer: OfferContents, metadata_strategy: core::marker::PhantomData, @@ -177,10 +176,9 @@ pub struct OfferWithExplicitMetadataBuilder<'a> { /// /// See [module-level documentation] for usage. /// -/// This is not exported to bindings users as builder patterns don't map outside of move semantics. -/// /// [module-level documentation]: self #[cfg(c_bindings)] +#[derive(Clone)] pub struct OfferWithDerivedMetadataBuilder<'a> { offer: OfferContents, metadata_strategy: core::marker::PhantomData, @@ -582,7 +580,7 @@ macro_rules! offer_accessors { ($self: ident, $contents: expr) => { } /// The minimum amount required for a successful payment of a single item. - pub fn amount(&$self) -> Option<&$crate::offers::offer::Amount> { + pub fn amount(&$self) -> Option<$crate::offers::offer::Amount> { $contents.amount() } @@ -808,8 +806,8 @@ impl OfferContents { self.metadata.as_ref().and_then(|metadata| metadata.as_bytes()) } - pub fn amount(&self) -> Option<&Amount> { - self.amount.as_ref() + pub fn amount(&self) -> Option { + self.amount } pub fn description(&self) -> Option { @@ -982,7 +980,7 @@ impl Writeable for OfferContents { /// The minimum amount required for an item in an [`Offer`], denominated in either bitcoin or /// another currency. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum Amount { /// An amount of bitcoin. Bitcoin { @@ -1381,7 +1379,7 @@ mod tests { .build() .unwrap(); let tlv_stream = offer.as_tlv_stream(); - assert_eq!(offer.amount(), Some(&bitcoin_amount)); + assert_eq!(offer.amount(), Some(bitcoin_amount)); assert_eq!(tlv_stream.amount, Some(1000)); assert_eq!(tlv_stream.currency, None); diff --git a/lightning/src/offers/refund.rs b/lightning/src/offers/refund.rs index 6a1d24106e9..1988a92aaa7 100644 --- a/lightning/src/offers/refund.rs +++ b/lightning/src/offers/refund.rs @@ -141,6 +141,7 @@ pub struct RefundBuilder<'a, T: secp256k1::Signing> { /// /// [module-level documentation]: self #[cfg(c_bindings)] +#[derive(Clone)] pub struct RefundMaybeWithDerivedMetadataBuilder<'a> { refund: RefundContents, secp_ctx: Option<&'a Secp256k1>, diff --git a/lightning/src/util/sweep.rs b/lightning/src/util/sweep.rs index 5135549689c..dd26a8ef844 100644 --- a/lightning/src/util/sweep.rs +++ b/lightning/src/util/sweep.rs @@ -14,7 +14,7 @@ use crate::chain::{self, BestBlock, Confirm, Filter, Listen, WatchedOutput}; use crate::io; use crate::ln::msgs::DecodeError; use crate::ln::types::ChannelId; -use crate::prelude::Vec; +use crate::prelude::*; use crate::sign::{ChangeDestinationSource, OutputSpender, SpendableOutputDescriptor}; use crate::sync::Mutex; use crate::util::logger::Logger;