Skip to content

Commit

Permalink
Fix naming for consistency, and removed unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
dpad85 committed Sep 20, 2024
1 parent 231ea8f commit 9405932
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package fr.acinq.lightning.bin.db.payments

import fr.acinq.bitcoin.TxId
import fr.acinq.lightning.bin.db.payments.liquidityads.PurchaseData
import fr.acinq.lightning.bin.db.payments.liquidityads.PurchaseData.Companion.encodeForDb
import fr.acinq.lightning.bin.db.payments.liquidityads.PurchaseData.Companion.encodeAsDb
import fr.acinq.lightning.db.InboundLiquidityOutgoingPayment
import fr.acinq.lightning.utils.UUID
import fr.acinq.lightning.utils.sat
Expand All @@ -40,7 +40,7 @@ class InboundLiquidityQueries(val database: PhoenixDatabase) {
is LiquidityAds.Purchase.Standard -> "STANDARD"
is LiquidityAds.Purchase.WithFeeCredit -> "WITH_FEE_CREDIT"
},
lease_blob = payment.purchase.encodeForDb(),
lease_blob = payment.purchase.encodeAsDb(),
payment_details_type = when (payment.purchase.paymentDetails) {
is LiquidityAds.PaymentDetails.FromChannelBalance -> "FROM_CHANNEL_BALANCE"
is LiquidityAds.PaymentDetails.FromFutureHtlc -> "FROM_FUTURE_HTLC"
Expand Down Expand Up @@ -94,7 +94,7 @@ class InboundLiquidityQueries(val database: PhoenixDatabase) {
miningFees = mining_fees_sat.sat,
channelId = channel_id.toByteVector32(),
txId = TxId(tx_id),
purchase = PurchaseData.decodeDataToCanonical(lease_type, lease_blob),
purchase = PurchaseData.decodeAsCanonical(lease_type, lease_blob),
createdAt = created_at,
confirmedAt = confirmed_at,
lockedAt = locked_at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
*/

@file:UseSerializers(
ByteVectorSerializer::class,
ByteVector32Serializer::class,
ByteVector64Serializer::class,
SatoshiSerializer::class,
MilliSatoshiSerializer::class
)

package fr.acinq.lightning.bin.db.payments.liquidityads
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 ACINQ SAS
* Copyright 2024 ACINQ SAS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,34 +15,23 @@
*/

@file:UseSerializers(
ByteVectorSerializer::class,
ByteVector32Serializer::class,
ByteVector64Serializer::class,
SatoshiSerializer::class,
MilliSatoshiSerializer::class
)

package fr.acinq.lightning.bin.db.payments.liquidityads

import fr.acinq.bitcoin.ByteVector
import fr.acinq.bitcoin.ByteVector32
import fr.acinq.bitcoin.ByteVector64
import fr.acinq.bitcoin.Satoshi
import fr.acinq.lightning.MilliSatoshi
import fr.acinq.lightning.bin.db.payments.DbTypesHelper
import fr.acinq.lightning.bin.db.payments.liquidityads.PaymentDetailsData.Companion.asCanonical
import fr.acinq.lightning.bin.db.payments.liquidityads.PaymentDetailsData.Companion.asDb
import fr.acinq.lightning.bin.db.serializers.v1.ByteVectorSerializer
import fr.acinq.lightning.bin.db.serializers.v1.ByteVector32Serializer
import fr.acinq.lightning.bin.db.serializers.v1.ByteVector64Serializer
import fr.acinq.lightning.bin.db.serializers.v1.SatoshiSerializer
import fr.acinq.lightning.bin.db.serializers.v1.MilliSatoshiSerializer
import fr.acinq.lightning.bin.db.serializers.v1.*
import fr.acinq.lightning.wire.LiquidityAds
import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlin.text.toByteArray


sealed class PurchaseData {
Expand Down Expand Up @@ -102,7 +91,7 @@ sealed class PurchaseData {
* @param typeVersion only used for the legacy leased data, where the blob did not contain the type of the object.
*/
@Suppress("DEPRECATION")
fun decodeDataToCanonical(
fun decodeAsCanonical(
typeVersion: String,
blob: ByteArray,
): LiquidityAds.Purchase = DbTypesHelper.decodeBlob(blob) { json, format ->
Expand All @@ -112,6 +101,6 @@ sealed class PurchaseData {
}
}

fun LiquidityAds.Purchase.encodeForDb(): ByteArray = Json.encodeToString(this.asDb()).toByteArray(Charsets.UTF_8)
fun LiquidityAds.Purchase.encodeAsDb(): ByteArray = Json.encodeToString(this.asDb()).toByteArray(Charsets.UTF_8)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import fr.acinq.lightning.bin.db.payments.liquidityads.InboundLiquidityPurchaseType;

-- Stores in a flat row payments standing for an inbound liquidity request (which are done through a splice).
-- The purchase data are stored in a complex column, as a json-encoded blob. See InboundLiquidityLeaseType file.
--
Expand Down
5 changes: 0 additions & 5 deletions src/commonMain/sqldelight/phoenixdb/migrations/2.sqm
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import fr.acinq.lightning.bin.db.payments.liquidityads.InboundLiquidityPaymentDetailsType;

-- Migration: v2 -> v3
--
-- With the new on-the-fly channel funding, the liquidity purchase data contain a payment details type that is stored in new columns.
--
-- Changes:
-- * Added column [payment_details_type] in table [inbound_liquidity_outgoing_payments]
-- * Added column [payment_details_blob] in table [inbound_liquidity_outgoing_payments]

ALTER TABLE inbound_liquidity_outgoing_payments ADD COLUMN payment_details_type TEXT DEFAULT NULL;

0 comments on commit 9405932

Please sign in to comment.