@@ -36,12 +36,10 @@ use crate::util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReada
36
36
use crate :: util:: string:: UntrustedString ;
37
37
38
38
use bitcoin:: { Transaction , OutPoint } ;
39
- use bitcoin:: locktime:: absolute:: LockTime ;
40
39
use bitcoin:: script:: ScriptBuf ;
41
40
use bitcoin:: hashes:: Hash ;
42
41
use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
43
42
use bitcoin:: secp256k1:: PublicKey ;
44
- use bitcoin:: transaction:: Version ;
45
43
use crate :: io;
46
44
use core:: time:: Duration ;
47
45
use core:: ops:: Deref ;
@@ -50,6 +48,35 @@ use crate::sync::Arc;
50
48
#[ allow( unused_imports) ]
51
49
use crate :: prelude:: * ;
52
50
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
+
53
80
/// Some information provided on receipt of payment depends on whether the payment received is a
54
81
/// spontaneous payment or a "conventional" lightning payment that's paying an invoice.
55
82
#[ derive( Clone , Debug , PartialEq , Eq ) ]
@@ -1257,7 +1284,7 @@ pub enum Event {
1257
1284
/// The channel_id of the channel which has been closed.
1258
1285
channel_id : ChannelId ,
1259
1286
/// The full transaction received from the user
1260
- transaction : Transaction
1287
+ funding_info : FundingInfo ,
1261
1288
} ,
1262
1289
/// Indicates a request to open a new channel by a peer.
1263
1290
///
@@ -1541,11 +1568,18 @@ impl Writeable for Event {
1541
1568
( 9 , channel_funding_txo, option) ,
1542
1569
} ) ;
1543
1570
} ,
1544
- & Event :: DiscardFunding { ref channel_id, ref transaction } => {
1571
+ & Event :: DiscardFunding { ref channel_id, ref funding_info } => {
1545
1572
11u8 . write ( writer) ?;
1573
+
1574
+ let transaction = if let FundingInfo :: Tx { transaction } = funding_info {
1575
+ Some ( transaction)
1576
+ } else {
1577
+ None
1578
+ } ;
1546
1579
write_tlv_fields ! ( writer, {
1547
1580
( 0 , channel_id, required) ,
1548
- ( 2 , transaction, required)
1581
+ ( 2 , transaction, option) ,
1582
+ ( 4 , funding_info, required) ,
1549
1583
} )
1550
1584
} ,
1551
1585
& Event :: PaymentPathSuccessful { ref payment_id, ref payment_hash, ref path } => {
@@ -1924,12 +1958,20 @@ impl MaybeReadable for Event {
1924
1958
11u8 => {
1925
1959
let mut f = || {
1926
1960
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 ;
1928
1963
read_tlv_fields ! ( reader, {
1929
1964
( 0 , channel_id, required) ,
1930
- ( 2 , transaction, required) ,
1965
+ ( 2 , transaction, option) ,
1966
+ ( 4 , funding_info, option) ,
1931
1967
} ) ;
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 } ) )
1933
1975
} ;
1934
1976
f ( )
1935
1977
} ,
0 commit comments