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