@@ -32,6 +32,7 @@ import (
32
32
looprpc "github.com/lightninglabs/loop/swapserverrpc"
33
33
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
34
34
"github.com/lightningnetwork/lnd/lntypes"
35
+ "github.com/lightningnetwork/lnd/lnwallet"
35
36
"github.com/lightningnetwork/lnd/queue"
36
37
"github.com/lightningnetwork/lnd/routing/route"
37
38
"github.com/lightningnetwork/lnd/zpay32"
@@ -1319,6 +1320,99 @@ 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 string ) (* 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 .toClientDeposits (deposits )
1372
+ if err != nil {
1373
+ return nil , err
1374
+ }
1375
+
1376
+ return & clientrpc.StaticAddressSummaryResponse {
1377
+ TotalNumSwaps : uint32 (totalNumSwaps ),
1378
+ ValueUnconfirmed : valueUnconfirmed ,
1379
+ ValueDeposited : valueDeposited ,
1380
+ ValueExpired : valueExpired ,
1381
+ ValueWithdrawn : valueWithdrawn ,
1382
+ ValueLoopedIn : valueLoopedIn ,
1383
+ Deposits : clientDeposits ,
1384
+ }, nil
1385
+ }
1386
+
1387
+ func (s * swapClientServer ) toClientDeposits (deposits []* deposit.Deposit ) ([]* clientrpc.Deposit , error ) {
1388
+ var clientDeposits []* clientrpc.Deposit
1389
+ for _ , d := range deposits {
1390
+ outpoint := wire .NewOutPoint (& d .Hash , d .Index ).String ()
1391
+ clientDeposits = append (clientDeposits , & clientrpc.Deposit {
1392
+ Id : d .ID [:],
1393
+ State : string (d .State ),
1394
+ Outpoint : outpoint ,
1395
+ Value : int64 (d .Value ),
1396
+ ConfirmationHeight : d .ConfirmationHeight ,
1397
+ })
1398
+ }
1399
+
1400
+ return clientDeposits , nil
1401
+ }
1402
+
1403
+ func (s * swapClientServer ) toDeposits (deposits []* lnwallet.Utxo ) []* clientrpc.Deposit {
1404
+ var unconfirmedDeposits []* clientrpc.Deposit
1405
+ for _ , u := range deposits {
1406
+ unconfirmedDeposits = append (unconfirmedDeposits , & clientrpc.Deposit {
1407
+ State : "Unconfirmed" ,
1408
+ Outpoint : u .OutPoint .String (),
1409
+ Value : int64 (u .Value ),
1410
+ })
1411
+ }
1412
+
1413
+ return unconfirmedDeposits
1414
+ }
1415
+
1322
1416
func toServerOutpoints (outpoints []* clientrpc.OutPoint ) ([]wire.OutPoint ,
1323
1417
error ) {
1324
1418
0 commit comments