@@ -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,35 @@ 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 tx, the funding transaction info
54+ /// inside the channel struct has a dummy value (See [`ChannelManager::unsafe_manual_funding_transaction_generated`]).
55+ /// In such cases, `FundingInfo` contains the `OutPoint` of the channel.
56+ #[ derive( Debug , PartialEq , Eq , Clone ) ]
57+ pub enum FundingInfo {
58+ /// The full funding `Transaction`.
59+ Tx {
60+ /// The funding transaction
61+ transaction : Transaction
62+ } ,
63+ /// The `OutPoint` of the funding.
64+ OutPoint {
65+ /// The outpoint of the funding
66+ outpoint : transaction:: OutPoint
67+ } ,
68+ }
69+
70+ impl_writeable_tlv_based_enum ! ( FundingInfo ,
71+ ( 0 , Tx ) => {
72+ ( 0 , transaction, required)
73+ } ,
74+ ( 1 , OutPoint ) => {
75+ ( 1 , outpoint, required)
76+ }
77+ ) ;
78+
79+
5380/// Some information provided on receipt of payment depends on whether the payment received is a
5481/// spontaneous payment or a "conventional" lightning payment that's paying an invoice.
5582#[ derive( Clone , Debug , PartialEq , Eq ) ]
@@ -1257,7 +1284,7 @@ pub enum Event {
12571284 /// The channel_id of the channel which has been closed.
12581285 channel_id : ChannelId ,
12591286 /// The full transaction received from the user
1260- transaction : Transaction
1287+ funding_info : FundingInfo ,
12611288 } ,
12621289 /// Indicates a request to open a new channel by a peer.
12631290 ///
@@ -1541,11 +1568,18 @@ impl Writeable for Event {
15411568 ( 9 , channel_funding_txo, option) ,
15421569 } ) ;
15431570 } ,
1544- & Event :: DiscardFunding { ref channel_id, ref transaction } => {
1571+ & Event :: DiscardFunding { ref channel_id, ref funding_info } => {
15451572 11u8 . write ( writer) ?;
1573+
1574+ let transaction = if let FundingInfo :: Tx { transaction } = funding_info {
1575+ Some ( transaction)
1576+ } else {
1577+ None
1578+ } ;
15461579 write_tlv_fields ! ( writer, {
15471580 ( 0 , channel_id, required) ,
1548- ( 2 , transaction, required)
1581+ ( 2 , transaction, option) ,
1582+ ( 4 , funding_info, required) ,
15491583 } )
15501584 } ,
15511585 & Event :: PaymentPathSuccessful { ref payment_id, ref payment_hash, ref path } => {
@@ -1924,12 +1958,20 @@ impl MaybeReadable for Event {
19241958 11u8 => {
19251959 let mut f = || {
19261960 let mut channel_id = ChannelId :: new_zero ( ) ;
1927- let mut transaction = Transaction { version : Version :: TWO , lock_time : LockTime :: ZERO , input : Vec :: new ( ) , output : Vec :: new ( ) } ;
1961+ let mut transaction: Option < Transaction > = None ;
1962+ let mut funding_info: Option < FundingInfo > = None ;
19281963 read_tlv_fields ! ( reader, {
19291964 ( 0 , channel_id, required) ,
1930- ( 2 , transaction, required) ,
1965+ ( 2 , transaction, option) ,
1966+ ( 4 , funding_info, option) ,
19311967 } ) ;
1932- Ok ( Some ( Event :: DiscardFunding { channel_id, transaction } ) )
1968+
1969+ let funding_info = if let Some ( tx) = transaction {
1970+ FundingInfo :: Tx { transaction : tx }
1971+ } else {
1972+ funding_info. ok_or ( msgs:: DecodeError :: InvalidValue ) ?
1973+ } ;
1974+ Ok ( Some ( Event :: DiscardFunding { channel_id, funding_info } ) )
19331975 } ;
19341976 f ( )
19351977 } ,
0 commit comments