rpc: modify QueryRoutes response to return exact number of requested routes

This commit is contained in:
Olaoluwa Osuntokun 2018-02-12 16:29:07 -08:00
parent eddca9bf92
commit 1879130f64
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
1 changed files with 8 additions and 4 deletions

View File

@ -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