From 1879130f643339e4913b1581bfbc328f065c9b2d Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 12 Feb 2018 16:29:07 -0800 Subject: [PATCH] rpc: modify QueryRoutes response to return exact number of requested routes --- rpcserver.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index fa86106b..ac74c932 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -2608,7 +2608,9 @@ func (r *rpcServer) QueryRoutes(ctx context.Context, // Query the channel router for a possible path to the destination that // can carry `in.Amt` satoshis _including_ the total fee required on // the route. - routes, err := r.server.chanRouter.FindRoutes(pubKey, amtMSat) + routes, err := r.server.chanRouter.FindRoutes( + pubKey, amtMSat, uint32(in.NumRoutes), + ) if err != nil { return nil, err } @@ -2616,10 +2618,12 @@ func (r *rpcServer) QueryRoutes(ctx context.Context, // For each valid route, we'll convert the result into the format // required by the RPC system. routeResp := &lnrpc.QueryRoutesResponse{ - Routes: make([]*lnrpc.Route, len(routes)), + Routes: make([]*lnrpc.Route, 0, in.NumRoutes), } - for i, route := range routes { - routeResp.Routes[i] = marshallRoute(route) + for i := int32(0); i < in.NumRoutes; i++ { + routeResp.Routes = append( + routeResp.Routes, marshallRoute(routes[i]), + ) } return routeResp, nil