-
Notifications
You must be signed in to change notification settings - Fork 1
Implement the findroute, findroutetonode and findroutebetweennodes commands
#21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mohitk108
wants to merge
4
commits into
ACINQ:master
Choose a base branch
from
mohitk108:routes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,66 @@ | ||
| package commands | ||
|
|
||
| import IResultWriter | ||
| import api.IEclairClientBuilder | ||
| import arrow.core.flatMap | ||
| import kotlinx.cli.ArgType | ||
| import kotlinx.coroutines.runBlocking | ||
| import types.FindRouteResponse | ||
| import types.Serialization | ||
|
|
||
| class FindRouteToNodeCommand( | ||
| private val resultWriter: IResultWriter, | ||
| private val eclairClientBuilder: IEclairClientBuilder | ||
| ) : BaseCommand( | ||
| "findroutetonode", | ||
| "Finds a route to the given node." | ||
| ) { | ||
| private val nodeId by option( | ||
| ArgType.String, | ||
| description = "The destination of the route" | ||
| ) | ||
| private val amountMsat by option( | ||
| ArgType.Int, | ||
| description = "The amount that should go through the route" | ||
| ) | ||
| private val ignoreNodeIds by option( | ||
| ArgType.String, | ||
| description = "A list of nodes to exclude from path-finding" | ||
| ) | ||
| private val ignoreShortChannelIds by option( | ||
| ArgType.String, | ||
| description = "A list of channels to exclude from path-finding" | ||
| ) | ||
| private val format by option( | ||
| ArgType.String, | ||
| description = "Format that will be used for the resulting route" | ||
| ) | ||
| private val maxFeeMsat by option( | ||
| ArgType.Int, | ||
| description = "Maximum fee allowed for this payment" | ||
| ) | ||
| private val includeLocalChannelCost by option( | ||
| ArgType.Boolean, | ||
| description = "If true, the relay fees of local channels will be counted" | ||
| ) | ||
| private val pathFindingExperimentName by option( | ||
| ArgType.String, | ||
| description = "Name of the path-finding configuration that should be used" | ||
| ) | ||
|
|
||
| override fun execute() = runBlocking { | ||
| val eclairClient = eclairClientBuilder.build(host, password) | ||
| val result = eclairClient.findroutetonode( | ||
| nodeId!!, | ||
| amountMsat!!, | ||
| ignoreNodeIds?.split(","), | ||
| ignoreShortChannelIds?.split(","), | ||
| format, | ||
| maxFeeMsat, | ||
| includeLocalChannelCost, | ||
| pathFindingExperimentName | ||
| ).flatMap { apiResponse -> Serialization.decode<FindRouteResponse>(apiResponse) } | ||
| .map { decoded -> Serialization.encode(decoded) } | ||
| resultWriter.write(result) | ||
| } | ||
| } |
This file contains hidden or 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,63 @@ | ||
| package commands | ||
|
|
||
| import api.IEclairClientBuilder | ||
| import kotlinx.cli.ArgParser | ||
| import kotlinx.cli.ExperimentalCli | ||
| import kotlinx.serialization.json.Json | ||
| import mocks.DummyEclairClient | ||
| import mocks.DummyResultWriter | ||
| import mocks.FailingEclairClient | ||
| import types.ApiError | ||
| import types.FindRouteResponse | ||
| import kotlin.test.* | ||
|
|
||
| @OptIn(ExperimentalCli::class) | ||
| class FindRouteToNodeTestCommandTest { | ||
| private fun runTest(eclairClient: IEclairClientBuilder): DummyResultWriter { | ||
| val resultWriter = DummyResultWriter() | ||
| val command = FindRouteToNodeCommand(resultWriter, eclairClient) | ||
| val parser = ArgParser("test") | ||
| parser.subcommands(command) | ||
| parser.parse( | ||
| arrayOf( | ||
| "findroutetonode", | ||
| "-p", | ||
| "password", | ||
| "--nodeId", | ||
| "02f666711319435b7905dd77d10c269d8d50c02668b975f526577167d370b50a3e", | ||
| "--amountMsat", | ||
| "1000" | ||
| ) | ||
| ) | ||
| return resultWriter | ||
| } | ||
|
|
||
| @Test | ||
| fun `successful request`() { | ||
| val resultWriter = | ||
| runTest(DummyEclairClient(findroutetonodeResponse = DummyEclairClient.validFindRouteToNodeResponse)) | ||
| assertNull(resultWriter.lastError) | ||
| assertNotNull(resultWriter.lastResult) | ||
| val format = Json { ignoreUnknownKeys = true } | ||
| assertEquals( | ||
| format.decodeFromString(FindRouteResponse.serializer(), DummyEclairClient.validFindRouteToNodeResponse), | ||
| format.decodeFromString(FindRouteResponse.serializer(), resultWriter.lastResult!!), | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `api error`() { | ||
| val error = ApiError(42, "test failure message") | ||
| val resultWriter = runTest(FailingEclairClient(error)) | ||
| assertNull(resultWriter.lastResult) | ||
| assertEquals(error, resultWriter.lastError) | ||
| } | ||
|
|
||
| @Test | ||
| fun `serialization error`() { | ||
| val resultWriter = runTest(DummyEclairClient(findroutetonodeResponse = "{invalidJson}")) | ||
| assertNull(resultWriter.lastResult) | ||
| assertNotNull(resultWriter.lastError) | ||
| assertTrue(resultWriter.lastError!!.message.contains("api response could not be parsed")) | ||
| } | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're only testing the case where
format=nodeId, you need to also test theformat=shortChannelIdandformat=fullcases.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll cover them soon.