-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'shortChannelId' output format for findroute* API calls (#1943)
Add new --format parameter to the findRoute* API calls. This lets the caller decide whether they want to receive a list of nodeIds or shortChannelIds to identify the route. Co-authored-by: Pierre-Marie Padiou <[email protected]>
- Loading branch information
Showing
5 changed files
with
164 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
eclair-node/src/main/scala/fr/acinq/eclair/api/directives/RouteFormat.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2021 ACINQ SAS | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package fr.acinq.eclair.api.directives | ||
|
||
import fr.acinq.eclair.router.Router.RouteResponse | ||
|
||
// @formatter:off | ||
sealed trait RouteFormat | ||
case object NodeIdRouteFormat extends RouteFormat | ||
case object ShortChannelIdRouteFormat extends RouteFormat | ||
// @formatter:on | ||
|
||
object RouteFormat { | ||
|
||
val NODE_ID = "nodeId" | ||
val SHORT_CHANNEL_ID = "shortChannelId" | ||
|
||
def fromString(s: String): RouteFormat = s match { | ||
case NODE_ID => NodeIdRouteFormat | ||
case SHORT_CHANNEL_ID => ShortChannelIdRouteFormat | ||
case _ => throw new IllegalArgumentException(s"invalid route format, possible values are ($NODE_ID, $SHORT_CHANNEL_ID)") | ||
} | ||
|
||
def format(route: RouteResponse, format_opt: Option[RouteFormat]): Seq[String] = format(route, format_opt.getOrElse(NodeIdRouteFormat)) | ||
|
||
def format(route: RouteResponse, format: RouteFormat): Seq[String] = format match { | ||
case NodeIdRouteFormat => | ||
val nodeIds = route.routes.head.hops match { | ||
case rest :+ last => rest.map(_.nodeId) :+ last.nodeId :+ last.nextNodeId | ||
case Nil => Nil | ||
} | ||
nodeIds.toList.map(_.toString) | ||
case ShortChannelIdRouteFormat => | ||
val shortChannelIds = route.routes.head.hops.map(_.lastUpdate.shortChannelId) | ||
shortChannelIds.map(_.toString) | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters