@@ -2018,7 +2018,10 @@ func (s *swapClientServer) ListStaticAddressDeposits(ctx context.Context,
20182018 return isVisibleDeposit (d ) &&
20192019 slices .Contains (outpoints , d .OutPoint .String ())
20202020 }
2021- filteredDeposits = filter (allDeposits , f )
2021+ filteredDeposits , err = s .filterDeposits (allDeposits , f )
2022+ if err != nil {
2023+ return nil , err
2024+ }
20222025
20232026 if len (outpoints ) != len (filteredDeposits ) {
20242027 return nil , fmt .Errorf ("not all outpoints found in " +
@@ -2038,7 +2041,10 @@ func (s *swapClientServer) ListStaticAddressDeposits(ctx context.Context,
20382041
20392042 return d .IsInState (toServerState (req .StateFilter ))
20402043 }
2041- filteredDeposits = filter (allDeposits , f )
2044+ filteredDeposits , err = s .filterDeposits (allDeposits , f )
2045+ if err != nil {
2046+ return nil , err
2047+ }
20422048 }
20432049
20442050 // Calculate the blocks until expiry for each deposit.
@@ -2322,9 +2328,12 @@ func (s *swapClientServer) StaticAddressLoopIn(ctx context.Context,
23222328 }
23232329
23242330 // Build a list of used deposits for the response.
2325- usedDeposits := filter (
2331+ usedDeposits , err := s . filterDeposits (
23262332 loopIn .Deposits , func (d * deposit.Deposit ) bool { return true },
23272333 )
2334+ if err != nil {
2335+ return nil , err
2336+ }
23282337
23292338 err = s .populateBlocksUntilExpiry (ctx , usedDeposits )
23302339 if err != nil {
@@ -2453,35 +2462,65 @@ func isVisibleDeposit(d *deposit.Deposit) bool {
24532462 return d .GetState () != deposit .Replaced
24542463}
24552464
2456- func filter (deposits []* deposit.Deposit , f filterFunc ) []* looprpc.Deposit {
2465+ func (s * swapClientServer ) filterDeposits (deposits []* deposit.Deposit ,
2466+ f filterFunc ) ([]* looprpc.Deposit , error ) {
2467+
24572468 var clientDeposits []* looprpc.Deposit
24582469 for _ , d := range deposits {
24592470 if ! f (d ) {
24602471 continue
24612472 }
24622473
2463- swapHash := make ([]byte , 0 , len (lntypes.Hash {}))
2464- if d .SwapHash != nil {
2465- swapHash = d .SwapHash [:]
2466- }
2467-
2468- hash := d .Hash
2469- outpoint := wire .NewOutPoint (& hash , d .Index ).String ()
2470- deposit := & looprpc.Deposit {
2471- Id : d .ID [:],
2472- State : toClientDepositState (
2473- d .GetState (),
2474- ),
2475- Outpoint : outpoint ,
2476- Value : int64 (d .Value ),
2477- ConfirmationHeight : d .ConfirmationHeight ,
2478- SwapHash : swapHash ,
2474+ deposit , err := s .rpcDeposit (d )
2475+ if err != nil {
2476+ return nil , err
24792477 }
24802478
24812479 clientDeposits = append (clientDeposits , deposit )
24822480 }
24832481
2484- return clientDeposits
2482+ return clientDeposits , nil
2483+ }
2484+
2485+ func (s * swapClientServer ) rpcDeposit (d * deposit.Deposit ) (
2486+ * looprpc.Deposit , error ) {
2487+
2488+ swapHash := make ([]byte , 0 , len (lntypes.Hash {}))
2489+ if d .SwapHash != nil {
2490+ swapHash = d .SwapHash [:]
2491+ }
2492+
2493+ hash := d .Hash
2494+ outpoint := wire .NewOutPoint (& hash , d .Index ).String ()
2495+ deposit := & looprpc.Deposit {
2496+ Id : d .ID [:],
2497+ State : toClientDepositState (
2498+ d .GetState (),
2499+ ),
2500+ Outpoint : outpoint ,
2501+ Value : int64 (d .Value ),
2502+ ConfirmationHeight : d .ConfirmationHeight ,
2503+ SwapHash : swapHash ,
2504+ }
2505+
2506+ if d .AddressParams == nil {
2507+ return deposit , nil
2508+ }
2509+
2510+ if s .staticAddressManager == nil {
2511+ return nil , fmt .Errorf ("static address manager not configured" )
2512+ }
2513+
2514+ staticAddress , err := s .staticAddressManager .GetTaprootAddress (
2515+ d .AddressParams .ClientPubkey , d .AddressParams .ServerPubkey ,
2516+ int64 (d .AddressParams .Expiry ),
2517+ )
2518+ if err != nil {
2519+ return nil , err
2520+ }
2521+ deposit .StaticAddress = staticAddress .String ()
2522+
2523+ return deposit , nil
24852524}
24862525
24872526func toClientDepositState (state fsm.StateType ) looprpc.DepositState {
0 commit comments