@@ -231,15 +231,62 @@ func sweepEntries(tx lndclient.Transaction, u entryUtils) ([]*HarmonyEntry, erro
231231 return []* HarmonyEntry {txEntry , feeEntry }, nil
232232}
233233
234+ // isUtxoManagementTx checks whether a transaction is restructuring our utxos.
235+ func isUtxoManagementTx (txn lndclient.Transaction ) bool {
236+ // Check all inputs.
237+ for _ , input := range txn .PreviousOutpoints {
238+ if ! input .IsOurOutput {
239+ return false
240+ }
241+ }
242+
243+ // Check all outputs.
244+ for _ , output := range txn .OutputDetails {
245+ if ! output .IsOurAddress {
246+ return false
247+ }
248+ }
249+
250+ // If all inputs and outputs belong to our wallet, it's utxo management.
251+ return true
252+ }
253+
254+ // createOnchainFeeEntry creates a fee entry for an on chain transaction.
255+ func createOnchainFeeEntry (tx lndclient.Transaction , category string ,
256+ note string , u entryUtils ) (* HarmonyEntry , error ) {
257+
258+ // Total fees are expressed as a positive value in sats, we convert to
259+ // msat here and make the value negative so that it reflects as a
260+ // debit.
261+ feeAmt := invertedSatsToMsats (tx .Fee )
262+
263+ feeEntry , err := newHarmonyEntry (
264+ tx .Timestamp , feeAmt , EntryTypeFee ,
265+ tx .TxHash , FeeReference (tx .TxHash ), note , category , true ,
266+ u .getFiat ,
267+ )
268+
269+ if err != nil {
270+ return nil , err
271+ }
272+
273+ return feeEntry , nil
274+ }
275+
276+ // utxoManagementFeeNote creates a note for utxo management fee types.
277+ func utxoManagementFeeNote (txid string ) string {
278+ return fmt .Sprintf ("fees for utxo management transaction: %v" , txid )
279+ }
280+
234281// onChainEntries produces relevant entries for an on chain transaction.
235282func onChainEntries (tx lndclient.Transaction ,
236283 u entryUtils ) ([]* HarmonyEntry , error ) {
237284
238285 var (
239- amtMsat = satsToMsat (tx .Amount )
240- entryType EntryType
241- feeType = EntryTypeFee
242- category = getCategory ( tx . Label , u . customCategories )
286+ amtMsat = satsToMsat (tx .Amount )
287+ entryType EntryType
288+ category = getCategory ( tx . Label , u . customCategories )
289+ utxoManagement bool
243290 )
244291
245292 // Determine the type of entry we are creating. If this is a sweep, we
@@ -252,6 +299,9 @@ func onChainEntries(tx lndclient.Transaction,
252299 case amtMsat > 0 :
253300 entryType = EntryTypeReceipt
254301
302+ case isUtxoManagementTx (tx ):
303+ utxoManagement = true
304+
255305 // If we have a zero amount on chain transaction, we do not create an
256306 // entry for it. This may happen when the remote party claims a htlc on
257307 // our commitment. We do not want to report 0 value transactions that
@@ -260,6 +310,17 @@ func onChainEntries(tx lndclient.Transaction,
260310 return nil , nil
261311 }
262312
313+ // If this is a utxo management transaction, we return a fee entry only.
314+ if utxoManagement {
315+ note := utxoManagementFeeNote (tx .TxHash )
316+ feeEntry , err := createOnchainFeeEntry (tx , category , note , u )
317+ if err != nil {
318+ return nil , err
319+ }
320+
321+ return []* HarmonyEntry {feeEntry }, nil
322+ }
323+
263324 txEntry , err := newHarmonyEntry (
264325 tx .Timestamp , amtMsat , entryType , tx .TxHash , tx .TxHash ,
265326 tx .Label , category , true , u .getFiat ,
@@ -273,15 +334,7 @@ func onChainEntries(tx lndclient.Transaction,
273334 return []* HarmonyEntry {txEntry }, nil
274335 }
275336
276- // Total fees are expressed as a positive value in sats, we convert to
277- // msat here and make the value negative so that it reflects as a
278- // debit.
279- feeAmt := invertedSatsToMsats (tx .Fee )
280-
281- feeEntry , err := newHarmonyEntry (
282- tx .Timestamp , feeAmt , feeType , tx .TxHash ,
283- FeeReference (tx .TxHash ), "" , category , true , u .getFiat ,
284- )
337+ feeEntry , err := createOnchainFeeEntry (tx , category , "" , u )
285338 if err != nil {
286339 return nil , err
287340 }
0 commit comments