Skip to content

Commit

Permalink
f Account for Invoice being renamed to Bolt11Invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed Aug 2, 2023
1 parent e233c3e commit 5954700
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ interface LDKNode {
[Throws=NodeError]
void sync_wallets();
[Throws=NodeError]
PaymentHash send_payment([ByRef]Invoice invoice);
PaymentHash send_payment([ByRef]Bolt11Invoice invoice);
[Throws=NodeError]
PaymentHash send_payment_using_amount([ByRef]Invoice invoice, u64 amount_msat);
PaymentHash send_payment_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat);
[Throws=NodeError]
PaymentHash send_spontaneous_payment(u64 amount_msat, PublicKey node_id);
[Throws=NodeError]
Invoice receive_payment(u64 amount_msat, [ByRef]string description, u32 expiry_secs);
Bolt11Invoice receive_payment(u64 amount_msat, [ByRef]string description, u32 expiry_secs);
[Throws=NodeError]
Invoice receive_variable_amount_payment([ByRef]string description, u32 expiry_secs);
Bolt11Invoice receive_variable_amount_payment([ByRef]string description, u32 expiry_secs);
PaymentDetails? payment([ByRef]PaymentHash payment_hash);
[Throws=NodeError]
boolean remove_payment([ByRef]PaymentHash payment_hash);
Expand Down Expand Up @@ -230,7 +230,7 @@ typedef string PublicKey;
typedef string Address;

[Custom]
typedef string Invoice;
typedef string Bolt11Invoice;

[Custom]
typedef string PaymentHash;
Expand Down
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//!
//! ```no_run
//! use ldk_node::{Builder, NetAddress};
//! use ldk_node::lightning_invoice::Invoice;
//! use ldk_node::lightning_invoice::Bolt11Invoice;
//! use ldk_node::bitcoin::secp256k1::PublicKey;
//! use ldk_node::bitcoin::Network;
//! use std::str::FromStr;
Expand All @@ -54,7 +54,7 @@
//! println!("EVENT: {:?}", event);
//! node.event_handled();
//!
//! let invoice = Invoice::from_str("INVOICE_STR").unwrap();
//! let invoice = Bolt11Invoice::from_str("INVOICE_STR").unwrap();
//! node.send_payment(&invoice).unwrap();
//!
//! node.stop().unwrap();
Expand Down Expand Up @@ -137,7 +137,7 @@ use lightning_background_processor::process_events_async;
use lightning_transaction_sync::EsploraSyncClient;

use lightning::routing::router::{PaymentParameters, RouteParameters};
use lightning_invoice::{payment, Currency, Invoice};
use lightning_invoice::{payment, Bolt11Invoice, Currency};

use bitcoin::hashes::sha256::Hash as Sha256;
use bitcoin::hashes::Hash;
Expand Down Expand Up @@ -1036,7 +1036,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
}

/// Send a payement given an invoice.
pub fn send_payment(&self, invoice: &Invoice) -> Result<PaymentHash, Error> {
pub fn send_payment(&self, invoice: &Bolt11Invoice) -> Result<PaymentHash, Error> {
let rt_lock = self.runtime.read().unwrap();
if rt_lock.is_none() {
return Err(Error::NotRunning);
Expand Down Expand Up @@ -1112,7 +1112,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
/// This can be used to pay a so-called "zero-amount" invoice, i.e., an invoice that leaves the
/// amount paid to be determined by the user.
pub fn send_payment_using_amount(
&self, invoice: &Invoice, amount_msat: u64,
&self, invoice: &Bolt11Invoice, amount_msat: u64,
) -> Result<PaymentHash, Error> {
let rt_lock = self.runtime.read().unwrap();
if rt_lock.is_none() {
Expand Down Expand Up @@ -1294,21 +1294,21 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
/// given.
pub fn receive_payment(
&self, amount_msat: u64, description: &str, expiry_secs: u32,
) -> Result<Invoice, Error> {
) -> Result<Bolt11Invoice, Error> {
self.receive_payment_inner(Some(amount_msat), description, expiry_secs)
}

/// Returns a payable invoice that can be used to request and receive a payment for which the
/// amount is to be determined by the user, also known as a "zero-amount" invoice.
pub fn receive_variable_amount_payment(
&self, description: &str, expiry_secs: u32,
) -> Result<Invoice, Error> {
) -> Result<Bolt11Invoice, Error> {
self.receive_payment_inner(None, description, expiry_secs)
}

fn receive_payment_inner(
&self, amount_msat: Option<u64>, description: &str, expiry_secs: u32,
) -> Result<Invoice, Error> {
) -> Result<Bolt11Invoice, Error> {
let currency = Currency::from(self.config.network);
let keys_manager = Arc::clone(&self.keys_manager);
let invoice = match lightning_invoice::utils::create_invoice_from_channelmanager(
Expand Down
8 changes: 4 additions & 4 deletions src/uniffi_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use bitcoin::hashes::Hash;
use bitcoin::secp256k1::PublicKey;
use bitcoin::{Address, Txid};
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
use lightning_invoice::{Invoice, SignedRawInvoice};
use lightning_invoice::{Bolt11Invoice, SignedRawBolt11Invoice};

use bip39::Mnemonic;

Expand Down Expand Up @@ -53,12 +53,12 @@ impl UniffiCustomTypeConverter for Address {
}
}

impl UniffiCustomTypeConverter for Invoice {
impl UniffiCustomTypeConverter for Bolt11Invoice {
type Builtin = String;

fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
if let Ok(signed) = val.parse::<SignedRawInvoice>() {
if let Ok(invoice) = Invoice::from_signed(signed) {
if let Ok(signed) = val.parse::<SignedRawBolt11Invoice>() {
if let Ok(invoice) = Bolt11Invoice::from_signed(signed) {
return Ok(invoice);
}
}
Expand Down

0 comments on commit 5954700

Please sign in to comment.