Skip to content

Commit da7a916

Browse files
Merge pull request #3061 from TheBlueMatt/2024-05-bindings-upstream
Minor bindings tweaks
2 parents 1890e80 + e1d0006 commit da7a916

File tree

11 files changed

+37
-35
lines changed

11 files changed

+37
-35
lines changed

lightning/src/blinded_path/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ pub struct BlindedHop {
121121

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

@@ -132,9 +132,9 @@ impl BlindedPath {
132132
///
133133
/// Errors if no hops are provided or if `node_pk`(s) are invalid.
134134
// TODO: make all payloads the same size with padding + add dummy hops
135-
pub fn new_for_message<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
136-
node_pks: &[PublicKey], entropy_source: &ES, secp_ctx: &Secp256k1<T>
137-
) -> Result<Self, ()> {
135+
pub fn new_for_message<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
136+
node_pks: &[PublicKey], entropy_source: ES, secp_ctx: &Secp256k1<T>
137+
) -> Result<Self, ()> where ES::Target: EntropySource {
138138
if node_pks.is_empty() { return Err(()) }
139139
let blinding_secret_bytes = entropy_source.get_secure_random_bytes();
140140
let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted");
@@ -148,10 +148,10 @@ impl BlindedPath {
148148
}
149149

150150
/// Create a one-hop blinded path for a payment.
151-
pub fn one_hop_for_payment<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
151+
pub fn one_hop_for_payment<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
152152
payee_node_id: PublicKey, payee_tlvs: payment::ReceiveTlvs, min_final_cltv_expiry_delta: u16,
153-
entropy_source: &ES, secp_ctx: &Secp256k1<T>
154-
) -> Result<(BlindedPayInfo, Self), ()> {
153+
entropy_source: ES, secp_ctx: &Secp256k1<T>
154+
) -> Result<(BlindedPayInfo, Self), ()> where ES::Target: EntropySource {
155155
// This value is not considered in pathfinding for 1-hop blinded paths, because it's intended to
156156
// be in relation to a specific channel.
157157
let htlc_maximum_msat = u64::max_value();
@@ -170,11 +170,11 @@ impl BlindedPath {
170170
///
171171
/// [`ForwardTlvs`]: crate::blinded_path::payment::ForwardTlvs
172172
// TODO: make all payloads the same size with padding + add dummy hops
173-
pub fn new_for_payment<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
173+
pub fn new_for_payment<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
174174
intermediate_nodes: &[payment::ForwardNode], payee_node_id: PublicKey,
175175
payee_tlvs: payment::ReceiveTlvs, htlc_maximum_msat: u64, min_final_cltv_expiry_delta: u16,
176-
entropy_source: &ES, secp_ctx: &Secp256k1<T>
177-
) -> Result<(BlindedPayInfo, Self), ()> {
176+
entropy_source: ES, secp_ctx: &Secp256k1<T>
177+
) -> Result<(BlindedPayInfo, Self), ()> where ES::Target: EntropySource {
178178
let introduction_node = IntroductionNode::NodeId(
179179
intermediate_nodes.first().map_or(payee_node_id, |n| n.node_id)
180180
);

lightning/src/chain/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ impl BestBlock {
5252
}
5353

5454
/// Returns a `BestBlock` as identified by the given block hash and height.
55+
///
56+
/// This is not exported to bindings users directly as the bindings auto-generate an
57+
/// equivalent `new`.
5558
pub fn new(block_hash: BlockHash, height: u32) -> Self {
5659
BestBlock { block_hash, height }
5760
}

lightning/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ pub use core2::io;
9696
#[cfg(not(feature = "std"))]
9797
#[doc(hidden)]
9898
/// IO utilities public only for use by in-crate macros. These should not be used externally
99+
///
100+
/// This is not exported to bindings users as it is not intended for public consumption.
99101
pub mod io_extras {
100102
use core2::io::{self, Read, Write};
101103

@@ -158,6 +160,8 @@ pub mod io_extras {
158160
#[cfg(feature = "std")]
159161
#[doc(hidden)]
160162
/// IO utilities public only for use by in-crate macros. These should not be used externally
163+
///
164+
/// This is not exported to bindings users as it is not intended for public consumption.
161165
mod io_extras {
162166
pub fn read_to_end<D: ::std::io::Read>(mut d: D) -> Result<Vec<u8>, ::std::io::Error> {
163167
let mut buf = Vec::new();

lightning/src/ln/channelmanager.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8563,8 +8563,6 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
85638563
///
85648564
/// Errors if the parameterized [`Router`] is unable to create a blinded path for the offer.
85658565
///
8566-
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
8567-
///
85688566
/// [`Offer`]: crate::offers::offer::Offer
85698567
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
85708568
pub fn create_offer_builder(&$self) -> Result<$builder, Bolt12SemanticError> {
@@ -8627,8 +8625,6 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
86278625
/// - `amount_msats` is invalid, or
86288626
/// - the parameterized [`Router`] is unable to create a blinded path for the refund.
86298627
///
8630-
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
8631-
///
86328628
/// [`Refund`]: crate::offers::refund::Refund
86338629
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
86348630
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths

lightning/src/ln/onion_payment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::prelude::*;
2626
use core::ops::Deref;
2727

2828
/// Invalid inbound onion payment.
29-
#[derive(Debug)]
29+
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
3030
pub struct InboundHTLCErr {
3131
/// BOLT 4 error code.
3232
pub err_code: u16,

lightning/src/ln/types.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ use core::ops::Deref;
3535
/// A _temporary_ ID is generated randomly.
3636
/// (Later revocation-point-based _v2_ is a possibility.)
3737
/// The variety (context) is not stored, it is relevant only at creation.
38-
///
39-
/// This is not exported to bindings users as we just use [u8; 32] directly.
4038
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
4139
pub struct ChannelId(pub [u8; 32]);
4240

lightning/src/offers/invoice.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ for InvoiceBuilder<'a, DerivedSigningPubkey> {
503503
///
504504
/// This is serialized as a TLV stream, which includes TLV records from the originating message. As
505505
/// such, it may include unknown, odd TLV records.
506+
#[derive(Clone)]
506507
pub struct UnsignedBolt12Invoice {
507508
bytes: Vec<u8>,
508509
contents: InvoiceContents,
@@ -697,7 +698,7 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
697698
///
698699
/// [`Offer`]: crate::offers::offer::Offer
699700
/// [`Offer::amount`]: crate::offers::offer::Offer::amount
700-
pub fn amount(&$self) -> Option<&Amount> {
701+
pub fn amount(&$self) -> Option<Amount> {
701702
$contents.amount()
702703
}
703704

@@ -944,7 +945,7 @@ impl InvoiceContents {
944945
}
945946
}
946947

947-
fn amount(&self) -> Option<&Amount> {
948+
fn amount(&self) -> Option<Amount> {
948949
match self {
949950
InvoiceContents::ForOffer { invoice_request, .. } =>
950951
invoice_request.inner.offer.amount(),
@@ -1545,7 +1546,7 @@ mod tests {
15451546
assert_eq!(unsigned_invoice.payer_metadata(), &[1; 32]);
15461547
assert_eq!(unsigned_invoice.offer_chains(), Some(vec![ChainHash::using_genesis_block(Network::Bitcoin)]));
15471548
assert_eq!(unsigned_invoice.metadata(), None);
1548-
assert_eq!(unsigned_invoice.amount(), Some(&Amount::Bitcoin { amount_msats: 1000 }));
1549+
assert_eq!(unsigned_invoice.amount(), Some(Amount::Bitcoin { amount_msats: 1000 }));
15491550
assert_eq!(unsigned_invoice.description(), Some(PrintableString("")));
15501551
assert_eq!(unsigned_invoice.offer_features(), Some(&OfferFeatures::empty()));
15511552
assert_eq!(unsigned_invoice.absolute_expiry(), None);
@@ -1589,7 +1590,7 @@ mod tests {
15891590
assert_eq!(invoice.payer_metadata(), &[1; 32]);
15901591
assert_eq!(invoice.offer_chains(), Some(vec![ChainHash::using_genesis_block(Network::Bitcoin)]));
15911592
assert_eq!(invoice.metadata(), None);
1592-
assert_eq!(invoice.amount(), Some(&Amount::Bitcoin { amount_msats: 1000 }));
1593+
assert_eq!(invoice.amount(), Some(Amount::Bitcoin { amount_msats: 1000 }));
15931594
assert_eq!(invoice.description(), Some(PrintableString("")));
15941595
assert_eq!(invoice.offer_features(), Some(&OfferFeatures::empty()));
15951596
assert_eq!(invoice.absolute_expiry(), None);

lightning/src/offers/invoice_request.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ for InvoiceRequestBuilder<'a, 'b, DerivedPayerId, secp256k1::All> {
487487
///
488488
/// This is serialized as a TLV stream, which includes TLV records from the originating message. As
489489
/// such, it may include unknown, odd TLV records.
490+
#[derive(Clone)]
490491
pub struct UnsignedInvoiceRequest {
491492
bytes: Vec<u8>,
492493
contents: InvoiceRequestContents,
@@ -1247,7 +1248,7 @@ mod tests {
12471248
assert_eq!(unsigned_invoice_request.payer_metadata(), &[1; 32]);
12481249
assert_eq!(unsigned_invoice_request.chains(), vec![ChainHash::using_genesis_block(Network::Bitcoin)]);
12491250
assert_eq!(unsigned_invoice_request.metadata(), None);
1250-
assert_eq!(unsigned_invoice_request.amount(), Some(&Amount::Bitcoin { amount_msats: 1000 }));
1251+
assert_eq!(unsigned_invoice_request.amount(), Some(Amount::Bitcoin { amount_msats: 1000 }));
12511252
assert_eq!(unsigned_invoice_request.description(), Some(PrintableString("")));
12521253
assert_eq!(unsigned_invoice_request.offer_features(), &OfferFeatures::empty());
12531254
assert_eq!(unsigned_invoice_request.absolute_expiry(), None);
@@ -1279,7 +1280,7 @@ mod tests {
12791280
assert_eq!(invoice_request.payer_metadata(), &[1; 32]);
12801281
assert_eq!(invoice_request.chains(), vec![ChainHash::using_genesis_block(Network::Bitcoin)]);
12811282
assert_eq!(invoice_request.metadata(), None);
1282-
assert_eq!(invoice_request.amount(), Some(&Amount::Bitcoin { amount_msats: 1000 }));
1283+
assert_eq!(invoice_request.amount(), Some(Amount::Bitcoin { amount_msats: 1000 }));
12831284
assert_eq!(invoice_request.description(), Some(PrintableString("")));
12841285
assert_eq!(invoice_request.offer_features(), &OfferFeatures::empty());
12851286
assert_eq!(invoice_request.absolute_expiry(), None);

lightning/src/offers/offer.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,9 @@ pub struct OfferBuilder<'a, M: MetadataStrategy, T: secp256k1::Signing> {
163163
///
164164
/// See [module-level documentation] for usage.
165165
///
166-
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
167-
///
168166
/// [module-level documentation]: self
169167
#[cfg(c_bindings)]
168+
#[derive(Clone)]
170169
pub struct OfferWithExplicitMetadataBuilder<'a> {
171170
offer: OfferContents,
172171
metadata_strategy: core::marker::PhantomData<ExplicitMetadata>,
@@ -177,10 +176,9 @@ pub struct OfferWithExplicitMetadataBuilder<'a> {
177176
///
178177
/// See [module-level documentation] for usage.
179178
///
180-
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
181-
///
182179
/// [module-level documentation]: self
183180
#[cfg(c_bindings)]
181+
#[derive(Clone)]
184182
pub struct OfferWithDerivedMetadataBuilder<'a> {
185183
offer: OfferContents,
186184
metadata_strategy: core::marker::PhantomData<DerivedMetadata>,
@@ -582,7 +580,7 @@ macro_rules! offer_accessors { ($self: ident, $contents: expr) => {
582580
}
583581

584582
/// The minimum amount required for a successful payment of a single item.
585-
pub fn amount(&$self) -> Option<&$crate::offers::offer::Amount> {
583+
pub fn amount(&$self) -> Option<$crate::offers::offer::Amount> {
586584
$contents.amount()
587585
}
588586

@@ -808,8 +806,8 @@ impl OfferContents {
808806
self.metadata.as_ref().and_then(|metadata| metadata.as_bytes())
809807
}
810808

811-
pub fn amount(&self) -> Option<&Amount> {
812-
self.amount.as_ref()
809+
pub fn amount(&self) -> Option<Amount> {
810+
self.amount
813811
}
814812

815813
pub fn description(&self) -> Option<PrintableString> {
@@ -982,7 +980,7 @@ impl Writeable for OfferContents {
982980

983981
/// The minimum amount required for an item in an [`Offer`], denominated in either bitcoin or
984982
/// another currency.
985-
#[derive(Clone, Debug, PartialEq)]
983+
#[derive(Clone, Copy, Debug, PartialEq)]
986984
pub enum Amount {
987985
/// An amount of bitcoin.
988986
Bitcoin {
@@ -1381,7 +1379,7 @@ mod tests {
13811379
.build()
13821380
.unwrap();
13831381
let tlv_stream = offer.as_tlv_stream();
1384-
assert_eq!(offer.amount(), Some(&bitcoin_amount));
1382+
assert_eq!(offer.amount(), Some(bitcoin_amount));
13851383
assert_eq!(tlv_stream.amount, Some(1000));
13861384
assert_eq!(tlv_stream.currency, None);
13871385

lightning/src/offers/refund.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ pub struct RefundBuilder<'a, T: secp256k1::Signing> {
141141
///
142142
/// [module-level documentation]: self
143143
#[cfg(c_bindings)]
144+
#[derive(Clone)]
144145
pub struct RefundMaybeWithDerivedMetadataBuilder<'a> {
145146
refund: RefundContents,
146147
secp_ctx: Option<&'a Secp256k1<secp256k1::All>>,

lightning/src/util/sweep.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::chain::{self, BestBlock, Confirm, Filter, Listen, WatchedOutput};
1414
use crate::io;
1515
use crate::ln::msgs::DecodeError;
1616
use crate::ln::types::ChannelId;
17-
use crate::prelude::Vec;
17+
use crate::prelude::*;
1818
use crate::sign::{ChangeDestinationSource, OutputSpender, SpendableOutputDescriptor};
1919
use crate::sync::Mutex;
2020
use crate::util::logger::Logger;

0 commit comments

Comments
 (0)