Onchain wallets information endpoints

This commit is contained in:
Raymond Sebetoa 2024-07-11 10:10:10 +02:00
parent d7333c87ad
commit 26bfc7d3f9
3 changed files with 33 additions and 0 deletions

View File

@ -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()

View File

@ -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()

View File

@ -62,6 +62,8 @@ fun main(args: Array<String>) =
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 }