Skip to content
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

Correctly handle ₿ prefix in BIP353 #70

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ kotlin {
implementation("app.cash.sqldelight:coroutines-extensions:${Versions.sqlDelight}")
}
}
commonTest {
dependencies {
implementation(kotlin("test"))
}
}
jvmMain {
dependencies {
implementation("app.cash.sqldelight:sqlite-driver:${Versions.sqlDelight}")
Expand Down
7 changes: 6 additions & 1 deletion src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ class Api(
call.respond(nodeParams.defaultOffer(peer.walletParams.trampolineNode.id).first.encode())
}
get("getlnaddress") {
call.respond(if (peer.channels.isNotEmpty()) peer.requestAddress("en") else "must have one channel")
if (peer.channels.isEmpty()) {
call.respond("must have one channel")
} else {
val address = peer.requestAddress("en")
call.respond("₿$address")
}
}
get("payments/incoming") {
val listAll = call.parameters["all"]?.toBoolean() ?: false // by default, only list incoming payments that have been received
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object Parser {
return null
}

val username = components[0].lowercase()
val username = components[0].lowercase().dropWhile { it == '₿' }
val domain = components[1]
return username to domain
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fr.acinq.lightning.bin.payments

import kotlin.test.Test
import kotlin.test.assertEquals

class ParserTestsCommon {

@Test
fun `test address parsing`() {
data class TestCase(val address: String, val user: String, val domain: String)

val testcases = listOf(
TestCase("[email protected]", "foo", "bar.com"),
TestCase("₿[email protected]", "foo", "bar.com"),
TestCase("₿₿[email protected]", "foo", "bar.com"),
)

testcases.forEach { testCase -> assertEquals(testCase.user to testCase.domain, Parser.parseEmailLikeAddress(testCase.address)) }
}
}