@@ -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"
@@ -1395,6 +1396,167 @@ func (s *swapClientServer) WithdrawDeposits(ctx context.Context,
1395
1396
return & clientrpc.WithdrawDepositsResponse {}, err
1396
1397
}
1397
1398
1399
+ // GetStaticAddressSummary returns a summary static address related information.
1400
+ // Amongst deposits and withdrawals and their total values it also includes a
1401
+ // list of detailed deposit information filtered by their state.
1402
+ func (s * swapClientServer ) GetStaticAddressSummary (ctx context.Context ,
1403
+ req * clientrpc.StaticAddressSummaryRequest ) (
1404
+ * clientrpc.StaticAddressSummaryResponse , error ) {
1405
+
1406
+ allDeposits , err := s .depositManager .GetAllDeposits ()
1407
+ if err != nil {
1408
+ return nil , err
1409
+ }
1410
+
1411
+ return s .depositSummary (ctx , allDeposits , req .StateFilter )
1412
+ }
1413
+
1414
+ func (s * swapClientServer ) depositSummary (ctx context.Context ,
1415
+ deposits []* deposit.Deposit , filter clientrpc.DepositState ) (
1416
+ * clientrpc.StaticAddressSummaryResponse , error ) {
1417
+
1418
+ var (
1419
+ totalNumDeposits = len (deposits )
1420
+ valueUnconfirmed int64
1421
+ valueDeposited int64
1422
+ valueExpired int64
1423
+ valueWithdrawn int64
1424
+ )
1425
+
1426
+ // Value unconfirmed.
1427
+ utxos , err := s .staticAddressManager .ListUnspent (
1428
+ ctx , 0 , deposit .MinConfs - 1 ,
1429
+ )
1430
+ if err != nil {
1431
+ return nil , err
1432
+ }
1433
+ for _ , u := range utxos {
1434
+ valueUnconfirmed += int64 (u .Value )
1435
+ }
1436
+
1437
+ // Confirmed total values by category.
1438
+ for _ , d := range deposits {
1439
+ value := int64 (d .Value )
1440
+ switch d .GetState () {
1441
+ case deposit .Deposited :
1442
+ valueDeposited += value
1443
+
1444
+ case deposit .Expired :
1445
+ valueExpired += value
1446
+
1447
+ case deposit .Withdrawn :
1448
+ valueWithdrawn += value
1449
+ }
1450
+ }
1451
+
1452
+ // Deposits filtered by state.
1453
+ clientDeposits := s .filterClientDeposits (deposits , filter )
1454
+
1455
+ params , err := s .staticAddressManager .GetStaticAddressParameters (ctx )
1456
+ if err != nil {
1457
+ return nil , err
1458
+ }
1459
+
1460
+ address , err := s .staticAddressManager .GetTaprootAddress (
1461
+ params .ClientPubkey , params .ServerPubkey , int64 (params .Expiry ),
1462
+ )
1463
+ if err != nil {
1464
+ return nil , err
1465
+ }
1466
+
1467
+ return & clientrpc.StaticAddressSummaryResponse {
1468
+ StaticAddress : address .String (),
1469
+ TotalNumDeposits : uint32 (totalNumDeposits ),
1470
+ ValueUnconfirmed : valueUnconfirmed ,
1471
+ ValueDeposited : valueDeposited ,
1472
+ ValueExpired : valueExpired ,
1473
+ ValueWithdrawn : valueWithdrawn ,
1474
+ FilteredDeposits : clientDeposits ,
1475
+ }, nil
1476
+ }
1477
+
1478
+ func (s * swapClientServer ) filterClientDeposits (deposits []* deposit.Deposit ,
1479
+ filterState clientrpc.DepositState ) []* clientrpc.Deposit {
1480
+
1481
+ var clientDeposits []* clientrpc.Deposit
1482
+ for _ , d := range deposits {
1483
+ state := d .GetState ()
1484
+ if filterState != clientrpc .DepositState_UNKNOWN_STATE &&
1485
+ state != toServerState (filterState ) {
1486
+
1487
+ continue
1488
+ }
1489
+
1490
+ hash := d .Hash
1491
+ outpoint := wire .NewOutPoint (& hash , d .Index ).String ()
1492
+ clientDeposits = append (clientDeposits , & clientrpc.Deposit {
1493
+ Id : d .ID [:],
1494
+ State : toClientState (state ),
1495
+ Outpoint : outpoint ,
1496
+ Value : int64 (d .Value ),
1497
+ ConfirmationHeight : d .ConfirmationHeight ,
1498
+ })
1499
+ }
1500
+
1501
+ return clientDeposits
1502
+ }
1503
+
1504
+ func toClientState (state fsm.StateType ) clientrpc.DepositState {
1505
+ switch state {
1506
+ case deposit .Deposited :
1507
+ return clientrpc .DepositState_DEPOSITED
1508
+
1509
+ case deposit .Withdrawing :
1510
+ return clientrpc .DepositState_WITHDRAWING
1511
+
1512
+ case deposit .Withdrawn :
1513
+ return clientrpc .DepositState_WITHDRAWN
1514
+
1515
+ case deposit .PublishExpiredDeposit :
1516
+ return clientrpc .DepositState_PUBLISH_EXPIRED
1517
+
1518
+ case deposit .WaitForExpirySweep :
1519
+ return clientrpc .DepositState_WAIT_FOR_EXPIRY_SWEEP
1520
+
1521
+ case deposit .Expired :
1522
+ return clientrpc .DepositState_EXPIRED
1523
+
1524
+ case deposit .Failed :
1525
+ return clientrpc .DepositState_FAILED_STATE
1526
+
1527
+ default :
1528
+ return clientrpc .DepositState_UNKNOWN_STATE
1529
+ }
1530
+ }
1531
+
1532
+ func toServerState (state clientrpc.DepositState ) fsm.StateType {
1533
+ switch state {
1534
+ case clientrpc .DepositState_DEPOSITED :
1535
+ return deposit .Deposited
1536
+
1537
+ case clientrpc .DepositState_WITHDRAWING :
1538
+ return deposit .Withdrawing
1539
+
1540
+ case clientrpc .DepositState_WITHDRAWN :
1541
+ return deposit .Withdrawn
1542
+
1543
+ case clientrpc .DepositState_PUBLISH_EXPIRED :
1544
+ return deposit .PublishExpiredDeposit
1545
+
1546
+ case clientrpc .DepositState_WAIT_FOR_EXPIRY_SWEEP :
1547
+ return deposit .WaitForExpirySweep
1548
+
1549
+ case clientrpc .DepositState_EXPIRED :
1550
+ return deposit .Expired
1551
+
1552
+ case clientrpc .DepositState_FAILED_STATE :
1553
+ return deposit .Failed
1554
+
1555
+ default :
1556
+ return fsm .EmptyState
1557
+ }
1558
+ }
1559
+
1398
1560
func toServerOutpoints (outpoints []* clientrpc.OutPoint ) ([]wire.OutPoint ,
1399
1561
error ) {
1400
1562
0 commit comments