Skip to content

Commit

Permalink
f - UnsignedBolt12Invoice impl for c_bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
jkczyz committed Mar 1, 2024
1 parent 7727292 commit d4363d4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9299,7 +9299,9 @@ where
builder.map(|b| b.into());
let response = builder.and_then(|builder| builder.allow_mpp().build())
.map_err(|e| OffersMessage::InvoiceError(e.into()))
.and_then(|invoice|
.and_then(|invoice| {
#[cfg(c_bindings)]
let mut invoice = invoice;
match invoice.sign(|invoice| self.node_signer.sign_bolt12_invoice(invoice)) {
Ok(invoice) => Ok(OffersMessage::Invoice(invoice)),
Err(SignError::Signing(())) => Err(OffersMessage::InvoiceError(
Expand All @@ -9308,7 +9310,8 @@ where
Err(SignError::Verification(_)) => Err(OffersMessage::InvoiceError(
InvoiceError::from_string("Failed invoice signature verification".to_string())
)),
});
}
});
match response {
Ok(invoice) => Some(invoice),
Err(error) => Some(error),
Expand Down
19 changes: 18 additions & 1 deletion lightning/src/offers/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ macro_rules! invoice_derived_signing_pubkey_builder_methods { (
#[cfg(not(c_bindings))]
let unsigned_invoice = UnsignedBolt12Invoice::new(invreq_bytes, invoice);
#[cfg(c_bindings)]
let unsigned_invoice = UnsignedBolt12Invoice::new(invreq_bytes, invoice.clone());
let mut unsigned_invoice = UnsignedBolt12Invoice::new(invreq_bytes, invoice.clone());

let invoice = unsigned_invoice
.sign::<_, Infallible>(
Expand Down Expand Up @@ -547,18 +547,33 @@ macro_rules! unsigned_invoice_sign_method { ($self: ident, $self_type: ty $(, $s
signature_tlv_stream.write(&mut $self.bytes).unwrap();

Ok(Bolt12Invoice {
#[cfg(not(c_bindings))]
bytes: $self.bytes,
#[cfg(c_bindings)]
bytes: $self.bytes.clone(),
#[cfg(not(c_bindings))]
contents: $self.contents,
#[cfg(c_bindings)]
contents: $self.contents.clone(),
signature,
#[cfg(not(c_bindings))]
tagged_hash: $self.tagged_hash,
#[cfg(c_bindings)]
tagged_hash: $self.tagged_hash.clone(),
})
}
} }

#[cfg(not(c_bindings))]
impl UnsignedBolt12Invoice {
unsigned_invoice_sign_method!(self, Self, mut);
}

#[cfg(c_bindings)]
impl UnsignedBolt12Invoice {
unsigned_invoice_sign_method!(self, &mut Self);
}

impl AsRef<TaggedHash> for UnsignedBolt12Invoice {
fn as_ref(&self) -> &TaggedHash {
&self.tagged_hash
Expand Down Expand Up @@ -1508,6 +1523,8 @@ mod tests {
},
}

#[cfg(c_bindings)]
let mut unsigned_invoice = unsigned_invoice;
let invoice = unsigned_invoice.sign(recipient_sign).unwrap();

let mut buffer = Vec::new();
Expand Down

0 comments on commit d4363d4

Please sign in to comment.