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