@@ -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,38 @@ 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 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
+
53
83
/// Some information provided on receipt of payment depends on whether the payment received is a
54
84
/// spontaneous payment or a "conventional" lightning payment that's paying an invoice.
55
85
#[ derive( Clone , Debug , PartialEq , Eq ) ]
@@ -1258,7 +1288,7 @@ pub enum Event {
1258
1288
/// The channel_id of the channel which has been closed.
1259
1289
channel_id : ChannelId ,
1260
1290
/// The full transaction received from the user
1261
- transaction : Transaction
1291
+ funding_info : FundingInfo ,
1262
1292
} ,
1263
1293
/// Indicates a request to open a new channel by a peer.
1264
1294
///
@@ -1542,11 +1572,18 @@ impl Writeable for Event {
1542
1572
( 9 , channel_funding_txo, option) ,
1543
1573
} ) ;
1544
1574
} ,
1545
- & Event :: DiscardFunding { ref channel_id, ref transaction } => {
1575
+ & Event :: DiscardFunding { ref channel_id, ref funding_info } => {
1546
1576
11u8 . write ( writer) ?;
1577
+
1578
+ let transaction = if let FundingInfo :: Tx { transaction } = funding_info {
1579
+ Some ( transaction)
1580
+ } else {
1581
+ None
1582
+ } ;
1547
1583
write_tlv_fields ! ( writer, {
1548
1584
( 0 , channel_id, required) ,
1549
- ( 2 , transaction, required)
1585
+ ( 2 , transaction, option) ,
1586
+ ( 4 , funding_info, required) ,
1550
1587
} )
1551
1588
} ,
1552
1589
& Event :: PaymentPathSuccessful { ref payment_id, ref payment_hash, ref path } => {
@@ -1925,12 +1962,20 @@ impl MaybeReadable for Event {
1925
1962
11u8 => {
1926
1963
let mut f = || {
1927
1964
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 ;
1929
1967
read_tlv_fields ! ( reader, {
1930
1968
( 0 , channel_id, required) ,
1931
- ( 2 , transaction, required) ,
1969
+ ( 2 , transaction, option) ,
1970
+ ( 4 , funding_info, option) ,
1932
1971
} ) ;
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 } ) )
1934
1979
} ;
1935
1980
f ( )
1936
1981
} ,
0 commit comments