X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fevents%2Fmod.rs;h=887851864c97e84f62a7502673cd37e2259d316a;hb=642913c586fc71b0e413532e7dedcd19cfd4815c;hp=527aabb0776e99f14a97cf09d53b623c27b224ad;hpb=b8cdde8af64189fd1567cbc85cfae26c610af969;p=rust-lightning diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index 527aabb0..88785186 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -19,18 +19,20 @@ pub mod bump_transaction; pub use bump_transaction::BumpTransactionEvent; use crate::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, PaymentContext, PaymentContextRef}; -use crate::sign::SpendableOutputDescriptor; +use crate::chain::transaction; use crate::ln::channelmanager::{InterceptId, PaymentId, RecipientOnionFields}; use crate::ln::channel::FUNDING_CONF_DEADLINE_BLOCKS; use crate::ln::features::ChannelTypeFeatures; use crate::ln::msgs; use crate::ln::types::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret}; -use crate::chain::transaction; +use crate::offers::invoice::Bolt12Invoice; +use crate::onion_message::messenger::Responder; use crate::routing::gossip::NetworkUpdate; +use crate::routing::router::{BlindedTail, Path, RouteHop, RouteParameters}; +use crate::sign::SpendableOutputDescriptor; use crate::util::errors::APIError; use crate::util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReadable, Readable, RequiredWrapper, UpgradableRequired, WithoutLength}; use crate::util::string::UntrustedString; -use crate::routing::router::{BlindedTail, Path, RouteHop, RouteParameters}; use bitcoin::{Transaction, OutPoint}; use bitcoin::blockdata::locktime::absolute::LockTime; @@ -372,7 +374,7 @@ impl core::fmt::Display for ClosureReason { ClosureReason::HolderForceClosed { broadcasted_latest_txn } => { f.write_str("user force-closed the channel")?; if let Some(brodcasted) = broadcasted_latest_txn { - write!(f, " and {} the latest transaction", if *brodcasted { "broadcasted" } else { "did not broadcast" }) + write!(f, " and {} the latest transaction", if *brodcasted { "broadcasted" } else { "elected not to broadcast" }) } else { Ok(()) } @@ -736,6 +738,31 @@ pub enum Event { /// The `payment_id` to have been associated with payment for the requested invoice. payment_id: PaymentId, }, + /// Indicates a [`Bolt12Invoice`] in response to an [`InvoiceRequest`] or a [`Refund`] was + /// received. + /// + /// This event will only be generated if [`UserConfig::manually_handle_bolt12_invoices`] is set. + /// Use [`ChannelManager::send_payment_for_bolt12_invoice`] to pay the invoice or + /// [`ChannelManager::abandon_payment`] to abandon the associated payment. See those docs for + /// further details. + /// + /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest + /// [`Refund`]: crate::offers::refund::Refund + /// [`UserConfig::manually_handle_bolt12_invoices`]: crate::util::config::UserConfig::manually_handle_bolt12_invoices + /// [`ChannelManager::send_payment_for_bolt12_invoice`]: crate::ln::channelmanager::ChannelManager::send_payment_for_bolt12_invoice + /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment + InvoiceReceived { + /// The `payment_id` associated with payment for the invoice. + payment_id: PaymentId, + /// The invoice to pay. + invoice: Bolt12Invoice, + /// A responder for replying with an [`InvoiceError`] if needed. + /// + /// `None` if the invoice wasn't sent with a reply path. + /// + /// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError + responder: Option, + }, /// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target /// and we got back the payment preimage for it). /// @@ -762,6 +789,8 @@ pub enum Event { /// If the recipient or an intermediate node misbehaves and gives us free money, this may /// overstate the amount paid, though this is unlikely. /// + /// This is only `None` for payments initiated on LDK versions prior to 0.0.103. + /// /// [`Route::get_total_fees`]: crate::routing::router::Route::get_total_fees fee_paid_msat: Option, }, @@ -1492,7 +1521,15 @@ impl Writeable for Event { write_tlv_fields!(writer, { (0, peer_node_id, required), }); - } + }, + &Event::InvoiceReceived { ref payment_id, ref invoice, ref responder } => { + 41u8.write(writer)?; + write_tlv_fields!(writer, { + (0, payment_id, required), + (2, invoice, required), + (4, responder, option), + }) + }, // Note that, going forward, all new events must only write data inside of // `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write // data via `write_tlv_fields`. @@ -1929,6 +1966,21 @@ impl MaybeReadable for Event { }; f() }, + 41u8 => { + let mut f = || { + _init_and_read_len_prefixed_tlv_fields!(reader, { + (0, payment_id, required), + (2, invoice, required), + (4, responder, option), + }); + Ok(Some(Event::InvoiceReceived { + payment_id: payment_id.0.unwrap(), + invoice: invoice.0.unwrap(), + responder, + })) + }; + f() + }, // Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue. // Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt // reads.