diff --git a/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt b/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt index 440c94b..ee0db36 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt @@ -22,6 +22,8 @@ import fr.acinq.lightning.channel.states.Closed import fr.acinq.lightning.channel.states.Closing import fr.acinq.lightning.channel.states.ClosingFeerates import fr.acinq.lightning.channel.states.Normal +import fr.acinq.lightning.crypto.KeyManager +import fr.acinq.lightning.crypto.div import fr.acinq.lightning.io.Peer import fr.acinq.lightning.io.WrappedChannelCommand import fr.acinq.lightning.payment.Bolt11Invoice @@ -309,6 +311,15 @@ class Api(private val nodeParams: NodeParams, private val peer: Peer, private va val walletState = wallet.walletStateFlow.value call.respond(walletState.utxos.toString()) //no serializable json structure for this } + get("/getfinalwalletinfo"){ + val finalOnChainWallet = nodeParams.keyManager.finalOnChainWallet + val path = (KeyManager.Bip84OnChainKeys.bip84BasePath(nodeParams.chain) / finalOnChainWallet.account).toString() + call.respond(FinalWalletInfo(path, finalOnChainWallet.xpub)) + } + get("/getswapinwalletinfo"){ + val swapInOnChainWallet = nodeParams.keyManager.swapInOnChainWallet + call.respond(SwapInWalletInfo(swapInOnChainWallet.legacyDescriptor, swapInOnChainWallet.publicDescriptor, swapInOnChainWallet.userPublicKey.toHex())) + } post("sendtoaddress") { val res = kotlin.runCatching { val formParameters = call.receiveParameters() diff --git a/src/commonMain/kotlin/fr/acinq/lightning/bin/json/JsonSerializers.kt b/src/commonMain/kotlin/fr/acinq/lightning/bin/json/JsonSerializers.kt index ed58a8b..24988b2 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/bin/json/JsonSerializers.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/bin/json/JsonSerializers.kt @@ -77,6 +77,13 @@ sealed class ApiType { val weaklyConfirmed: Long, val deeplyConfirmed: Long ) : ApiType() + + @Serializable + data class FinalWalletInfo(@SerialName("path") val path: String, @SerialName("xpub") val xpub: String) : ApiType() + + @Serializable + data class SwapInWalletInfo(@SerialName("legacyDescriptor") val legacyDescriptor: String, @SerialName("publicDescriptor") val publicDescriptor: String, @SerialName("userPublicKey") val userPublicKey: String) : ApiType() + @Serializable data class GeneratedInvoice(@SerialName("amountSat") val amount: Satoshi?, val paymentHash: ByteVector32, val serialized: String) : ApiType() diff --git a/src/commonMain/kotlin/fr/acinq/lightning/cli/PhoenixCli.kt b/src/commonMain/kotlin/fr/acinq/lightning/cli/PhoenixCli.kt index 632fb35..f39cb11 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/cli/PhoenixCli.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/cli/PhoenixCli.kt @@ -62,6 +62,8 @@ fun main(args: Array) = GetFinalWalletBalance(), GetSwapInWalletBalance(), GetSwapInTransactions(), + GetFinalWalletInfo(), + GetSwapInWalletInfo(), ManualSpliceIn() ) .main(args) @@ -317,6 +319,19 @@ class GetSwapInTransactions : PhoenixCliCommand(name = "getswapintransactions", } } +class GetFinalWalletInfo : PhoenixCliCommand(name = "getfinalwalletinfo", help = "Get the final wallet information", printHelpOnEmptyArgs = true) { + override suspend fun httpRequest() = commonOptions.httpClient.use { + it.get(url = commonOptions.baseUrl / "getfinalwalletinfo") + } +} + +class GetSwapInWalletInfo : PhoenixCliCommand(name = "getswapinwalletinfo", help = "Get the swap-in wallet information", printHelpOnEmptyArgs = true) { + override suspend fun httpRequest() = commonOptions.httpClient.use { + it.get(url = commonOptions.baseUrl / "getswapinwalletinfo") + } +} + + class SendToAddress : PhoenixCliCommand(name = "sendtoaddress", help = "Send to a Bitcoin address", printHelpOnEmptyArgs = true) { private val amountSat by option("--amountSat").long().required() private val address by option("--address").required().check { runCatching { Base58Check.decode(it) }.isSuccess || runCatching { Bech32.decodeWitnessAddress(it) }.isSuccess }