@@ -45,7 +45,7 @@ type LightningClient interface {
4545
4646 // ListTransactions returns all known transactions of the backing lnd
4747 // node.
48- ListTransactions (ctx context.Context ) ([]* wire. MsgTx , error )
48+ ListTransactions (ctx context.Context ) ([]Transaction , error )
4949
5050 // ListChannels retrieves all channels of the backing lnd node.
5151 ListChannels (ctx context.Context ) ([]ChannelInfo , error )
@@ -257,6 +257,35 @@ func (c Initiator) String() string {
257257 }
258258}
259259
260+ // Transaction represents an on chain transaction.
261+ type Transaction struct {
262+ // Tx is the on chain transaction.
263+ Tx * wire.MsgTx
264+
265+ // TxHash is the transaction hash string.
266+ TxHash string
267+
268+ // Timestamp is the timestamp our wallet has for the transaction.
269+ Timestamp time.Time
270+
271+ // Amount is the balance change that this transaction had on addresses
272+ // controlled by our wallet.
273+ Amount btcutil.Amount
274+
275+ // Fee is the amount of fees our wallet committed to this transaction.
276+ // Note that this field is not exhaustive, as it does not account for
277+ // fees taken from inputs that that wallet doesn't know it owns (for
278+ // example, the fees taken from our channel balance when we close a
279+ // channel).
280+ Fee btcutil.Amount
281+
282+ // Confirmations is the number of confirmations the transaction has.
283+ Confirmations int32
284+
285+ // Label is an optional label set for on chain transactions.
286+ Label string
287+ }
288+
260289var (
261290 // ErrMalformedServerResponse is returned when the swap and/or prepay
262291 // invoice is malformed.
@@ -675,7 +704,7 @@ func unmarshalInvoice(resp *lnrpc.Invoice) (*Invoice, error) {
675704}
676705
677706// ListTransactions returns all known transactions of the backing lnd node.
678- func (s * lightningClient ) ListTransactions (ctx context.Context ) ([]* wire. MsgTx , error ) {
707+ func (s * lightningClient ) ListTransactions (ctx context.Context ) ([]Transaction , error ) {
679708 rpcCtx , cancel := context .WithTimeout (ctx , rpcTimeout )
680709 defer cancel ()
681710
@@ -686,8 +715,8 @@ func (s *lightningClient) ListTransactions(ctx context.Context) ([]*wire.MsgTx,
686715 return nil , err
687716 }
688717
689- txs := make ([]* wire. MsgTx , 0 , len (resp .Transactions ))
690- for _ , respTx := range resp .Transactions {
718+ txs := make ([]Transaction , len (resp .Transactions ))
719+ for i , respTx := range resp .Transactions {
691720 rawTx , err := hex .DecodeString (respTx .RawTxHex )
692721 if err != nil {
693722 return nil , err
@@ -697,7 +726,16 @@ func (s *lightningClient) ListTransactions(ctx context.Context) ([]*wire.MsgTx,
697726 if err := tx .Deserialize (bytes .NewReader (rawTx )); err != nil {
698727 return nil , err
699728 }
700- txs = append (txs , & tx )
729+
730+ txs [i ] = Transaction {
731+ Tx : & tx ,
732+ TxHash : tx .TxHash ().String (),
733+ Timestamp : time .Unix (respTx .TimeStamp , 0 ),
734+ Amount : btcutil .Amount (respTx .Amount ),
735+ Fee : btcutil .Amount (respTx .TotalFees ),
736+ Confirmations : respTx .NumConfirmations ,
737+ Label : respTx .Label ,
738+ }
701739 }
702740
703741 return txs , nil
0 commit comments