Skip to content

Commit c4fccb8

Browse files
committed
staticaddr: include address in deposit list
1 parent fd236c9 commit c4fccb8

5 files changed

Lines changed: 97 additions & 24 deletions

File tree

loopd/swapclient_server.go

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

24872526
func toClientDepositState(state fsm.StateType) looprpc.DepositState {

loopd/swapclient_server_staticaddr_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,17 @@ func TestListStaticAddressDepositsHidesReplaced(t *testing.T) {
275275
available.SetState(deposit.Deposited)
276276

277277
addrMgr, lnd := newTestStaticAddressContext(t)
278+
addresses, err := addrMgr.GetAllAddresses(context.Background())
279+
require.NoError(t, err)
280+
require.Len(t, addresses, 1)
281+
available.AddressParams = addresses[0]
282+
283+
expectedAddr, err := addrMgr.GetTaprootAddress(
284+
addresses[0].ClientPubkey, addresses[0].ServerPubkey,
285+
int64(addresses[0].Expiry),
286+
)
287+
require.NoError(t, err)
288+
278289
server := &swapClientServer{
279290
depositManager: newTestDepositManager(replaced, available),
280291
staticAddressManager: addrMgr,
@@ -290,6 +301,10 @@ func TestListStaticAddressDepositsHidesReplaced(t *testing.T) {
290301
t, available.OutPoint.String(),
291302
resp.FilteredDeposits[0].Outpoint,
292303
)
304+
require.Equal(
305+
t, expectedAddr.String(),
306+
resp.FilteredDeposits[0].StaticAddress,
307+
)
293308
}
294309

295310
func TestGetStaticAddressSummaryIgnoresReplaced(t *testing.T) {

looprpc/client.pb.go

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

looprpc/client.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,6 +2104,11 @@ message Deposit {
21042104
set if the deposit is part of a loop-in swap.
21052105
*/
21062106
bytes swap_hash = 7;
2107+
2108+
/*
2109+
The static address that the deposit was sent to.
2110+
*/
2111+
string static_address = 8;
21072112
}
21082113

21092114
message StaticAddressWithdrawal {

looprpc/client.swagger.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,10 @@
17261726
"type": "string",
17271727
"format": "byte",
17281728
"description": "The swap hash of the swap that this deposit is part of. This field is only\nset if the deposit is part of a loop-in swap."
1729+
},
1730+
"static_address": {
1731+
"type": "string",
1732+
"description": "The static address that the deposit was sent to."
17291733
}
17301734
}
17311735
},

0 commit comments

Comments
 (0)