Skip to content

Commit fbb1a3b

Browse files
committed
lndclient: add list sweeps to wallet cilent
1 parent c76f2c4 commit fbb1a3b

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

lndclient/walletkit_client.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ type WalletKitClient interface {
5757

5858
EstimateFee(ctx context.Context, confTarget int32) (chainfee.SatPerKWeight,
5959
error)
60+
61+
// ListSweeps returns a list of sweep transaction ids known to our node.
62+
// Note that this function only looks up transaction ids, and does not
63+
// query our wallet for the full set of transactions.
64+
ListSweeps(ctx context.Context) ([]string, error)
6065
}
6166

6267
type walletKitClient struct {
@@ -319,3 +324,26 @@ func (m *walletKitClient) EstimateFee(ctx context.Context, confTarget int32) (
319324

320325
return chainfee.SatPerKWeight(resp.SatPerKw), nil
321326
}
327+
328+
// ListSweeps returns a list of sweep transaction ids known to our node.
329+
// Note that this function only looks up transaction ids (Verbose=false), and
330+
// does not query our wallet for the full set of transactions.
331+
func (m *walletKitClient) ListSweeps(ctx context.Context) ([]string, error) {
332+
rpcCtx, cancel := context.WithTimeout(ctx, rpcTimeout)
333+
defer cancel()
334+
335+
resp, err := m.client.ListSweeps(
336+
m.walletKitMac.WithMacaroonAuth(rpcCtx),
337+
&walletrpc.ListSweepsRequest{
338+
Verbose: false,
339+
},
340+
)
341+
if err != nil {
342+
return nil, err
343+
}
344+
345+
// Since we have requested the abbreviated response from lnd, we can
346+
// just get our response to a list of sweeps and return it.
347+
sweeps := resp.GetTransactionIds()
348+
return sweeps.TransactionIds, nil
349+
}

test/lnd_services_mock.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ type LndMockServices struct {
158158
SignatureMsg string
159159

160160
Transactions []lndclient.Transaction
161+
Sweeps []string
161162

162163
// Invoices is a set of invoices that have been created by the mock,
163164
// keyed by hash string.

test/walletkit_mock.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,8 @@ func (m *mockWalletKit) EstimateFee(ctx context.Context, confTarget int32) (
126126

127127
return feeEstimate, nil
128128
}
129+
130+
// ListSweeps returns a list of the sweep transaction ids known to our node.
131+
func (m *mockWalletKit) ListSweeps(_ context.Context) ([]string, error) {
132+
return m.lnd.Sweeps, nil
133+
}

0 commit comments

Comments
 (0)