Skip to content

Commit 043f780

Browse files
committed
loopd: adding getInfo rpc call
1 parent 7f6f265 commit 043f780

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

loopd/daemon.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
438438

439439
// Now finally fully initialize the swap client RPC server instance.
440440
d.swapClientServer = swapClientServer{
441+
config: d.cfg,
441442
network: lndclient.Network(d.cfg.Network),
442443
impl: swapclient,
443444
liquidityMgr: getLiquidityManager(swapclient),

loopd/perms/perms.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ var RequiredPermissions = map[string][]bakery.Op{
6767
Entity: "suggestions",
6868
Action: "read",
6969
}},
70+
"/looprpc.SwapClient/GetInfo": {{
71+
Entity: "suggestions",
72+
Action: "read",
73+
}},
7074
"/looprpc.SwapClient/GetLiquidityParams": {{
7175
Entity: "suggestions",
7276
Action: "read",

loopd/swapclient_server.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type swapClientServer struct {
6868
clientrpc.UnimplementedSwapClientServer
6969
clientrpc.UnimplementedDebugServer
7070

71+
config *Config
7172
network lndclient.Network
7273
impl *loop.Client
7374
liquidityMgr *liquidity.Manager
@@ -738,6 +739,77 @@ func (s *swapClientServer) GetLsatTokens(ctx context.Context,
738739
return &clientrpc.TokensResponse{Tokens: rpcTokens}, nil
739740
}
740741

742+
// GetInfo returns basic information about the loop daemon and details to swaps
743+
// from the swap store.
744+
func (s *swapClientServer) GetInfo(_ context.Context,
745+
_ *clientrpc.GetInfoRequest) (*clientrpc.GetInfoResponse, error) {
746+
747+
// Fetch loop-outs from the loop db.
748+
outSwaps, err := s.impl.Store.FetchLoopOutSwaps()
749+
if err != nil {
750+
return nil, err
751+
}
752+
753+
// Collect loop-out stats.
754+
loopOutStats := &clientrpc.LoopStats{}
755+
for _, out := range outSwaps {
756+
switch out.State().State.Type() {
757+
case loopdb.StateTypeSuccess:
758+
loopOutStats.SuccessCount++
759+
loopOutStats.SumSucceededAmt += int64(
760+
out.Contract.AmountRequested,
761+
)
762+
763+
case loopdb.StateTypePending:
764+
loopOutStats.PendingCount++
765+
loopOutStats.SumPendingAmt += int64(
766+
out.Contract.AmountRequested,
767+
)
768+
769+
case loopdb.StateTypeFail:
770+
loopOutStats.FailCount++
771+
}
772+
}
773+
774+
// Fetch loop-ins from the loop db.
775+
inSwaps, err := s.impl.Store.FetchLoopInSwaps()
776+
if err != nil {
777+
return nil, err
778+
}
779+
780+
// Collect loop-in stats.
781+
loopInStats := &clientrpc.LoopStats{}
782+
for _, in := range inSwaps {
783+
switch in.State().State.Type() {
784+
case loopdb.StateTypeSuccess:
785+
loopInStats.SuccessCount++
786+
loopInStats.SumSucceededAmt += int64(
787+
in.Contract.AmountRequested,
788+
)
789+
790+
case loopdb.StateTypePending:
791+
loopInStats.PendingCount++
792+
loopInStats.SumPendingAmt += int64(
793+
in.Contract.AmountRequested,
794+
)
795+
796+
case loopdb.StateTypeFail:
797+
loopInStats.FailCount++
798+
}
799+
}
800+
801+
return &clientrpc.GetInfoResponse{
802+
Version: loop.Version(),
803+
Network: s.config.Network,
804+
RpcListen: s.config.RPCListen,
805+
RestListen: s.config.RESTListen,
806+
MacaroonPath: s.config.MacaroonPath,
807+
TlsCertPath: s.config.TLSCertPath,
808+
LoopOutStats: loopOutStats,
809+
LoopInStats: loopInStats,
810+
}, nil
811+
}
812+
741813
// GetLiquidityParams gets our current liquidity manager's parameters.
742814
func (s *swapClientServer) GetLiquidityParams(_ context.Context,
743815
_ *clientrpc.GetLiquidityParamsRequest) (*clientrpc.LiquidityParameters,

0 commit comments

Comments
 (0)