From fbb1a3b20439963b00de80db98f628ce243f3dbf Mon Sep 17 00:00:00 2001 From: carla Date: Wed, 17 Jun 2020 08:44:44 +0200 Subject: [PATCH] lndclient: add list sweeps to wallet cilent --- lndclient/walletkit_client.go | 28 ++++++++++++++++++++++++++++ test/lnd_services_mock.go | 1 + test/walletkit_mock.go | 5 +++++ 3 files changed, 34 insertions(+) diff --git a/lndclient/walletkit_client.go b/lndclient/walletkit_client.go index d46409d..99ff405 100644 --- a/lndclient/walletkit_client.go +++ b/lndclient/walletkit_client.go @@ -57,6 +57,11 @@ type WalletKitClient interface { EstimateFee(ctx context.Context, confTarget int32) (chainfee.SatPerKWeight, error) + + // ListSweeps returns a list of sweep transaction ids known to our node. + // Note that this function only looks up transaction ids, and does not + // query our wallet for the full set of transactions. + ListSweeps(ctx context.Context) ([]string, error) } type walletKitClient struct { @@ -319,3 +324,26 @@ func (m *walletKitClient) EstimateFee(ctx context.Context, confTarget int32) ( return chainfee.SatPerKWeight(resp.SatPerKw), nil } + +// ListSweeps returns a list of sweep transaction ids known to our node. +// Note that this function only looks up transaction ids (Verbose=false), and +// does not query our wallet for the full set of transactions. +func (m *walletKitClient) ListSweeps(ctx context.Context) ([]string, error) { + rpcCtx, cancel := context.WithTimeout(ctx, rpcTimeout) + defer cancel() + + resp, err := m.client.ListSweeps( + m.walletKitMac.WithMacaroonAuth(rpcCtx), + &walletrpc.ListSweepsRequest{ + Verbose: false, + }, + ) + if err != nil { + return nil, err + } + + // Since we have requested the abbreviated response from lnd, we can + // just get our response to a list of sweeps and return it. + sweeps := resp.GetTransactionIds() + return sweeps.TransactionIds, nil +} diff --git a/test/lnd_services_mock.go b/test/lnd_services_mock.go index eef5c28..1e313dd 100644 --- a/test/lnd_services_mock.go +++ b/test/lnd_services_mock.go @@ -158,6 +158,7 @@ type LndMockServices struct { SignatureMsg string Transactions []lndclient.Transaction + Sweeps []string // Invoices is a set of invoices that have been created by the mock, // keyed by hash string. diff --git a/test/walletkit_mock.go b/test/walletkit_mock.go index 769297a..fcd59c9 100644 --- a/test/walletkit_mock.go +++ b/test/walletkit_mock.go @@ -126,3 +126,8 @@ func (m *mockWalletKit) EstimateFee(ctx context.Context, confTarget int32) ( return feeEstimate, nil } + +// ListSweeps returns a list of the sweep transaction ids known to our node. +func (m *mockWalletKit) ListSweeps(_ context.Context) ([]string, error) { + return m.lnd.Sweeps, nil +}