mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-15 03:51:23 +01:00
lnrpc: extract sendtoroute unmarshall to method
This commit is contained in:
parent
5d33d7226c
commit
5a4951affd
1 changed files with 31 additions and 33 deletions
64
rpcserver.go
64
rpcserver.go
|
@ -2565,25 +2565,7 @@ func (r *rpcServer) SendToRoute(stream lnrpc.Lightning_SendToRouteServer) error
|
||||||
|
|
||||||
graph := r.server.chanDB.ChannelGraph()
|
graph := r.server.chanDB.ChannelGraph()
|
||||||
|
|
||||||
if len(req.Routes) == 0 {
|
return unmarshallSendToRouteRequest(req, graph)
|
||||||
return nil, fmt.Errorf("unable to send, no routes provided")
|
|
||||||
}
|
|
||||||
|
|
||||||
routes := make([]*routing.Route, len(req.Routes))
|
|
||||||
for i, rpcroute := range req.Routes {
|
|
||||||
route, err := r.unmarshallRoute(rpcroute, graph)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
routes[i] = route
|
|
||||||
}
|
|
||||||
|
|
||||||
return &rpcPaymentRequest{
|
|
||||||
SendRequest: &lnrpc.SendRequest{
|
|
||||||
PaymentHash: req.PaymentHash,
|
|
||||||
},
|
|
||||||
routes: routes,
|
|
||||||
}, nil
|
|
||||||
},
|
},
|
||||||
send: func(r *lnrpc.SendResponse) error {
|
send: func(r *lnrpc.SendResponse) error {
|
||||||
// Calling stream.Send concurrently is not safe.
|
// Calling stream.Send concurrently is not safe.
|
||||||
|
@ -2594,6 +2576,31 @@ func (r *rpcServer) SendToRoute(stream lnrpc.Lightning_SendToRouteServer) error
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unmarshallSendToRouteRequest unmarshalls an rpc sendtoroute request
|
||||||
|
func unmarshallSendToRouteRequest(req *lnrpc.SendToRouteRequest,
|
||||||
|
graph *channeldb.ChannelGraph) (*rpcPaymentRequest, error) {
|
||||||
|
|
||||||
|
if len(req.Routes) == 0 {
|
||||||
|
return nil, fmt.Errorf("unable to send, no routes provided")
|
||||||
|
}
|
||||||
|
|
||||||
|
routes := make([]*routing.Route, len(req.Routes))
|
||||||
|
for i, rpcroute := range req.Routes {
|
||||||
|
route, err := unmarshallRoute(rpcroute, graph)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
routes[i] = route
|
||||||
|
}
|
||||||
|
|
||||||
|
return &rpcPaymentRequest{
|
||||||
|
SendRequest: &lnrpc.SendRequest{
|
||||||
|
PaymentHash: req.PaymentHash,
|
||||||
|
},
|
||||||
|
routes: routes,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// rpcPaymentIntent is a small wrapper struct around the of values we can
|
// rpcPaymentIntent is a small wrapper struct around the of values we can
|
||||||
// receive from a client over RPC if they wish to send a payment. We'll either
|
// receive from a client over RPC if they wish to send a payment. We'll either
|
||||||
// extract these fields from a payment request (which may include routing
|
// extract these fields from a payment request (which may include routing
|
||||||
|
@ -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 {
|
if err != nil {
|
||||||
route, err := r.unmarshallRoute(route, graph)
|
return nil, err
|
||||||
if err != nil {
|
|
||||||
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…
Add table
Reference in a new issue