@@ -19,6 +19,7 @@ import (
19
19
"github.com/lightninglabs/aperture/l402"
20
20
"github.com/lightninglabs/lndclient"
21
21
"github.com/lightninglabs/loop"
22
+ "github.com/lightninglabs/loop/fsm"
22
23
"github.com/lightninglabs/loop/instantout"
23
24
"github.com/lightninglabs/loop/instantout/reservation"
24
25
"github.com/lightninglabs/loop/labels"
@@ -1383,6 +1384,162 @@ func (s *swapClientServer) WithdrawDeposits(ctx context.Context,
1383
1384
return & clientrpc.WithdrawDepositsResponse {}, err
1384
1385
}
1385
1386
1387
+ func (s * swapClientServer ) GetStaticAddressSummary (ctx context.Context ,
1388
+ req * clientrpc.StaticAddressSummaryRequest ) (* clientrpc.StaticAddressSummaryResponse ,
1389
+ error ) {
1390
+
1391
+ allDeposits , err := s .depositManager .GetAllDeposits ()
1392
+ if err != nil {
1393
+ return nil , err
1394
+ }
1395
+
1396
+ return s .depositSummary (ctx , allDeposits , req .StateFilter )
1397
+ }
1398
+
1399
+ func (s * swapClientServer ) depositSummary (ctx context.Context ,
1400
+ deposits []* deposit.Deposit ,
1401
+ filter clientrpc.DepositState ) (* clientrpc.StaticAddressSummaryResponse ,
1402
+ error ) {
1403
+
1404
+ var (
1405
+ totalNumDeposits = len (deposits )
1406
+ valueUnconfirmed int64
1407
+ valueDeposited int64
1408
+ valueExpired int64
1409
+ valueWithdrawn int64
1410
+ )
1411
+
1412
+ // Value unconfirmed.
1413
+ utxos , err := s .staticAddressManager .ListUnspent (
1414
+ ctx , 0 , deposit .MinConfs - 1 ,
1415
+ )
1416
+ if err != nil {
1417
+ return nil , err
1418
+ }
1419
+ for _ , u := range utxos {
1420
+ valueUnconfirmed += int64 (u .Value )
1421
+ }
1422
+
1423
+ for _ , d := range deposits {
1424
+ value := int64 (d .Value )
1425
+ switch d .GetState () {
1426
+ case deposit .Deposited :
1427
+ valueDeposited += value
1428
+
1429
+ case deposit .Expired :
1430
+ valueExpired += value
1431
+
1432
+ case deposit .Withdrawn :
1433
+ valueWithdrawn += value
1434
+ }
1435
+ }
1436
+
1437
+ clientDeposits := s .filterClientDeposits (deposits , filter )
1438
+
1439
+ params , err := s .staticAddressManager .GetStaticAddressParameters (ctx )
1440
+ if err != nil {
1441
+ return nil , err
1442
+ }
1443
+
1444
+ address , err := s .staticAddressManager .GetTaprootAddress (
1445
+ params .ClientPubkey , params .ServerPubkey , int64 (params .Expiry ),
1446
+ )
1447
+ if err != nil {
1448
+ return nil , err
1449
+ }
1450
+
1451
+ return & clientrpc.StaticAddressSummaryResponse {
1452
+ StaticAddress : address .String (),
1453
+ TotalNumDeposits : uint32 (totalNumDeposits ),
1454
+ ValueUnconfirmed : valueUnconfirmed ,
1455
+ ValueDeposited : valueDeposited ,
1456
+ ValueExpired : valueExpired ,
1457
+ ValueWithdrawn : valueWithdrawn ,
1458
+ FilteredDeposits : clientDeposits ,
1459
+ }, nil
1460
+ }
1461
+
1462
+ func (s * swapClientServer ) filterClientDeposits (deposits []* deposit.Deposit ,
1463
+ filterState clientrpc.DepositState ) []* clientrpc.Deposit {
1464
+
1465
+ var clientDeposits []* clientrpc.Deposit
1466
+ for _ , d := range deposits {
1467
+ if filterState != clientrpc .DepositState_UNKNOWN_STATE &&
1468
+ d .GetState () != toServerState (filterState ) {
1469
+
1470
+ continue
1471
+ }
1472
+
1473
+ hash := d .Hash
1474
+ outpoint := wire .NewOutPoint (& hash , d .Index ).String ()
1475
+ clientDeposits = append (clientDeposits , & clientrpc.Deposit {
1476
+ Id : d .ID [:],
1477
+ State : toClientState (d .GetState ()),
1478
+ Outpoint : outpoint ,
1479
+ Value : int64 (d .Value ),
1480
+ ConfirmationHeight : d .ConfirmationHeight ,
1481
+ })
1482
+ }
1483
+
1484
+ return clientDeposits
1485
+ }
1486
+
1487
+ func toClientState (state fsm.StateType ) clientrpc.DepositState {
1488
+ switch state {
1489
+ case deposit .Deposited :
1490
+ return clientrpc .DepositState_DEPOSITED
1491
+
1492
+ case deposit .Withdrawing :
1493
+ return clientrpc .DepositState_WITHDRAWING
1494
+
1495
+ case deposit .Withdrawn :
1496
+ return clientrpc .DepositState_WITHDRAWN
1497
+
1498
+ case deposit .PublishExpiredDeposit :
1499
+ return clientrpc .DepositState_PUBLISH_EXPIRED
1500
+
1501
+ case deposit .WaitForExpirySweep :
1502
+ return clientrpc .DepositState_WAIT_FOR_EXPIRY_SWEEP
1503
+
1504
+ case deposit .Expired :
1505
+ return clientrpc .DepositState_EXPIRED
1506
+
1507
+ case deposit .Failed :
1508
+ return clientrpc .DepositState_FAILED_STATE
1509
+
1510
+ default :
1511
+ return clientrpc .DepositState_UNKNOWN_STATE
1512
+ }
1513
+ }
1514
+
1515
+ func toServerState (state clientrpc.DepositState ) fsm.StateType {
1516
+ switch state {
1517
+ case clientrpc .DepositState_DEPOSITED :
1518
+ return deposit .Deposited
1519
+
1520
+ case clientrpc .DepositState_WITHDRAWING :
1521
+ return deposit .Withdrawing
1522
+
1523
+ case clientrpc .DepositState_WITHDRAWN :
1524
+ return deposit .Withdrawn
1525
+
1526
+ case clientrpc .DepositState_PUBLISH_EXPIRED :
1527
+ return deposit .PublishExpiredDeposit
1528
+
1529
+ case clientrpc .DepositState_WAIT_FOR_EXPIRY_SWEEP :
1530
+ return deposit .WaitForExpirySweep
1531
+
1532
+ case clientrpc .DepositState_EXPIRED :
1533
+ return deposit .Expired
1534
+
1535
+ case clientrpc .DepositState_FAILED_STATE :
1536
+ return deposit .Failed
1537
+
1538
+ default :
1539
+ return fsm .EmptyState
1540
+ }
1541
+ }
1542
+
1386
1543
func toServerOutpoints (outpoints []* clientrpc.OutPoint ) ([]wire.OutPoint ,
1387
1544
error ) {
1388
1545
0 commit comments