@@ -36,12 +36,10 @@ use crate::util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReada
3636use crate :: util:: string:: UntrustedString ;
3737
3838use bitcoin:: { Transaction , OutPoint } ;
39- use bitcoin:: locktime:: absolute:: LockTime ;
4039use bitcoin:: script:: ScriptBuf ;
4140use bitcoin:: hashes:: Hash ;
4241use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
4342use bitcoin:: secp256k1:: PublicKey ;
44- use bitcoin:: transaction:: Version ;
4543use crate :: io;
4644use core:: time:: Duration ;
4745use core:: ops:: Deref ;
@@ -50,6 +48,38 @@ use crate::sync::Arc;
5048#[ allow( unused_imports) ]
5149use crate :: prelude:: * ;
5250
51+ /// `FundingInfo` holds information about a channel's funding transaction.
52+ ///
53+ /// When LDK is set to manual propagation of the funding transaction
54+ /// (via [`ChannelManager::unsafe_manual_funding_transaction_generated`),
55+ /// LDK does not have the full transaction data. Instead, the `OutPoint`
56+ /// for the funding is provided here.
57+ ///
58+ /// [`ChannelManager::unsafe_manual_funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::unsafe_manual_funding_transaction_generated
59+ #[ derive( Debug , PartialEq , Eq , Clone ) ]
60+ pub enum FundingInfo {
61+ /// The full funding `Transaction`.
62+ Tx {
63+ /// The funding transaction
64+ transaction : Transaction
65+ } ,
66+ /// The `OutPoint` of the funding.
67+ OutPoint {
68+ /// The outpoint of the funding
69+ outpoint : transaction:: OutPoint
70+ } ,
71+ }
72+
73+ impl_writeable_tlv_based_enum ! ( FundingInfo ,
74+ ( 0 , Tx ) => {
75+ ( 0 , transaction, required)
76+ } ,
77+ ( 1 , OutPoint ) => {
78+ ( 1 , outpoint, required)
79+ }
80+ ) ;
81+
82+
5383/// Some information provided on receipt of payment depends on whether the payment received is a
5484/// spontaneous payment or a "conventional" lightning payment that's paying an invoice.
5585#[ derive( Clone , Debug , PartialEq , Eq ) ]
@@ -1258,7 +1288,7 @@ pub enum Event {
12581288 /// The channel_id of the channel which has been closed.
12591289 channel_id : ChannelId ,
12601290 /// The full transaction received from the user
1261- transaction : Transaction
1291+ funding_info : FundingInfo ,
12621292 } ,
12631293 /// Indicates a request to open a new channel by a peer.
12641294 ///
@@ -1542,11 +1572,18 @@ impl Writeable for Event {
15421572 ( 9 , channel_funding_txo, option) ,
15431573 } ) ;
15441574 } ,
1545- & Event :: DiscardFunding { ref channel_id, ref transaction } => {
1575+ & Event :: DiscardFunding { ref channel_id, ref funding_info } => {
15461576 11u8 . write ( writer) ?;
1577+
1578+ let transaction = if let FundingInfo :: Tx { transaction } = funding_info {
1579+ Some ( transaction)
1580+ } else {
1581+ None
1582+ } ;
15471583 write_tlv_fields ! ( writer, {
15481584 ( 0 , channel_id, required) ,
1549- ( 2 , transaction, required)
1585+ ( 2 , transaction, option) ,
1586+ ( 4 , funding_info, required) ,
15501587 } )
15511588 } ,
15521589 & Event :: PaymentPathSuccessful { ref payment_id, ref payment_hash, ref path } => {
@@ -1925,12 +1962,20 @@ impl MaybeReadable for Event {
19251962 11u8 => {
19261963 let mut f = || {
19271964 let mut channel_id = ChannelId :: new_zero ( ) ;
1928- let mut transaction = Transaction { version : Version :: TWO , lock_time : LockTime :: ZERO , input : Vec :: new ( ) , output : Vec :: new ( ) } ;
1965+ let mut transaction: Option < Transaction > = None ;
1966+ let mut funding_info: Option < FundingInfo > = None ;
19291967 read_tlv_fields ! ( reader, {
19301968 ( 0 , channel_id, required) ,
1931- ( 2 , transaction, required) ,
1969+ ( 2 , transaction, option) ,
1970+ ( 4 , funding_info, option) ,
19321971 } ) ;
1933- Ok ( Some ( Event :: DiscardFunding { channel_id, transaction } ) )
1972+
1973+ let funding_info = if let Some ( tx) = transaction {
1974+ FundingInfo :: Tx { transaction : tx }
1975+ } else {
1976+ funding_info. ok_or ( msgs:: DecodeError :: InvalidValue ) ?
1977+ } ;
1978+ Ok ( Some ( Event :: DiscardFunding { channel_id, funding_info } ) )
19341979 } ;
19351980 f ( )
19361981 } ,
0 commit comments