Skip to content

Commit 802f510

Browse files
committed
tbd
1 parent 4e6752f commit 802f510

File tree

9 files changed

+873
-280
lines changed

9 files changed

+873
-280
lines changed

cmd/loop/staticaddr.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var staticAddressCommands = cli.Command{
2222
newStaticAddressCommand,
2323
listUnspentCommand,
2424
withdrawalCommand,
25+
summaryCommand,
2526
},
2627
}
2728

@@ -183,6 +184,41 @@ func withdraw(ctx *cli.Context) error {
183184
return nil
184185
}
185186

187+
var summaryCommand = cli.Command{
188+
Name: "summary",
189+
ShortName: "s",
190+
Usage: "Display a summary of static address related data.",
191+
Description: `
192+
Displays various static address related data. Utxos, Deposits,
193+
Withdrawls, loop-ins...
194+
`,
195+
Action: summary,
196+
}
197+
198+
func summary(ctx *cli.Context) error {
199+
ctxb := context.Background()
200+
if ctx.NArg() > 0 {
201+
return cli.ShowCommandHelp(ctx, "summary")
202+
}
203+
204+
client, cleanup, err := getClient(ctx)
205+
if err != nil {
206+
return err
207+
}
208+
defer cleanup()
209+
210+
resp, err := client.GetStaticAddressSummary(
211+
ctxb, &looprpc.StaticAddressSummaryRequest{},
212+
)
213+
if err != nil {
214+
return err
215+
}
216+
217+
printRespJSON(resp)
218+
219+
return nil
220+
}
221+
186222
func utxosToOutpoints(utxos []string) ([]*looprpc.OutPoint, error) {
187223
var outpoints []*looprpc.OutPoint
188224
if len(utxos) == 0 {

loopd/perms/perms.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ var RequiredPermissions = map[string][]bakery.Op{
9090
Entity: "loop",
9191
Action: "in",
9292
}},
93+
"/looprpc.SwapClient/GetStaticAddressSummary": {{
94+
Entity: "swap",
95+
Action: "read",
96+
}, {
97+
Entity: "loop",
98+
Action: "in",
99+
}},
93100
"/looprpc.SwapClient/GetLsatTokens": {{
94101
Entity: "auth",
95102
Action: "read",

loopd/swapclient_server.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
looprpc "github.com/lightninglabs/loop/swapserverrpc"
3333
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
3434
"github.com/lightningnetwork/lnd/lntypes"
35+
"github.com/lightningnetwork/lnd/lnwallet"
3536
"github.com/lightningnetwork/lnd/queue"
3637
"github.com/lightningnetwork/lnd/routing/route"
3738
"github.com/lightningnetwork/lnd/zpay32"
@@ -1319,6 +1320,99 @@ 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 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+
13221416
func toServerOutpoints(outpoints []*clientrpc.OutPoint) ([]wire.OutPoint,
13231417
error) {
13241418

0 commit comments

Comments
 (0)