Skip to content

Commit

Permalink
correctly handle ₿ prefix in BIP353
Browse files Browse the repository at this point in the history
  • Loading branch information
pm47 committed Jul 12, 2024
1 parent e92062e commit d36f9f6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
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
5 changes: 4 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,10 @@ 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")
when (val address = if (peer.channels.isNotEmpty()) peer.requestAddress("en") else null) {
null -> call.respond("must have one channel")
else -> 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)) }
}
}

0 comments on commit d36f9f6

Please sign in to comment.