-
Notifications
You must be signed in to change notification settings - Fork 3
fix: short channel id in connection details #1002
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
Merged
Merged
Changes from 2 commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package to.bitkit.ext | ||
|
|
||
| /** | ||
| * Decodes a BOLT short channel id into Core Lightning `block x tx x output` form | ||
| * (e.g. `777477x916x0`): block height in the high 24 bits, transaction index in the next 24, | ||
| * funding output index in the low 16. | ||
| */ | ||
| fun ULong.formattedAsShortChannelId(): String { | ||
| val blockHeight = this shr 40 | ||
| val txIndex = (this shr 16) and 0xFFFFFFu | ||
| val outputIndex = this and 0xFFFFu | ||
| return "${blockHeight}x${txIndex}x$outputIndex" | ||
| } | ||
|
|
||
| /** | ||
| * Short channel id for display. Uses the channel's own scid (open channels) and, for closed | ||
| * channels which carry none, the scid from the confidently-linked order. Null when unavailable. | ||
| */ | ||
| internal fun resolveDisplayShortChannelId(channelScid: ULong?, linkedOrderScid: String?): String? = | ||
| channelScid?.formattedAsShortChannelId() | ||
| ?: linkedOrderScid?.toULongOrNull()?.formattedAsShortChannelId() | ||
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,61 @@ | ||
| package to.bitkit.ext | ||
|
|
||
| import org.junit.Test | ||
| import to.bitkit.test.BaseUnitTest | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertNull | ||
|
|
||
| class ShortChannelIdTest : BaseUnitTest() { | ||
|
|
||
| @Test | ||
| fun `formattedAsShortChannelId formats lnd scid into cln form`() { | ||
| // The two formats the issue calls out (LND uint64 and CLN block x tx x output) | ||
| // are two encodings of the same channel. | ||
| assertEquals("777477x916x0", 854_845_001_888_432_128uL.formattedAsShortChannelId()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `formattedAsShortChannelId formats from components`() { | ||
| val scid = (700_000uL shl 40) or (1uL shl 16) or 2uL | ||
| assertEquals("700000x1x2", scid.formattedAsShortChannelId()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `formattedAsShortChannelId formats zero as all zeroes`() { | ||
| assertEquals("0x0x0", 0uL.formattedAsShortChannelId()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `formattedAsShortChannelId keeps max components in their fields`() { | ||
| val scid = (0xFFFFFFuL shl 40) or (0xFFFFFFuL shl 16) or 0xFFFFuL | ||
| assertEquals("16777215x16777215x65535", scid.formattedAsShortChannelId()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `resolveDisplayShortChannelId prefers channel scid for open channel`() { | ||
| val result = resolveDisplayShortChannelId( | ||
| channelScid = 854_845_001_888_432_128uL, | ||
| linkedOrderScid = "0", | ||
| ) | ||
| assertEquals("777477x916x0", result) | ||
| } | ||
|
|
||
| @Test | ||
| fun `resolveDisplayShortChannelId falls back to linked order scid for closed channel`() { | ||
| val result = resolveDisplayShortChannelId( | ||
| channelScid = null, | ||
| linkedOrderScid = "854845001888432128", | ||
| ) | ||
| assertEquals("777477x916x0", result) | ||
| } | ||
|
|
||
| @Test | ||
| fun `resolveDisplayShortChannelId returns null when both unavailable`() { | ||
| assertNull(resolveDisplayShortChannelId(channelScid = null, linkedOrderScid = null)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `resolveDisplayShortChannelId returns null for non-numeric order scid`() { | ||
| assertNull(resolveDisplayShortChannelId(channelScid = null, linkedOrderScid = "not-a-number")) | ||
| } | ||
| } |
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 @@ | ||
| Connection Details now shows the short channel ID for Lightning connections instead of the long internal channel ID. |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.