@@ -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 ) ]
@@ -1257,7 +1287,7 @@ pub enum Event {
1257
1287
/// The channel_id of the channel which has been closed.
1258
1288
channel_id : ChannelId ,
1259
1289
/// The full transaction received from the user
1260
- transaction : Transaction
1290
+ funding_info : FundingInfo ,
1261
1291
} ,
1262
1292
/// Indicates a request to open a new channel by a peer.
1263
1293
///
@@ -1541,11 +1571,18 @@ impl Writeable for Event {
1541
1571
( 9 , channel_funding_txo, option) ,
1542
1572
} ) ;
1543
1573
} ,
1544
- & Event :: DiscardFunding { ref channel_id, ref transaction } => {
1574
+ & Event :: DiscardFunding { ref channel_id, ref funding_info } => {
1545
1575
11u8 . write ( writer) ?;
1576
+
1577
+ let transaction = if let FundingInfo :: Tx { transaction } = funding_info {
1578
+ Some ( transaction)
1579
+ } else {
1580
+ None
1581
+ } ;
1546
1582
write_tlv_fields ! ( writer, {
1547
1583
( 0 , channel_id, required) ,
1548
- ( 2 , transaction, required)
1584
+ ( 2 , transaction, option) ,
1585
+ ( 4 , funding_info, required) ,
1549
1586
} )
1550
1587
} ,
1551
1588
& Event :: PaymentPathSuccessful { ref payment_id, ref payment_hash, ref path } => {
@@ -1924,12 +1961,20 @@ impl MaybeReadable for Event {
1924
1961
11u8 => {
1925
1962
let mut f = || {
1926
1963
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 ( ) } ;
1964
+ let mut transaction: Option < Transaction > = None ;
1965
+ let mut funding_info: Option < FundingInfo > = None ;
1928
1966
read_tlv_fields ! ( reader, {
1929
1967
( 0 , channel_id, required) ,
1930
- ( 2 , transaction, required) ,
1968
+ ( 2 , transaction, option) ,
1969
+ ( 4 , funding_info, option) ,
1931
1970
} ) ;
1932
- Ok ( Some ( Event :: DiscardFunding { channel_id, transaction } ) )
1971
+
1972
+ let funding_info = if let Some ( tx) = transaction {
1973
+ FundingInfo :: Tx { transaction : tx }
1974
+ } else {
1975
+ funding_info. ok_or ( msgs:: DecodeError :: InvalidValue ) ?
1976
+ } ;
1977
+ Ok ( Some ( Event :: DiscardFunding { channel_id, funding_info } ) )
1933
1978
} ;
1934
1979
f ( )
1935
1980
} ,
0 commit comments