@@ -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"
@@ -1327,6 +1328,161 @@ func (s *swapClientServer) WithdrawDeposits(ctx context.Context,
13271328 return & clientrpc.WithdrawDepositsResponse {}, err
13281329}
13291330
1331+ func (s * swapClientServer ) GetStaticAddressSummary (ctx context.Context ,
1332+ req * clientrpc.StaticAddressSummaryRequest ) (* clientrpc.StaticAddressSummaryResponse ,
1333+ error ) {
1334+
1335+ allDeposits , err := s .depositManager .GetAllDeposits ()
1336+ if err != nil {
1337+ return nil , err
1338+ }
1339+
1340+ return s .depositSummary (ctx , allDeposits , req .StateFilter )
1341+ }
1342+
1343+ func (s * swapClientServer ) depositSummary (ctx context.Context ,
1344+ deposits []* deposit.Deposit ,
1345+ filter clientrpc.DepositState ) (* clientrpc.StaticAddressSummaryResponse ,
1346+ error ) {
1347+
1348+ var (
1349+ totalNumDeposits = len (deposits )
1350+ valueUnconfirmed int64
1351+ valueDeposited int64
1352+ valueExpired int64
1353+ valueWithdrawn int64
1354+ )
1355+
1356+ // Value unconfirmed.
1357+ utxos , err := s .staticAddressManager .ListUnspent (
1358+ ctx , 0 , deposit .MinConfs - 1 ,
1359+ )
1360+ if err != nil {
1361+ return nil , err
1362+ }
1363+ for _ , u := range utxos {
1364+ valueUnconfirmed += int64 (u .Value )
1365+ }
1366+
1367+ for _ , d := range deposits {
1368+ value := int64 (d .Value )
1369+ switch d .State {
1370+ case deposit .Deposited :
1371+ valueDeposited += value
1372+
1373+ case deposit .Expired :
1374+ valueExpired += value
1375+
1376+ case deposit .Withdrawn :
1377+ valueWithdrawn += value
1378+ }
1379+ }
1380+
1381+ clientDeposits , err := s .filterClientDeposits (deposits , filter )
1382+ if err != nil {
1383+ return nil , err
1384+ }
1385+
1386+ params , err := s .staticAddressManager .GetStaticAddressParameters (ctx )
1387+ if err != nil {
1388+ return nil , err
1389+ }
1390+
1391+ address , err := s .staticAddressManager .GetTaprootAddress (
1392+ params .ClientPubkey , params .ServerPubkey , int64 (params .Expiry ),
1393+ )
1394+
1395+ return & clientrpc.StaticAddressSummaryResponse {
1396+ StaticAddress : address .String (),
1397+ TotalNumDeposits : uint32 (totalNumDeposits ),
1398+ ValueUnconfirmed : valueUnconfirmed ,
1399+ ValueDeposited : valueDeposited ,
1400+ ValueExpired : valueExpired ,
1401+ ValueWithdrawn : valueWithdrawn ,
1402+ FilteredDeposits : clientDeposits ,
1403+ }, nil
1404+ }
1405+
1406+ func (s * swapClientServer ) filterClientDeposits (deposits []* deposit.Deposit ,
1407+ filterState clientrpc.DepositState ) ([]* clientrpc.Deposit , error ) {
1408+
1409+ var clientDeposits []* clientrpc.Deposit
1410+ for _ , d := range deposits {
1411+ if filterState != clientrpc .DepositState_UNKNOWN_STATE &&
1412+ d .State != toServerState (filterState ) {
1413+
1414+ continue
1415+ }
1416+
1417+ outpoint := wire .NewOutPoint (& d .Hash , d .Index ).String ()
1418+ clientDeposits = append (clientDeposits , & clientrpc.Deposit {
1419+ Id : d .ID [:],
1420+ State : toClientState (d .State ),
1421+ Outpoint : outpoint ,
1422+ Value : int64 (d .Value ),
1423+ ConfirmationHeight : d .ConfirmationHeight ,
1424+ })
1425+ }
1426+
1427+ return clientDeposits , nil
1428+ }
1429+
1430+ func toClientState (state fsm.StateType ) clientrpc.DepositState {
1431+ switch state {
1432+ case deposit .Deposited :
1433+ return clientrpc .DepositState_DEPOSITED
1434+
1435+ case deposit .Withdrawing :
1436+ return clientrpc .DepositState_WITHDRAWING
1437+
1438+ case deposit .Withdrawn :
1439+ return clientrpc .DepositState_WITHDRAWN
1440+
1441+ case deposit .PublishExpiredDeposit :
1442+ return clientrpc .DepositState_PUBLISH_EXPIRED
1443+
1444+ case deposit .WaitForExpirySweep :
1445+ return clientrpc .DepositState_WAIT_FOR_EXPIRY_SWEEP
1446+
1447+ case deposit .Expired :
1448+ return clientrpc .DepositState_EXPIRED
1449+
1450+ case deposit .Failed :
1451+ return clientrpc .DepositState_FAILED_STATE
1452+
1453+ default :
1454+ return clientrpc .DepositState_UNKNOWN_STATE
1455+ }
1456+ }
1457+
1458+ func toServerState (state clientrpc.DepositState ) fsm.StateType {
1459+ switch state {
1460+ case clientrpc .DepositState_DEPOSITED :
1461+ return deposit .Deposited
1462+
1463+ case clientrpc .DepositState_WITHDRAWING :
1464+ return deposit .Withdrawing
1465+
1466+ case clientrpc .DepositState_WITHDRAWN :
1467+ return deposit .Withdrawn
1468+
1469+ case clientrpc .DepositState_PUBLISH_EXPIRED :
1470+ return deposit .PublishExpiredDeposit
1471+
1472+ case clientrpc .DepositState_WAIT_FOR_EXPIRY_SWEEP :
1473+ return deposit .WaitForExpirySweep
1474+
1475+ case clientrpc .DepositState_EXPIRED :
1476+ return deposit .Expired
1477+
1478+ case clientrpc .DepositState_FAILED_STATE :
1479+ return deposit .Failed
1480+
1481+ default :
1482+ return fsm .EmptyState
1483+ }
1484+ }
1485+
13301486func toServerOutpoints (outpoints []* clientrpc.OutPoint ) ([]wire.OutPoint ,
13311487 error ) {
13321488
0 commit comments