From e0c794490b286de75a51e31b9f177bff12989ee0 Mon Sep 17 00:00:00 2001 From: Slyghtning Date: Wed, 25 Oct 2023 15:45:47 +0200 Subject: [PATCH] staticaddr: list unspent outputs in server --- staticaddr/server.go | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/staticaddr/server.go b/staticaddr/server.go index 4eeca96..a6273dd 100644 --- a/staticaddr/server.go +++ b/staticaddr/server.go @@ -26,10 +26,10 @@ func NewAddressServer(addressClient staticaddressrpc.StaticAddressServerClient, // NewAddress is the rpc endpoint for loop clients to request a new static // address. -func (r *AddressServer) NewAddress(ctx context.Context, +func (s *AddressServer) NewAddress(ctx context.Context, _ *looprpc.NewAddressRequest) (*looprpc.NewAddressResponse, error) { - address, err := r.manager.NewAddress(ctx) + address, err := s.manager.NewAddress(ctx) if err != nil { return nil, err } @@ -40,3 +40,31 @@ func (r *AddressServer) NewAddress(ctx context.Context, Address: address.String(), }, nil } + +// ListUnspent returns a list of utxos behind the static address. +func (s *AddressServer) ListUnspent(ctx context.Context, + req *looprpc.ListUnspentRequest) (*looprpc.ListUnspentResponse, error) { + + // List all unspent utxos the wallet sees, regardless of the number of + // confirmations. + staticAddress, utxos, err := s.manager.ListUnspentRaw( + ctx, req.MinConfs, req.MaxConfs, + ) + if err != nil { + return nil, err + } + + // Prepare the list response. + var respUtxos []*looprpc.Utxo + for _, u := range utxos { + utxo := &looprpc.Utxo{ + StaticAddress: staticAddress.String(), + AmountSat: int64(u.Value), + Confirmations: u.Confirmations, + Outpoint: u.OutPoint.String(), + } + respUtxos = append(respUtxos, utxo) + } + + return &looprpc.ListUnspentResponse{Utxos: respUtxos}, nil +}