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