mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-13 10:21:37 +02:00
lnrpc: extract sendtoroute unmarshall to method
This commit is contained in:
parent
5d33d7226c
commit
5a4951affd
40
rpcserver.go
40
rpcserver.go
@ -2565,13 +2565,28 @@ func (r *rpcServer) SendToRoute(stream lnrpc.Lightning_SendToRouteServer) error
|
|||||||
|
|
||||||
graph := r.server.chanDB.ChannelGraph()
|
graph := r.server.chanDB.ChannelGraph()
|
||||||
|
|
||||||
|
return unmarshallSendToRouteRequest(req, graph)
|
||||||
|
},
|
||||||
|
send: func(r *lnrpc.SendResponse) error {
|
||||||
|
// Calling stream.Send concurrently is not safe.
|
||||||
|
lock.Lock()
|
||||||
|
defer lock.Unlock()
|
||||||
|
return stream.Send(r)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// unmarshallSendToRouteRequest unmarshalls an rpc sendtoroute request
|
||||||
|
func unmarshallSendToRouteRequest(req *lnrpc.SendToRouteRequest,
|
||||||
|
graph *channeldb.ChannelGraph) (*rpcPaymentRequest, error) {
|
||||||
|
|
||||||
if len(req.Routes) == 0 {
|
if len(req.Routes) == 0 {
|
||||||
return nil, fmt.Errorf("unable to send, no routes provided")
|
return nil, fmt.Errorf("unable to send, no routes provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
routes := make([]*routing.Route, len(req.Routes))
|
routes := make([]*routing.Route, len(req.Routes))
|
||||||
for i, rpcroute := range req.Routes {
|
for i, rpcroute := range req.Routes {
|
||||||
route, err := r.unmarshallRoute(rpcroute, graph)
|
route, err := unmarshallRoute(rpcroute, graph)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -2584,14 +2599,6 @@ func (r *rpcServer) SendToRoute(stream lnrpc.Lightning_SendToRouteServer) error
|
|||||||
},
|
},
|
||||||
routes: routes,
|
routes: routes,
|
||||||
}, nil
|
}, nil
|
||||||
},
|
|
||||||
send: func(r *lnrpc.SendResponse) error {
|
|
||||||
// Calling stream.Send concurrently is not safe.
|
|
||||||
lock.Lock()
|
|
||||||
defer lock.Unlock()
|
|
||||||
return stream.Send(r)
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// rpcPaymentIntent is a small wrapper struct around the of values we can
|
// rpcPaymentIntent is a small wrapper struct around the of values we can
|
||||||
@ -3027,21 +3034,12 @@ func (r *rpcServer) SendToRouteSync(ctx context.Context,
|
|||||||
|
|
||||||
graph := r.server.chanDB.ChannelGraph()
|
graph := r.server.chanDB.ChannelGraph()
|
||||||
|
|
||||||
routes := make([]*routing.Route, len(req.Routes))
|
paymentRequest, err := unmarshallSendToRouteRequest(req, graph)
|
||||||
for i, route := range req.Routes {
|
|
||||||
route, err := r.unmarshallRoute(route, graph)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
routes[i] = route
|
|
||||||
}
|
|
||||||
|
|
||||||
return r.sendPaymentSync(ctx, &rpcPaymentRequest{
|
return r.sendPaymentSync(ctx, paymentRequest)
|
||||||
SendRequest: &lnrpc.SendRequest{
|
|
||||||
PaymentHashString: req.PaymentHashString,
|
|
||||||
},
|
|
||||||
routes: routes,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendPaymentSync is the synchronous variant of sendPayment. It will block and
|
// sendPaymentSync is the synchronous variant of sendPayment. It will block and
|
||||||
@ -4024,7 +4022,7 @@ func unmarshallHop(graph *channeldb.ChannelGraph, hop *lnrpc.Hop,
|
|||||||
|
|
||||||
// unmarshallRoute unmarshalls an rpc route. For hops that don't specify a
|
// unmarshallRoute unmarshalls an rpc route. For hops that don't specify a
|
||||||
// pubkey, the channel graph is queried.
|
// pubkey, the channel graph is queried.
|
||||||
func (r *rpcServer) unmarshallRoute(rpcroute *lnrpc.Route,
|
func unmarshallRoute(rpcroute *lnrpc.Route,
|
||||||
graph *channeldb.ChannelGraph) (*routing.Route, error) {
|
graph *channeldb.ChannelGraph) (*routing.Route, error) {
|
||||||
|
|
||||||
sourceNode, err := graph.SourceNode()
|
sourceNode, err := graph.SourceNode()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user