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

@ -2608,7 +2608,9 @@ func (r *rpcServer) QueryRoutes(ctx context.Context,
// Query the channel router for a possible path to the destination that // Query the channel router for a possible path to the destination that
// can carry `in.Amt` satoshis _including_ the total fee required on // can carry `in.Amt` satoshis _including_ the total fee required on
// the route. // the route.
routes, err := r.server.chanRouter.FindRoutes(pubKey, amtMSat) routes, err := r.server.chanRouter.FindRoutes(
pubKey, amtMSat, uint32(in.NumRoutes),
)
if err != nil { if err != nil {
return nil, err 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 // For each valid route, we'll convert the result into the format
// required by the RPC system. // required by the RPC system.
routeResp := &lnrpc.QueryRoutesResponse{ routeResp := &lnrpc.QueryRoutesResponse{
Routes: make([]*lnrpc.Route, len(routes)), Routes: make([]*lnrpc.Route, 0, in.NumRoutes),
} }
for i, route := range routes { for i := int32(0); i < in.NumRoutes; i++ {
routeResp.Routes[i] = marshallRoute(route) routeResp.Routes = append(
routeResp.Routes, marshallRoute(routes[i]),
)
} }
return routeResp, nil return routeResp, nil