mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
lndclient: update listTransactions to return full transaction
This commit is contained in:
parent
475c7f29f1
commit
c76f2c4cf1
3 changed files with 49 additions and 8 deletions
|
|
@ -45,7 +45,7 @@ type LightningClient interface {
|
|||
|
||||
// ListTransactions returns all known transactions of the backing lnd
|
||||
// node.
|
||||
ListTransactions(ctx context.Context) ([]*wire.MsgTx, error)
|
||||
ListTransactions(ctx context.Context) ([]Transaction, error)
|
||||
|
||||
// ListChannels retrieves all channels of the backing lnd node.
|
||||
ListChannels(ctx context.Context) ([]ChannelInfo, error)
|
||||
|
|
@ -257,6 +257,35 @@ func (c Initiator) String() string {
|
|||
}
|
||||
}
|
||||
|
||||
// Transaction represents an on chain transaction.
|
||||
type Transaction struct {
|
||||
// Tx is the on chain transaction.
|
||||
Tx *wire.MsgTx
|
||||
|
||||
// TxHash is the transaction hash string.
|
||||
TxHash string
|
||||
|
||||
// Timestamp is the timestamp our wallet has for the transaction.
|
||||
Timestamp time.Time
|
||||
|
||||
// Amount is the balance change that this transaction had on addresses
|
||||
// controlled by our wallet.
|
||||
Amount btcutil.Amount
|
||||
|
||||
// Fee is the amount of fees our wallet committed to this transaction.
|
||||
// Note that this field is not exhaustive, as it does not account for
|
||||
// fees taken from inputs that that wallet doesn't know it owns (for
|
||||
// example, the fees taken from our channel balance when we close a
|
||||
// channel).
|
||||
Fee btcutil.Amount
|
||||
|
||||
// Confirmations is the number of confirmations the transaction has.
|
||||
Confirmations int32
|
||||
|
||||
// Label is an optional label set for on chain transactions.
|
||||
Label string
|
||||
}
|
||||
|
||||
var (
|
||||
// ErrMalformedServerResponse is returned when the swap and/or prepay
|
||||
// invoice is malformed.
|
||||
|
|
@ -675,7 +704,7 @@ func unmarshalInvoice(resp *lnrpc.Invoice) (*Invoice, error) {
|
|||
}
|
||||
|
||||
// ListTransactions returns all known transactions of the backing lnd node.
|
||||
func (s *lightningClient) ListTransactions(ctx context.Context) ([]*wire.MsgTx, error) {
|
||||
func (s *lightningClient) ListTransactions(ctx context.Context) ([]Transaction, error) {
|
||||
rpcCtx, cancel := context.WithTimeout(ctx, rpcTimeout)
|
||||
defer cancel()
|
||||
|
||||
|
|
@ -686,8 +715,8 @@ func (s *lightningClient) ListTransactions(ctx context.Context) ([]*wire.MsgTx,
|
|||
return nil, err
|
||||
}
|
||||
|
||||
txs := make([]*wire.MsgTx, 0, len(resp.Transactions))
|
||||
for _, respTx := range resp.Transactions {
|
||||
txs := make([]Transaction, len(resp.Transactions))
|
||||
for i, respTx := range resp.Transactions {
|
||||
rawTx, err := hex.DecodeString(respTx.RawTxHex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -697,7 +726,16 @@ func (s *lightningClient) ListTransactions(ctx context.Context) ([]*wire.MsgTx,
|
|||
if err := tx.Deserialize(bytes.NewReader(rawTx)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
txs = append(txs, &tx)
|
||||
|
||||
txs[i] = Transaction{
|
||||
Tx: &tx,
|
||||
TxHash: tx.TxHash().String(),
|
||||
Timestamp: time.Unix(respTx.TimeStamp, 0),
|
||||
Amount: btcutil.Amount(respTx.Amount),
|
||||
Fee: btcutil.Amount(respTx.TotalFees),
|
||||
Confirmations: respTx.NumConfirmations,
|
||||
Label: respTx.Label,
|
||||
}
|
||||
}
|
||||
|
||||
return txs, nil
|
||||
|
|
|
|||
|
|
@ -160,11 +160,12 @@ func (h *mockLightningClient) LookupInvoice(_ context.Context,
|
|||
|
||||
// ListTransactions returns all known transactions of the backing lnd node.
|
||||
func (h *mockLightningClient) ListTransactions(
|
||||
ctx context.Context) ([]*wire.MsgTx, error) {
|
||||
_ context.Context) ([]lndclient.Transaction, error) {
|
||||
|
||||
h.lnd.lock.Lock()
|
||||
txs := h.lnd.Transactions
|
||||
h.lnd.lock.Unlock()
|
||||
|
||||
return txs, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ type LndMockServices struct {
|
|||
Signature []byte
|
||||
SignatureMsg string
|
||||
|
||||
Transactions []*wire.MsgTx
|
||||
Transactions []lndclient.Transaction
|
||||
|
||||
// Invoices is a set of invoices that have been created by the mock,
|
||||
// keyed by hash string.
|
||||
|
|
@ -188,7 +188,9 @@ func (s *LndMockServices) NotifyHeight(height int32) error {
|
|||
// AddRelevantTx marks the given transaction as relevant.
|
||||
func (s *LndMockServices) AddTx(tx *wire.MsgTx) {
|
||||
s.lock.Lock()
|
||||
s.Transactions = append(s.Transactions, tx.Copy())
|
||||
s.Transactions = append(s.Transactions, lndclient.Transaction{
|
||||
Tx: tx.Copy(),
|
||||
})
|
||||
s.lock.Unlock()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue