payments/migration1: freeze core payment code
Copy the core payments/db code into payments/db/migration1 and add the required sqlc-generated types/queries from sqldb/sqlc. This effectively freezes the migration code so it stays robust against future query or schema changes in the main payments package. Replace the delegation to channeldb.ReadElement/WriteElement with self-contained, frozen implementations that only handle the exact types required by this migration package. This removes the dependency on the live channeldb codec so that future changes to channeldb serialization cannot silently corrupt or break the migration. UnknownElementType is also defined locally for the same reason.
This commit is contained in:
17 files changed
+7992
No files matched your search
@@ -0,0 +1,31 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.29.0
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
|
||||
PrepareContext(context.Context, string) (*sql.Stmt, error)
|
||||
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
|
||||
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// GetTx returns the underlying DBTX (either *sql.DB or *sql.Tx) used by the
|
||||
// Queries struct.
|
||||
func (q *Queries) GetTx() DBTX {
|
||||
return q.db
|
||||
}
|
||||
|
||||
// makeQueryParams generates a string of query parameters for a SQL query. It is
|
||||
// meant to replace the `?` placeholders in a SQL query with numbered parameters
|
||||
// like `$1`, `$2`, etc. This is required for the sqlc /*SLICE:<field_name>*/
|
||||
// workaround. See scripts/gen_sqlc_docker.sh for more details.
|
||||
func makeQueryParams(numTotalArgs, numListArgs int) string {
|
||||
if numListArgs == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
var b strings.Builder
|
||||
|
||||
// Pre-allocate a rough estimation of the buffer size to avoid
|
||||
// re-allocations. A parameter like $1000, takes 6 bytes.
|
||||
b.Grow(numListArgs * 6)
|
||||
|
||||
diff := numTotalArgs - numListArgs
|
||||
for i := 0; i < numListArgs; i++ {
|
||||
if i > 0 {
|
||||
// We don't need to check the error here because the
|
||||
// WriteString method of strings.Builder always returns
|
||||
// nil.
|
||||
_, _ = b.WriteString(",")
|
||||
}
|
||||
|
||||
// We don't need to check the error here because the
|
||||
// Write method (called by fmt.Fprintf) of strings.Builder
|
||||
// always returns nil.
|
||||
_, _ = fmt.Fprintf(&b, "$%d", i+diff+1)
|
||||
}
|
||||
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// PaymentAndIntent is an interface that provides access to a payment and its
|
||||
// associated payment intent.
|
||||
type PaymentAndIntent interface {
|
||||
// GetPayment returns the Payment associated with this interface.
|
||||
GetPayment() Payment
|
||||
|
||||
// GetPaymentIntent returns the PaymentIntent associated with this
|
||||
// payment.
|
||||
GetPaymentIntent() PaymentIntent
|
||||
}
|
||||
|
||||
// GetPayment returns the Payment associated with this interface.
|
||||
//
|
||||
// NOTE: This method is part of the PaymentAndIntent interface.
|
||||
func (r FilterPaymentsRow) GetPayment() Payment {
|
||||
return r.Payment
|
||||
}
|
||||
|
||||
// GetPaymentIntent returns the PaymentIntent associated with this payment.
|
||||
// If the payment has no intent (IntentType is NULL), this returns a zero-value
|
||||
// PaymentIntent.
|
||||
//
|
||||
// NOTE: This method is part of the PaymentAndIntent interface.
|
||||
func (r FilterPaymentsRow) GetPaymentIntent() PaymentIntent {
|
||||
if !r.IntentType.Valid {
|
||||
return PaymentIntent{}
|
||||
}
|
||||
|
||||
return PaymentIntent{
|
||||
IntentType: r.IntentType.Int16,
|
||||
IntentPayload: r.IntentPayload,
|
||||
}
|
||||
}
|
||||
|
||||
// GetPayment returns the Payment associated with this interface.
|
||||
//
|
||||
// NOTE: This method is part of the PaymentAndIntent interface.
|
||||
func (r FetchPaymentRow) GetPayment() Payment {
|
||||
return r.Payment
|
||||
}
|
||||
|
||||
// GetPaymentIntent returns the PaymentIntent associated with this payment.
|
||||
// If the payment has no intent (IntentType is NULL), this returns a zero-value
|
||||
// PaymentIntent.
|
||||
//
|
||||
// NOTE: This method is part of the PaymentAndIntent interface.
|
||||
func (r FetchPaymentRow) GetPaymentIntent() PaymentIntent {
|
||||
if !r.IntentType.Valid {
|
||||
return PaymentIntent{}
|
||||
}
|
||||
|
||||
return PaymentIntent{
|
||||
IntentType: r.IntentType.Int16,
|
||||
IntentPayload: r.IntentPayload,
|
||||
}
|
||||
}
|
||||
|
||||
func (r FetchPaymentsByIDsRow) GetPayment() Payment {
|
||||
return Payment{
|
||||
ID: r.ID,
|
||||
AmountMsat: r.AmountMsat,
|
||||
CreatedAt: r.CreatedAt,
|
||||
PaymentIdentifier: r.PaymentIdentifier,
|
||||
FailReason: r.FailReason,
|
||||
}
|
||||
}
|
||||
|
||||
func (r FetchPaymentsByIDsRow) GetPaymentIntent() PaymentIntent {
|
||||
if !r.IntentType.Valid {
|
||||
return PaymentIntent{}
|
||||
}
|
||||
|
||||
return PaymentIntent{
|
||||
IntentType: r.IntentType.Int16,
|
||||
IntentPayload: r.IntentPayload,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.29.0
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Payment struct {
|
||||
ID int64
|
||||
AmountMsat int64
|
||||
CreatedAt time.Time
|
||||
PaymentIdentifier []byte
|
||||
FailReason sql.NullInt32
|
||||
}
|
||||
|
||||
type PaymentAttemptFirstHopCustomRecord struct {
|
||||
ID int64
|
||||
HtlcAttemptIndex int64
|
||||
Key int64
|
||||
Value []byte
|
||||
}
|
||||
|
||||
type PaymentDuplicate struct {
|
||||
ID int64
|
||||
PaymentID int64
|
||||
AmountMsat int64
|
||||
CreatedAt time.Time
|
||||
FailReason sql.NullInt32
|
||||
SettlePreimage []byte
|
||||
SettleTime sql.NullTime
|
||||
}
|
||||
|
||||
type PaymentFirstHopCustomRecord struct {
|
||||
ID int64
|
||||
PaymentID int64
|
||||
Key int64
|
||||
Value []byte
|
||||
}
|
||||
|
||||
type PaymentHopCustomRecord struct {
|
||||
ID int64
|
||||
HopID int64
|
||||
Key int64
|
||||
Value []byte
|
||||
}
|
||||
|
||||
type PaymentHtlcAttempt struct {
|
||||
ID int64
|
||||
AttemptIndex int64
|
||||
PaymentID int64
|
||||
SessionKey []byte
|
||||
AttemptTime time.Time
|
||||
PaymentHash []byte
|
||||
FirstHopAmountMsat int64
|
||||
RouteTotalTimeLock int32
|
||||
RouteTotalAmount int64
|
||||
RouteSourceKey []byte
|
||||
}
|
||||
|
||||
type PaymentHtlcAttemptResolution struct {
|
||||
AttemptIndex int64
|
||||
ResolutionTime time.Time
|
||||
ResolutionType int32
|
||||
SettlePreimage []byte
|
||||
FailureSourceIndex sql.NullInt32
|
||||
HtlcFailReason sql.NullInt32
|
||||
FailureMsg []byte
|
||||
}
|
||||
|
||||
type PaymentIntent struct {
|
||||
ID int64
|
||||
PaymentID int64
|
||||
IntentType int16
|
||||
IntentPayload []byte
|
||||
}
|
||||
|
||||
type PaymentRouteHop struct {
|
||||
ID int64
|
||||
HtlcAttemptIndex int64
|
||||
HopIndex int32
|
||||
PubKey []byte
|
||||
Scid string
|
||||
OutgoingTimeLock int32
|
||||
AmtToForward int64
|
||||
MetaData []byte
|
||||
}
|
||||
|
||||
type PaymentRouteHopAmp struct {
|
||||
HopID int64
|
||||
RootShare []byte
|
||||
SetID []byte
|
||||
ChildIndex int32
|
||||
}
|
||||
|
||||
type PaymentRouteHopBlinded struct {
|
||||
HopID int64
|
||||
EncryptedData []byte
|
||||
BlindingPoint []byte
|
||||
BlindedPathTotalAmt sql.NullInt64
|
||||
}
|
||||
|
||||
type PaymentRouteHopMpp struct {
|
||||
HopID int64
|
||||
PaymentAddr []byte
|
||||
TotalMsat int64
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user