lnrpc/routerrpc: use vertex constructor

This commit is contained in:
Joost Jager 2019-08-07 13:09:27 +02:00
parent a332990d2c
commit 6ee2c04190
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -89,15 +89,7 @@ func (r *RouterBackend) QueryRoutes(ctx context.Context,
return route.Vertex{}, err return route.Vertex{}, err
} }
if len(pubKeyBytes) != 33 { return route.NewVertexFromBytes(pubKeyBytes)
return route.Vertex{},
errors.New("invalid key length")
}
var v route.Vertex
copy(v[:], pubKeyBytes)
return v, nil
} }
// Parse the hex-encoded source and target public keys into full public // Parse the hex-encoded source and target public keys into full public
@ -134,11 +126,10 @@ func (r *RouterBackend) QueryRoutes(ctx context.Context,
ignoredNodes := make(map[route.Vertex]struct{}) ignoredNodes := make(map[route.Vertex]struct{})
for _, ignorePubKey := range in.IgnoredNodes { for _, ignorePubKey := range in.IgnoredNodes {
if len(ignorePubKey) != 33 { ignoreVertex, err := route.NewVertexFromBytes(ignorePubKey)
return nil, fmt.Errorf("invalid ignore node pubkey") if err != nil {
return nil, err
} }
var ignoreVertex route.Vertex
copy(ignoreVertex[:], ignorePubKey)
ignoredNodes[ignoreVertex] = struct{}{} ignoredNodes[ignoreVertex] = struct{}{}
} }
@ -484,12 +475,11 @@ func (r *RouterBackend) extractIntentFromSendRequest(
// from the other fields. // from the other fields.
// Payment destination. // Payment destination.
if len(rpcPayReq.Dest) != 33 { target, err := route.NewVertexFromBytes(rpcPayReq.Dest)
return nil, errors.New("invalid key length") if err != nil {
return nil, err
} }
pubBytes := rpcPayReq.Dest payIntent.Target = target
copy(payIntent.Target[:], pubBytes)
// Final payment CLTV delta. // Final payment CLTV delta.
if rpcPayReq.FinalCltvDelta != 0 { if rpcPayReq.FinalCltvDelta != 0 {