5
5
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
6
6
// accordance with one or both of these licenses.
7
7
8
- use crate :: sweep:: value_satoshis_from_descriptor ;
8
+ use crate :: sweep:: value_from_descriptor ;
9
9
10
10
use lightning:: chain:: channelmonitor:: Balance as LdkBalance ;
11
- use lightning:: ln:: { ChannelId , PaymentHash , PaymentPreimage } ;
11
+ use lightning:: chain:: channelmonitor:: BalanceSource ;
12
+ use lightning:: ln:: types:: ChannelId ;
13
+ use lightning:: ln:: { PaymentHash , PaymentPreimage } ;
12
14
use lightning:: util:: sweep:: { OutputSpendStatus , TrackedSpendableOutput } ;
13
15
14
16
use bitcoin:: secp256k1:: PublicKey ;
@@ -80,6 +82,49 @@ pub enum LightningBalance {
80
82
/// The amount available to claim, in satoshis, excluding the on-chain fees which will be
81
83
/// required to do so.
82
84
amount_satoshis : u64 ,
85
+ /// The transaction fee we pay for the closing commitment transaction. This amount is not
86
+ /// included in the `amount_satoshis` value.
87
+ ///
88
+ /// Note that if this channel is inbound (and thus our counterparty pays the commitment
89
+ /// transaction fee) this value will be zero. For channels created prior to LDK Node 0.4
90
+ /// the channel is always treated as outbound (and thus this value is never zero).
91
+ transaction_fee_satoshis : u64 ,
92
+ /// The amount of millisatoshis which has been burned to fees from HTLCs which are outbound
93
+ /// from us and are related to a payment which was sent by us. This is the sum of the
94
+ /// millisatoshis part of all HTLCs which are otherwise represented by
95
+ /// [`LightningBalance::MaybeTimeoutClaimableHTLC`] with their
96
+ /// [`LightningBalance::MaybeTimeoutClaimableHTLC::outbound_payment`] flag set, as well as
97
+ /// any dust HTLCs which would otherwise be represented the same.
98
+ ///
99
+ /// This amount (rounded up to a whole satoshi value) will not be included in `amount_satoshis`.
100
+ outbound_payment_htlc_rounded_msat : u64 ,
101
+ /// The amount of millisatoshis which has been burned to fees from HTLCs which are outbound
102
+ /// from us and are related to a forwarded HTLC. This is the sum of the millisatoshis part
103
+ /// of all HTLCs which are otherwise represented by
104
+ /// [`LightningBalance::MaybeTimeoutClaimableHTLC`] with their
105
+ /// [`LightningBalance::MaybeTimeoutClaimableHTLC::outbound_payment`] flag *not* set, as
106
+ /// well as any dust HTLCs which would otherwise be represented the same.
107
+ ///
108
+ /// This amount (rounded up to a whole satoshi value) will not be included in `amount_satoshis`.
109
+ outbound_forwarded_htlc_rounded_msat : u64 ,
110
+ /// The amount of millisatoshis which has been burned to fees from HTLCs which are inbound
111
+ /// to us and for which we know the preimage. This is the sum of the millisatoshis part of
112
+ /// all HTLCs which would be represented by [`LightningBalance::ContentiousClaimable`] on
113
+ /// channel close, but whose current value is included in `amount_satoshis`, as well as any
114
+ /// dust HTLCs which would otherwise be represented the same.
115
+ ///
116
+ /// This amount (rounded up to a whole satoshi value) will not be included in the counterparty's
117
+ /// `amount_satoshis`.
118
+ inbound_claiming_htlc_rounded_msat : u64 ,
119
+ /// The amount of millisatoshis which has been burned to fees from HTLCs which are inbound
120
+ /// to us and for which we do not know the preimage. This is the sum of the millisatoshis
121
+ /// part of all HTLCs which would be represented by
122
+ /// [`LightningBalance::MaybePreimageClaimableHTLC`] on channel close, as well as any dust
123
+ /// HTLCs which would otherwise be represented the same.
124
+ ///
125
+ /// This amount (rounded up to a whole satoshi value) will not be included in the
126
+ /// counterparty's `amount_satoshis`.
127
+ inbound_htlc_rounded_msat : u64 ,
83
128
} ,
84
129
/// The channel has been closed, and the given balance is ours but awaiting confirmations until
85
130
/// we consider it spendable.
@@ -96,6 +141,8 @@ pub enum LightningBalance {
96
141
///
97
142
/// [`Event::SpendableOutputs`]: lightning::events::Event::SpendableOutputs
98
143
confirmation_height : u32 ,
144
+ /// Whether this balance is a result of cooperative close, a force-close, or an HTLC.
145
+ source : BalanceSource ,
99
146
} ,
100
147
/// The channel has been closed, and the given balance should be ours but awaiting spending
101
148
/// transaction confirmation. If the spending transaction does not confirm in time, it is
@@ -136,6 +183,8 @@ pub enum LightningBalance {
136
183
claimable_height : u32 ,
137
184
/// The payment hash whose preimage our counterparty needs to claim this HTLC.
138
185
payment_hash : PaymentHash ,
186
+ /// Indicates whether this HTLC represents a payment which was sent outbound from us.
187
+ outbound_payment : bool ,
139
188
} ,
140
189
/// HTLCs which we received from our counterparty which are claimable with a preimage which we
141
190
/// do not currently have. This will only be claimable if we receive the preimage from the node
@@ -174,16 +223,33 @@ impl LightningBalance {
174
223
channel_id : ChannelId , counterparty_node_id : PublicKey , balance : LdkBalance ,
175
224
) -> Self {
176
225
match balance {
177
- LdkBalance :: ClaimableOnChannelClose { amount_satoshis } => {
178
- Self :: ClaimableOnChannelClose { channel_id, counterparty_node_id, amount_satoshis }
226
+ LdkBalance :: ClaimableOnChannelClose {
227
+ amount_satoshis,
228
+ transaction_fee_satoshis,
229
+ outbound_payment_htlc_rounded_msat,
230
+ outbound_forwarded_htlc_rounded_msat,
231
+ inbound_claiming_htlc_rounded_msat,
232
+ inbound_htlc_rounded_msat,
233
+ } => Self :: ClaimableOnChannelClose {
234
+ channel_id,
235
+ counterparty_node_id,
236
+ amount_satoshis,
237
+ transaction_fee_satoshis,
238
+ outbound_payment_htlc_rounded_msat,
239
+ outbound_forwarded_htlc_rounded_msat,
240
+ inbound_claiming_htlc_rounded_msat,
241
+ inbound_htlc_rounded_msat,
179
242
} ,
180
- LdkBalance :: ClaimableAwaitingConfirmations { amount_satoshis, confirmation_height } => {
181
- Self :: ClaimableAwaitingConfirmations {
182
- channel_id,
183
- counterparty_node_id,
184
- amount_satoshis,
185
- confirmation_height,
186
- }
243
+ LdkBalance :: ClaimableAwaitingConfirmations {
244
+ amount_satoshis,
245
+ confirmation_height,
246
+ source,
247
+ } => Self :: ClaimableAwaitingConfirmations {
248
+ channel_id,
249
+ counterparty_node_id,
250
+ amount_satoshis,
251
+ confirmation_height,
252
+ source,
187
253
} ,
188
254
LdkBalance :: ContentiousClaimable {
189
255
amount_satoshis,
@@ -202,12 +268,14 @@ impl LightningBalance {
202
268
amount_satoshis,
203
269
claimable_height,
204
270
payment_hash,
271
+ outbound_payment,
205
272
} => Self :: MaybeTimeoutClaimableHTLC {
206
273
channel_id,
207
274
counterparty_node_id,
208
275
amount_satoshis,
209
276
claimable_height,
210
277
payment_hash,
278
+ outbound_payment,
211
279
} ,
212
280
LdkBalance :: MaybePreimageClaimableHTLC {
213
281
amount_satoshis,
@@ -278,7 +346,7 @@ impl PendingSweepBalance {
278
346
match output_info. status {
279
347
OutputSpendStatus :: PendingInitialBroadcast { .. } => {
280
348
let channel_id = output_info. channel_id ;
281
- let amount_satoshis = value_satoshis_from_descriptor ( & output_info. descriptor ) ;
349
+ let amount_satoshis = value_from_descriptor ( & output_info. descriptor ) . to_sat ( ) ;
282
350
Self :: PendingBroadcast { channel_id, amount_satoshis }
283
351
} ,
284
352
OutputSpendStatus :: PendingFirstConfirmation {
@@ -287,8 +355,8 @@ impl PendingSweepBalance {
287
355
..
288
356
} => {
289
357
let channel_id = output_info. channel_id ;
290
- let amount_satoshis = value_satoshis_from_descriptor ( & output_info. descriptor ) ;
291
- let latest_spending_txid = latest_spending_tx. txid ( ) ;
358
+ let amount_satoshis = value_from_descriptor ( & output_info. descriptor ) . to_sat ( ) ;
359
+ let latest_spending_txid = latest_spending_tx. compute_txid ( ) ;
292
360
Self :: BroadcastAwaitingConfirmation {
293
361
channel_id,
294
362
latest_broadcast_height,
@@ -303,8 +371,8 @@ impl PendingSweepBalance {
303
371
..
304
372
} => {
305
373
let channel_id = output_info. channel_id ;
306
- let amount_satoshis = value_satoshis_from_descriptor ( & output_info. descriptor ) ;
307
- let latest_spending_txid = latest_spending_tx. txid ( ) ;
374
+ let amount_satoshis = value_from_descriptor ( & output_info. descriptor ) . to_sat ( ) ;
375
+ let latest_spending_txid = latest_spending_tx. compute_txid ( ) ;
308
376
Self :: AwaitingThresholdConfirmations {
309
377
channel_id,
310
378
latest_spending_txid,
0 commit comments