Skip to content

Commit

Permalink
Merge pull request #3061 from TheBlueMatt/2024-05-bindings-upstream
Browse files Browse the repository at this point in the history
Minor bindings tweaks
  • Loading branch information
valentinewallace committed May 14, 2024
2 parents 1890e80 + e1d0006 commit da7a916
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 35 deletions.
24 changes: 12 additions & 12 deletions lightning/src/blinded_path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ pub struct BlindedHop {

impl BlindedPath {
/// Create a one-hop blinded path for a message.
pub fn one_hop_for_message<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
recipient_node_id: PublicKey, entropy_source: &ES, secp_ctx: &Secp256k1<T>
) -> Result<Self, ()> {
pub fn one_hop_for_message<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
recipient_node_id: PublicKey, entropy_source: ES, secp_ctx: &Secp256k1<T>
) -> Result<Self, ()> where ES::Target: EntropySource {
Self::new_for_message(&[recipient_node_id], entropy_source, secp_ctx)
}

Expand All @@ -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<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
node_pks: &[PublicKey], entropy_source: &ES, secp_ctx: &Secp256k1<T>
) -> Result<Self, ()> {
pub fn new_for_message<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
node_pks: &[PublicKey], entropy_source: ES, secp_ctx: &Secp256k1<T>
) -> Result<Self, ()> 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");
Expand All @@ -148,10 +148,10 @@ impl BlindedPath {
}

/// Create a one-hop blinded path for a payment.
pub fn one_hop_for_payment<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
pub fn one_hop_for_payment<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
payee_node_id: PublicKey, payee_tlvs: payment::ReceiveTlvs, min_final_cltv_expiry_delta: u16,
entropy_source: &ES, secp_ctx: &Secp256k1<T>
) -> Result<(BlindedPayInfo, Self), ()> {
entropy_source: ES, secp_ctx: &Secp256k1<T>
) -> 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();
Expand All @@ -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<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
pub fn new_for_payment<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
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<T>
) -> Result<(BlindedPayInfo, Self), ()> {
entropy_source: ES, secp_ctx: &Secp256k1<T>
) -> Result<(BlindedPayInfo, Self), ()> where ES::Target: EntropySource {
let introduction_node = IntroductionNode::NodeId(
intermediate_nodes.first().map_or(payee_node_id, |n| n.node_id)
);
Expand Down
3 changes: 3 additions & 0 deletions lightning/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down
4 changes: 4 additions & 0 deletions lightning/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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<D: ::std::io::Read>(mut d: D) -> Result<Vec<u8>, ::std::io::Error> {
let mut buf = Vec::new();
Expand Down
4 changes: 0 additions & 4 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/onion_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions lightning/src/ln/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
9 changes: 5 additions & 4 deletions lightning/src/offers/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,
contents: InvoiceContents,
Expand Down Expand Up @@ -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<Amount> {
$contents.amount()
}

Expand Down Expand Up @@ -944,7 +945,7 @@ impl InvoiceContents {
}
}

fn amount(&self) -> Option<&Amount> {
fn amount(&self) -> Option<Amount> {
match self {
InvoiceContents::ForOffer { invoice_request, .. } =>
invoice_request.inner.offer.amount(),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/offers/invoice_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,
contents: InvoiceRequestContents,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 7 additions & 9 deletions lightning/src/offers/offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExplicitMetadata>,
Expand All @@ -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<DerivedMetadata>,
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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<Amount> {
self.amount
}

pub fn description(&self) -> Option<PrintableString> {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions lightning/src/offers/refund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<secp256k1::All>>,
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/util/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit da7a916

Please sign in to comment.