rpc: re-implement QueryRoute as QueryRoutes
This commit is contained in:
parent
dabaf9da70
commit
47c065b72c
@ -2123,6 +2123,7 @@ var testsCases = []*testCase{
|
|||||||
name: "multi-hop htlc error propagation",
|
name: "multi-hop htlc error propagation",
|
||||||
test: testHtlcErrorPropagation,
|
test: testHtlcErrorPropagation,
|
||||||
},
|
},
|
||||||
|
// TODO(roasbeef): multi-path integration test
|
||||||
{
|
{
|
||||||
// TODO(roasbeef): test always needs to be last as Bob's state
|
// TODO(roasbeef): test always needs to be last as Bob's state
|
||||||
// is borked since we trick him into attempting to cheat Alice?
|
// is borked since we trick him into attempting to cheat Alice?
|
||||||
|
22
rpcserver.go
22
rpcserver.go
@ -1529,7 +1529,7 @@ func (r *rpcServer) GetNodeInfo(_ context.Context, in *lnrpc.NodeInfoRequest) (*
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryRoute attempts to query the daemons' Channel Router for a possible
|
// QueryRoutes attempts to query the daemons' Channel Router for a possible
|
||||||
// route to a target destination capable of carrying a specific amount of
|
// route to a target destination capable of carrying a specific amount of
|
||||||
// satoshis within the route's flow. The retuned route contains the full
|
// satoshis within the route's flow. The retuned route contains the full
|
||||||
// details required to craft and send an HTLC, also including the necessary
|
// details required to craft and send an HTLC, also including the necessary
|
||||||
@ -1538,7 +1538,9 @@ func (r *rpcServer) GetNodeInfo(_ context.Context, in *lnrpc.NodeInfoRequest) (*
|
|||||||
//
|
//
|
||||||
// TODO(roasbeef): should return a slice of routes in reality
|
// TODO(roasbeef): should return a slice of routes in reality
|
||||||
// * create separate PR to send based on well formatted route
|
// * create separate PR to send based on well formatted route
|
||||||
func (r *rpcServer) QueryRoute(_ context.Context, in *lnrpc.RouteRequest) (*lnrpc.Route, error) {
|
func (r *rpcServer) QueryRoutes(_ context.Context,
|
||||||
|
in *lnrpc.QueryRoutesRequest) (*lnrpc.QueryRoutesResponse, error) {
|
||||||
|
|
||||||
// First parse the hex-encdoed public key into a full public key objet
|
// First parse the hex-encdoed public key into a full public key objet
|
||||||
// we can properly manipulate.
|
// we can properly manipulate.
|
||||||
pubKeyBytes, err := hex.DecodeString(in.PubKey)
|
pubKeyBytes, err := hex.DecodeString(in.PubKey)
|
||||||
@ -1553,16 +1555,22 @@ func (r *rpcServer) QueryRoute(_ context.Context, in *lnrpc.RouteRequest) (*lnrp
|
|||||||
// 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.
|
||||||
route, err := r.server.chanRouter.FindRoute(pubKey,
|
routes, err := r.server.chanRouter.FindRoutes(pubKey,
|
||||||
btcutil.Amount(in.Amt))
|
btcutil.Amount(in.Amt))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a route exists within the network that is able to support our
|
// For each valid route, we'll convert the result into the format
|
||||||
// request, then we'll convert the result into the format required by
|
// required by the RPC system.
|
||||||
// the RPC system.
|
routeResp := &lnrpc.QueryRoutesResponse{
|
||||||
return marshalRoute(route), nil
|
Routes: make([]*lnrpc.Route, len(routes)),
|
||||||
|
}
|
||||||
|
for i, route := range routes {
|
||||||
|
routeResp.Routes[i] = marshalRoute(route)
|
||||||
|
}
|
||||||
|
|
||||||
|
return routeResp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func marshalRoute(route *routing.Route) *lnrpc.Route {
|
func marshalRoute(route *routing.Route) *lnrpc.Route {
|
||||||
|
Loading…
Reference in New Issue
Block a user