@@ -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,37 @@ 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
+ ///
57
+ /// [`ChannelManager::unsafe_manual_funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::unsafe_manual_funding_transaction_generated
58
+ #[ derive( Debug , PartialEq , Eq , Clone ) ]
59
+ pub enum FundingInfo {
60
+ /// The full funding `Transaction`.
61
+ Tx {
62
+ /// The funding transaction
63
+ transaction : Transaction
64
+ } ,
65
+ /// The `OutPoint` of the funding.
66
+ OutPoint {
67
+ /// The outpoint of the funding
68
+ outpoint : transaction:: OutPoint
69
+ } ,
70
+ }
71
+
72
+ impl_writeable_tlv_based_enum ! ( FundingInfo ,
73
+ ( 0 , Tx ) => {
74
+ ( 0 , transaction, required)
75
+ } ,
76
+ ( 1 , OutPoint ) => {
77
+ ( 1 , outpoint, required)
78
+ }
79
+ ) ;
80
+
81
+
53
82
/// Some information provided on receipt of payment depends on whether the payment received is a
54
83
/// spontaneous payment or a "conventional" lightning payment that's paying an invoice.
55
84
#[ derive( Clone , Debug , PartialEq , Eq ) ]
@@ -1257,7 +1286,7 @@ pub enum Event {
1257
1286
/// The channel_id of the channel which has been closed.
1258
1287
channel_id : ChannelId ,
1259
1288
/// The full transaction received from the user
1260
- transaction : Transaction
1289
+ funding_info : FundingInfo ,
1261
1290
} ,
1262
1291
/// Indicates a request to open a new channel by a peer.
1263
1292
///
@@ -1541,11 +1570,18 @@ impl Writeable for Event {
1541
1570
( 9 , channel_funding_txo, option) ,
1542
1571
} ) ;
1543
1572
} ,
1544
- & Event :: DiscardFunding { ref channel_id, ref transaction } => {
1573
+ & Event :: DiscardFunding { ref channel_id, ref funding_info } => {
1545
1574
11u8 . write ( writer) ?;
1575
+
1576
+ let transaction = if let FundingInfo :: Tx { transaction } = funding_info {
1577
+ Some ( transaction)
1578
+ } else {
1579
+ None
1580
+ } ;
1546
1581
write_tlv_fields ! ( writer, {
1547
1582
( 0 , channel_id, required) ,
1548
- ( 2 , transaction, required)
1583
+ ( 2 , transaction, option) ,
1584
+ ( 4 , funding_info, required) ,
1549
1585
} )
1550
1586
} ,
1551
1587
& Event :: PaymentPathSuccessful { ref payment_id, ref payment_hash, ref path } => {
@@ -1924,12 +1960,20 @@ impl MaybeReadable for Event {
1924
1960
11u8 => {
1925
1961
let mut f = || {
1926
1962
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 ( ) } ;
1963
+ let mut transaction: Option < Transaction > = None ;
1964
+ let mut funding_info: Option < FundingInfo > = None ;
1928
1965
read_tlv_fields ! ( reader, {
1929
1966
( 0 , channel_id, required) ,
1930
- ( 2 , transaction, required) ,
1967
+ ( 2 , transaction, option) ,
1968
+ ( 4 , funding_info, option) ,
1931
1969
} ) ;
1932
- Ok ( Some ( Event :: DiscardFunding { channel_id, transaction } ) )
1970
+
1971
+ let funding_info = if let Some ( tx) = transaction {
1972
+ FundingInfo :: Tx { transaction : tx }
1973
+ } else {
1974
+ funding_info. ok_or ( msgs:: DecodeError :: InvalidValue ) ?
1975
+ } ;
1976
+ Ok ( Some ( Event :: DiscardFunding { channel_id, funding_info } ) )
1933
1977
} ;
1934
1978
f ( )
1935
1979
} ,
0 commit comments