mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
loopd: adding getInfo rpc call
This commit is contained in:
parent
7f6f265db3
commit
043f780198
3 changed files with 77 additions and 0 deletions
|
|
@ -438,6 +438,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
|||
|
||||
// Now finally fully initialize the swap client RPC server instance.
|
||||
d.swapClientServer = swapClientServer{
|
||||
config: d.cfg,
|
||||
network: lndclient.Network(d.cfg.Network),
|
||||
impl: swapclient,
|
||||
liquidityMgr: getLiquidityManager(swapclient),
|
||||
|
|
|
|||
|
|
@ -67,6 +67,10 @@ var RequiredPermissions = map[string][]bakery.Op{
|
|||
Entity: "suggestions",
|
||||
Action: "read",
|
||||
}},
|
||||
"/looprpc.SwapClient/GetInfo": {{
|
||||
Entity: "suggestions",
|
||||
Action: "read",
|
||||
}},
|
||||
"/looprpc.SwapClient/GetLiquidityParams": {{
|
||||
Entity: "suggestions",
|
||||
Action: "read",
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ type swapClientServer struct {
|
|||
clientrpc.UnimplementedSwapClientServer
|
||||
clientrpc.UnimplementedDebugServer
|
||||
|
||||
config *Config
|
||||
network lndclient.Network
|
||||
impl *loop.Client
|
||||
liquidityMgr *liquidity.Manager
|
||||
|
|
@ -738,6 +739,77 @@ func (s *swapClientServer) GetLsatTokens(ctx context.Context,
|
|||
return &clientrpc.TokensResponse{Tokens: rpcTokens}, nil
|
||||
}
|
||||
|
||||
// GetInfo returns basic information about the loop daemon and details to swaps
|
||||
// from the swap store.
|
||||
func (s *swapClientServer) GetInfo(_ context.Context,
|
||||
_ *clientrpc.GetInfoRequest) (*clientrpc.GetInfoResponse, error) {
|
||||
|
||||
// Fetch loop-outs from the loop db.
|
||||
outSwaps, err := s.impl.Store.FetchLoopOutSwaps()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Collect loop-out stats.
|
||||
loopOutStats := &clientrpc.LoopStats{}
|
||||
for _, out := range outSwaps {
|
||||
switch out.State().State.Type() {
|
||||
case loopdb.StateTypeSuccess:
|
||||
loopOutStats.SuccessCount++
|
||||
loopOutStats.SumSucceededAmt += int64(
|
||||
out.Contract.AmountRequested,
|
||||
)
|
||||
|
||||
case loopdb.StateTypePending:
|
||||
loopOutStats.PendingCount++
|
||||
loopOutStats.SumPendingAmt += int64(
|
||||
out.Contract.AmountRequested,
|
||||
)
|
||||
|
||||
case loopdb.StateTypeFail:
|
||||
loopOutStats.FailCount++
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch loop-ins from the loop db.
|
||||
inSwaps, err := s.impl.Store.FetchLoopInSwaps()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Collect loop-in stats.
|
||||
loopInStats := &clientrpc.LoopStats{}
|
||||
for _, in := range inSwaps {
|
||||
switch in.State().State.Type() {
|
||||
case loopdb.StateTypeSuccess:
|
||||
loopInStats.SuccessCount++
|
||||
loopInStats.SumSucceededAmt += int64(
|
||||
in.Contract.AmountRequested,
|
||||
)
|
||||
|
||||
case loopdb.StateTypePending:
|
||||
loopInStats.PendingCount++
|
||||
loopInStats.SumPendingAmt += int64(
|
||||
in.Contract.AmountRequested,
|
||||
)
|
||||
|
||||
case loopdb.StateTypeFail:
|
||||
loopInStats.FailCount++
|
||||
}
|
||||
}
|
||||
|
||||
return &clientrpc.GetInfoResponse{
|
||||
Version: loop.Version(),
|
||||
Network: s.config.Network,
|
||||
RpcListen: s.config.RPCListen,
|
||||
RestListen: s.config.RESTListen,
|
||||
MacaroonPath: s.config.MacaroonPath,
|
||||
TlsCertPath: s.config.TLSCertPath,
|
||||
LoopOutStats: loopOutStats,
|
||||
LoopInStats: loopInStats,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetLiquidityParams gets our current liquidity manager's parameters.
|
||||
func (s *swapClientServer) GetLiquidityParams(_ context.Context,
|
||||
_ *clientrpc.GetLiquidityParamsRequest) (*clientrpc.LiquidityParameters,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue