diff --git a/loopd/daemon.go b/loopd/daemon.go index 803ab92..adca452 100644 --- a/loopd/daemon.go +++ b/loopd/daemon.go @@ -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), diff --git a/loopd/perms/perms.go b/loopd/perms/perms.go index 5c8f432..0179e30 100644 --- a/loopd/perms/perms.go +++ b/loopd/perms/perms.go @@ -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", diff --git a/loopd/swapclient_server.go b/loopd/swapclient_server.go index d63ec55..628ebaa 100644 --- a/loopd/swapclient_server.go +++ b/loopd/swapclient_server.go @@ -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,