@@ -24,6 +24,24 @@ import (
2424 "google.golang.org/grpc"
2525)
2626
27+ // LeaseDescriptor contains information about a locked output.
28+ type LeaseDescriptor struct {
29+ // LockID is the ID of the lease.
30+ LockID wtxmgr.LockID
31+
32+ // Outpoint is the outpoint of the locked output.
33+ Outpoint wire.OutPoint
34+
35+ // Value is the value of the locked output in satoshis.
36+ Value btcutil.Amount
37+
38+ // PkScript is the pkscript of the locked output.
39+ PkScript []byte
40+
41+ // Expiration is the absolute time of the lock's expiration.
42+ Expiration time.Time
43+ }
44+
2745// WalletKitClient exposes wallet functionality.
2846type WalletKitClient interface {
2947 // ListUnspent returns a list of all utxos spendable by the wallet with
@@ -40,6 +58,9 @@ type WalletKitClient interface {
4058 LeaseOutput (ctx context.Context , lockID wtxmgr.LockID ,
4159 op wire.OutPoint , leaseTime time.Duration ) (time.Time , error )
4260
61+ // ListLeases returns a list of all currently locked outputs.
62+ ListLeases (ctx context.Context ) ([]LeaseDescriptor , error )
63+
4364 // ReleaseOutput unlocks an output, allowing it to be available for coin
4465 // selection if it remains unspent. The ID should match the one used to
4566 // originally lock the output.
@@ -250,6 +271,54 @@ func (m *walletKitClient) LeaseOutput(ctx context.Context, lockID wtxmgr.LockID,
250271 return time .Unix (int64 (resp .Expiration ), 0 ), nil
251272}
252273
274+ // ListLeases returns a list of all currently locked outputs.
275+ func (m * walletKitClient ) ListLeases (ctx context.Context ) ([]LeaseDescriptor ,
276+ error ) {
277+
278+ rpcCtx , cancel := context .WithTimeout (ctx , m .timeout )
279+ defer cancel ()
280+
281+ resp , err := m .client .ListLeases (
282+ m .walletKitMac .WithMacaroonAuth (rpcCtx ),
283+ & walletrpc.ListLeasesRequest {},
284+ )
285+ if err != nil {
286+ return nil , err
287+ }
288+
289+ leases := make ([]LeaseDescriptor , 0 , len (resp .LockedUtxos ))
290+ for _ , leasedUtxo := range resp .LockedUtxos {
291+ leasedUtxo := leasedUtxo
292+
293+ txHash , err := chainhash .NewHash (
294+ leasedUtxo .Outpoint .TxidBytes ,
295+ )
296+ if err != nil {
297+ return nil , err
298+ }
299+
300+ if len (leasedUtxo .Id ) != len (wtxmgr.LockID {}) {
301+ return nil , fmt .Errorf ("invalid lease lock id length" )
302+ }
303+
304+ var lockID wtxmgr.LockID
305+ copy (lockID [:], leasedUtxo .Id )
306+
307+ leases = append (leases , LeaseDescriptor {
308+ LockID : lockID ,
309+ Outpoint : wire.OutPoint {
310+ Hash : * txHash ,
311+ Index : leasedUtxo .Outpoint .OutputIndex ,
312+ },
313+ Value : btcutil .Amount (leasedUtxo .Value ),
314+ PkScript : leasedUtxo .PkScript ,
315+ Expiration : time .Unix (int64 (leasedUtxo .Expiration ), 0 ),
316+ })
317+ }
318+
319+ return leases , nil
320+ }
321+
253322// ReleaseOutput unlocks an output, allowing it to be available for coin
254323// selection if it remains unspent. The ID should match the one used to
255324// originally lock the output.
0 commit comments