diff --git a/build.gradle.kts b/build.gradle.kts index 0a1a0d1..c8165fa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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}") diff --git a/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt b/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt index c3f1210..92feded 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt @@ -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 diff --git a/src/commonMain/kotlin/fr/acinq/lightning/bin/payments/Parser.kt b/src/commonMain/kotlin/fr/acinq/lightning/bin/payments/Parser.kt index 7c82b6a..36e257d 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/bin/payments/Parser.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/bin/payments/Parser.kt @@ -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 } diff --git a/src/commonTest/kotlin/fr/acinq/lightning/bin/payments/ParserTestsCommon.kt b/src/commonTest/kotlin/fr/acinq/lightning/bin/payments/ParserTestsCommon.kt new file mode 100644 index 0000000..e0eaf68 --- /dev/null +++ b/src/commonTest/kotlin/fr/acinq/lightning/bin/payments/ParserTestsCommon.kt @@ -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("foo@bar.com", "foo", "bar.com"), + TestCase("₿foo@bar.com", "foo", "bar.com"), + TestCase("₿₿foo@bar.com", "foo", "bar.com"), + ) + + testcases.forEach { testCase -> assertEquals(testCase.user to testCase.domain, Parser.parseEmailLikeAddress(testCase.address)) } + } +} \ No newline at end of file