@@ -19,6 +19,7 @@ import (
19
19
"github.com/lightninglabs/aperture/lsat"
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"
@@ -1319,6 +1320,142 @@ func (s *swapClientServer) WithdrawDeposits(ctx context.Context,
1319
1320
return & clientrpc.WithdrawDepositsResponse {}, err
1320
1321
}
1321
1322
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 , error ) {
1338
+
1339
+ var (
1340
+ totalNumSwaps = len (deposits )
1341
+ valueUnconfirmed int64
1342
+ valueDeposited int64
1343
+ valueExpired int64
1344
+ valueWithdrawn int64
1345
+ valueLoopedIn int64
1346
+ )
1347
+
1348
+ // Value unconfirmed.
1349
+ utxos , err := s .staticAddressManager .ListUnspent (ctx , 0 , deposit .MinConfs - 1 )
1350
+ if err != nil {
1351
+ return nil , err
1352
+ }
1353
+ for _ , u := range utxos {
1354
+ valueUnconfirmed += int64 (u .Value )
1355
+ }
1356
+
1357
+ for _ , d := range deposits {
1358
+ value := int64 (d .Value )
1359
+ switch d .State {
1360
+ case deposit .Deposited :
1361
+ valueDeposited += value
1362
+
1363
+ case deposit .SweptExpiredDeposit :
1364
+ valueExpired += value
1365
+
1366
+ case deposit .Withdrawn :
1367
+ valueWithdrawn += value
1368
+ }
1369
+ }
1370
+
1371
+ clientDeposits , err := s .filterClientDeposits (deposits , filter )
1372
+ if err != nil {
1373
+ return nil , err
1374
+ }
1375
+
1376
+ params , err := s .staticAddressManager .GetStaticAddressParameters (ctx )
1377
+ if err != nil {
1378
+ return nil , err
1379
+ }
1380
+
1381
+ address , err := s .staticAddressManager .GetTaprootAddress (
1382
+ params .ClientPubkey , params .ServerPubkey , int64 (params .Expiry ),
1383
+ )
1384
+
1385
+ return & clientrpc.StaticAddressSummaryResponse {
1386
+ StaticAddress : address .String (),
1387
+ TotalNumSwaps : uint32 (totalNumSwaps ),
1388
+ ValueUnconfirmed : valueUnconfirmed ,
1389
+ ValueDeposited : valueDeposited ,
1390
+ ValueExpired : valueExpired ,
1391
+ ValueWithdrawn : valueWithdrawn ,
1392
+ ValueLoopedIn : valueLoopedIn ,
1393
+ FilteredDeposits : clientDeposits ,
1394
+ }, nil
1395
+ }
1396
+
1397
+ func (s * swapClientServer ) filterClientDeposits (deposits []* deposit.Deposit ,
1398
+ filterState clientrpc.DepositState ) ([]* clientrpc.Deposit , error ) {
1399
+
1400
+ var clientDeposits []* clientrpc.Deposit
1401
+ for _ , d := range deposits {
1402
+ if filterState != clientrpc .DepositState_EMPTY &&
1403
+ d .State != toServerState (filterState ) {
1404
+
1405
+ continue
1406
+ }
1407
+
1408
+ outpoint := wire .NewOutPoint (& d .Hash , d .Index ).String ()
1409
+ clientDeposits = append (clientDeposits , & clientrpc.Deposit {
1410
+ Id : d .ID [:],
1411
+ State : toClientState (d .State ),
1412
+ Outpoint : outpoint ,
1413
+ Value : int64 (d .Value ),
1414
+ ConfirmationHeight : d .ConfirmationHeight ,
1415
+ })
1416
+ }
1417
+
1418
+ return clientDeposits , nil
1419
+ }
1420
+
1421
+ func toClientState (state fsm.StateType ) clientrpc.DepositState {
1422
+ switch state {
1423
+ case deposit .Deposited :
1424
+ return clientrpc .DepositState_DEPOSITED
1425
+
1426
+ case deposit .SweptExpiredDeposit :
1427
+ return clientrpc .DepositState_EXPIRED
1428
+
1429
+ case deposit .Withdrawn :
1430
+ return clientrpc .DepositState_WITHDRAWN
1431
+
1432
+ case deposit .Failed :
1433
+ return clientrpc .DepositState_FAILED_STATE
1434
+
1435
+ default :
1436
+ return clientrpc .DepositState_EMPTY
1437
+ }
1438
+ }
1439
+
1440
+ func toServerState (state clientrpc.DepositState ) fsm.StateType {
1441
+ switch state {
1442
+ case clientrpc .DepositState_DEPOSITED :
1443
+ return deposit .Deposited
1444
+
1445
+ case clientrpc .DepositState_EXPIRED :
1446
+ return deposit .SweptExpiredDeposit
1447
+
1448
+ case clientrpc .DepositState_WITHDRAWN :
1449
+ return deposit .Withdrawn
1450
+
1451
+ case clientrpc .DepositState_FAILED_STATE :
1452
+ return deposit .Failed
1453
+
1454
+ default :
1455
+ return fsm .EmptyState
1456
+ }
1457
+ }
1458
+
1322
1459
func toServerOutpoints (outpoints []* clientrpc.OutPoint ) ([]wire.OutPoint ,
1323
1460
error ) {
1324
1461
0 commit comments