mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
Merge pull request #125 from wpaulino/lndclient-listtransactions
lndclient: expose ListTransactions as part of LightningClient
This commit is contained in:
commit
1ea58ad3d6
4 changed files with 57 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package lndclient
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
|
|
@ -9,13 +10,13 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/zpay32"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
|
@ -36,6 +37,10 @@ type LightningClient interface {
|
|||
|
||||
AddInvoice(ctx context.Context, in *invoicesrpc.AddInvoiceData) (
|
||||
lntypes.Hash, string, error)
|
||||
|
||||
// ListTransactions returns all known transactions of the backing lnd
|
||||
// node.
|
||||
ListTransactions(ctx context.Context) ([]*wire.MsgTx, error)
|
||||
}
|
||||
|
||||
// Info contains info about the connected lnd node.
|
||||
|
|
@ -350,3 +355,32 @@ func (s *lightningClient) AddInvoice(ctx context.Context,
|
|||
|
||||
return hash, resp.PaymentRequest, nil
|
||||
}
|
||||
|
||||
// ListTransactions returns all known transactions of the backing lnd node.
|
||||
func (s *lightningClient) ListTransactions(ctx context.Context) ([]*wire.MsgTx, error) {
|
||||
rpcCtx, cancel := context.WithTimeout(ctx, rpcTimeout)
|
||||
defer cancel()
|
||||
|
||||
rpcCtx = s.adminMac.WithMacaroonAuth(rpcCtx)
|
||||
rpcIn := &lnrpc.GetTransactionsRequest{}
|
||||
resp, err := s.client.GetTransactions(rpcCtx, rpcIn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
txs := make([]*wire.MsgTx, 0, len(resp.Transactions))
|
||||
for _, respTx := range resp.Transactions {
|
||||
rawTx, err := hex.DecodeString(respTx.RawTxHex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx wire.MsgTx
|
||||
if err := tx.Deserialize(bytes.NewReader(rawTx)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
txs = append(txs, &tx)
|
||||
}
|
||||
|
||||
return txs, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/lightninglabs/loop/lndclient"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
|
||||
|
|
@ -126,3 +127,13 @@ func (h *mockLightningClient) AddInvoice(ctx context.Context,
|
|||
|
||||
return hash, payReqString, nil
|
||||
}
|
||||
|
||||
// ListTransactions returns all known transactions of the backing lnd node.
|
||||
func (h *mockLightningClient) ListTransactions(
|
||||
ctx context.Context) ([]*wire.MsgTx, error) {
|
||||
|
||||
h.lnd.lock.Lock()
|
||||
txs := h.lnd.Transactions
|
||||
h.lnd.lock.Unlock()
|
||||
return txs, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,6 +135,8 @@ type LndMockServices struct {
|
|||
Signature []byte
|
||||
SignatureMsg string
|
||||
|
||||
Transactions []*wire.MsgTx
|
||||
|
||||
WaitForFinished func()
|
||||
|
||||
lock sync.Mutex
|
||||
|
|
@ -152,6 +154,13 @@ func (s *LndMockServices) NotifyHeight(height int32) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// 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.lock.Unlock()
|
||||
}
|
||||
|
||||
// IsDone checks whether all channels have been fully emptied. If not this may
|
||||
// indicate unexpected behaviour of the code under test.
|
||||
func (s *LndMockServices) IsDone() error {
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ func (m *mockWalletKit) NextAddr(ctx context.Context) (btcutil.Address, error) {
|
|||
}
|
||||
|
||||
func (m *mockWalletKit) PublishTransaction(ctx context.Context, tx *wire.MsgTx) error {
|
||||
m.lnd.AddTx(tx)
|
||||
m.lnd.TxPublishChannel <- tx
|
||||
return nil
|
||||
}
|
||||
|
|
@ -84,6 +85,7 @@ func (m *mockWalletKit) SendOutputs(ctx context.Context, outputs []*wire.TxOut,
|
|||
})
|
||||
}
|
||||
|
||||
m.lnd.AddTx(&tx)
|
||||
m.lnd.SendOutputsChannel <- tx
|
||||
|
||||
return &tx, nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue