Files
gudari/app/src/main/java/com/bitcointxoko/gudariwallet/api/LNbitsApi.kt
T
2026-06-12 12:14:01 +02:00

207 lines
6.5 KiB
Kotlin

package com.bitcointxoko.gudariwallet.api
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Path
import retrofit2.http.Query
import retrofit2.http.Url
interface LNbitsApi {
/** GET /api/v1/wallet — returns balance and wallet info */
@GET("api/v1/wallet")
suspend fun getWallet(
@Header("X-Api-Key") invoiceKey: String
): WalletResponse
/** POST /api/v1/payments — creates a BOLT-11 invoice */
@POST("api/v1/payments")
suspend fun createInvoice(
@Header("X-Api-Key") apiKey: String,
@Body request: CreateInvoiceRequest
): CreateInvoiceResponse
/**
* GET /api/v1/payments/{checking_id}
* Returns paid status and details for a specific payment hash.
* Auth: invoice key is sufficient.
*/
@GET("api/v1/payments/{checking_id}")
suspend fun checkPayment(
@Header("X-Api-Key") apiKey: String,
@Path("checking_id") checkingId: String
): PaymentStatusResponse
/** POST /api/v1/payments/pay — pays a BOLT-11 invoice */
@POST("api/v1/payments")
suspend fun payInvoice(
@Header("X-Api-Key") adminKey: String,
@Body request: PayInvoiceRequest
): PayInvoiceResponse
/** GET /api/v1/payments — returns payment history */
// @GET("api/v1/payments")
// suspend fun getPayments(
// @Header("X-Api-Key") apiKey: String
// ): List<WsPayment>
/** GET /api/v1/payments/paginated — returns bulk payment history */
@GET("api/v1/payments/paginated")
suspend fun getPaymentsPaginated(
@Header("X-Api-Key") apiKey : String,
@Query("offset") offset : Int,
@Query("limit") limit : Int
): PaginatedPaymentsResponse
/** POST /api/v1/payments/decode — returns decoded payment request */
@POST("api/v1/payments/decode")
suspend fun decodeInvoice(
@Header("X-Api-Key") invoiceKey: String,
@Body request: DecodeInvoiceRequest
): DecodeInvoiceResponse
// Unified scanner — accepts LNURL, Lightning Address, OR bolt11
@GET("api/v1/lnurlscan/{code}")
suspend fun lnurlScan(
@Header("X-Api-Key") invoiceKey: String,
@Path("code") code: String
): LnurlScanResponse
// Pay an LNURL-pay (after scanning)
@POST("api/v1/payments/lnurl")
suspend fun payLnurl(
@Header("X-Api-Key") adminKey: String,
@Body body: PayLnurlRequest
): PayLnurlResponse
// LNURL-withdraw callback (dynamic URL, per LUD-03)
@GET
suspend fun withdrawCallback(
@Url url: String
): WithdrawCallbackResponse
// Direct fetch of a raw LNURL metadata URL (LUD-17: lnurlp://, lnurlw://)
@GET
suspend fun fetchLnurlMetadata(
@Url url: String
): LnurlScanResponse
/**
* GET {callback}?amount={msat}&comment={comment}
* Fetches a BOLT-11 invoice from an LNURL-pay callback URL directly.
* This is a raw @Url call — bypasses LNbits server-side proxy entirely.
*/
@GET
suspend fun fetchLnurlCallback(
@Url url: String
): LnurlCallbackResponse
/**
* GET /lnurlp/api/v1/links?all_wallets=false
* Returns all LNURLp pay links for the current wallet.
* Auth: invoice key is sufficient.
*/
@GET("lnurlp/api/v1/links")
suspend fun getLnurlpLinks(
@Header("X-Api-Key") invoiceKey: String,
@Query("all_wallets") allWallets: Boolean = false
): List<LnurlpLink>
// Get historical payments
@GET("api/v1/payments")
suspend fun getPayments(
@Header("X-Api-Key") invoiceKey: String,
@Query("limit") limit: Int,
@Query("offset") offset: Int
): List<PaymentRecord>
// Get payment detail
@GET("api/v1/payments/{checking_id}")
suspend fun getPaymentDetail(
@Header("X-Api-Key") invoiceKey: String,
@Path("checking_id") checkingId: String
): PaymentDetailResponse
/**
* Returns the current BTC price in [currency].
* Example: GET /api/v1/rate/USD → {"rate": 43250.50}
* No X-Api-Key header needed.
*/
@GET("api/v1/rate/{currency}")
suspend fun getFiatRate(
@Path("currency") currency: String
): FiatRateResponse
/**
* Returns the list of supported ISO 4217 currency codes.
* Example: GET /api/v1/currencies → ["USD","EUR","GBP",...]
* No X-Api-Key header needed.
*/
@GET("api/v1/currencies")
suspend fun getSupportedCurrencies(): List<String>
// ── NWC Provider ──────────────────────────────────────────────────────────
@GET("nwcprovider/api/v1/permissions")
suspend fun getNwcPermissions(
@Header("X-Api-Key") invoiceKey: String
): Map<String, Any>
@GET("nwcprovider/api/v1/nwc")
suspend fun getNwcKeys(
@Header("X-Api-Key") adminKey: String,
@Query("include_expired") includeExpired: Boolean = false
): List<NwcGetResponse>
@GET("nwcprovider/api/v1/nwc/{pubkey}")
suspend fun getNwcKey(
@Header("X-Api-Key") adminKey: String,
@Path("pubkey") pubkey: String,
@Query("include_expired") includeExpired: Boolean = false,
@Query("refresh_last_used") refreshLastUsed: Boolean = false
): NwcGetResponse
@PUT("nwcprovider/api/v1/nwc/{pubkey}")
suspend fun registerNwcKey(
@Header("X-Api-Key") adminKey: String,
@Path("pubkey") pubkey: String,
@Body request: NwcRegistrationRequest
): NwcGetResponse
@DELETE("nwcprovider/api/v1/nwc/{pubkey}")
suspend fun deleteNwcKey(
@Header("X-Api-Key") adminKey: String,
@Path("pubkey") pubkey: String
)
@GET("nwcprovider/api/v1/pairing/{secret}")
suspend fun getNwcPairingUrl(
@Header("X-Api-Key") invoiceKey: String,
@Path("secret") secret: String
): String
@GET("nwcprovider/api/v1/config")
suspend fun getNwcConfig(
@Header("X-Api-Key") adminKey: String
): Map<String, Any>
@GET("nwcprovider/api/v1/config/{key}")
suspend fun getNwcConfigValue(
@Header("X-Api-Key") adminKey: String,
@Path("key") key: String
): Map<String, Any>
@POST("nwcprovider/api/v1/config")
suspend fun setNwcConfig(
@Header("X-Api-Key") adminKey: String,
@Body config: Map<String, Any>
): Map<String, Any>
}