mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
sweepbatcher/Store: do not provide LoopOut field
This data is not used by Batcher since commit "sweepbatcher: load swap from loopdb, not own store". Now sweepbatcher.Store depends only on tables sweeps and sweep_batches and does not depend on swaps, loopout_swaps and htlc_keys, making it easier to reuse.
This commit is contained in:
parent
4be69e186e
commit
7a7ea05e52
4 changed files with 14 additions and 152 deletions
|
|
@ -8,7 +8,6 @@ package sqlc
|
|||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"time"
|
||||
)
|
||||
|
||||
const confirmBatch = `-- name: ConfirmBatch :exec
|
||||
|
|
@ -36,73 +35,24 @@ func (q *Queries) DropBatch(ctx context.Context, id int32) error {
|
|||
|
||||
const getBatchSweeps = `-- name: GetBatchSweeps :many
|
||||
SELECT
|
||||
sweeps.id, sweeps.swap_hash, sweeps.batch_id, sweeps.outpoint_txid, sweeps.outpoint_index, sweeps.amt, sweeps.completed,
|
||||
swaps.id, swaps.swap_hash, swaps.preimage, swaps.initiation_time, swaps.amount_requested, swaps.cltv_expiry, swaps.max_miner_fee, swaps.max_swap_fee, swaps.initiation_height, swaps.protocol_version, swaps.label,
|
||||
loopout_swaps.swap_hash, loopout_swaps.dest_address, loopout_swaps.swap_invoice, loopout_swaps.max_swap_routing_fee, loopout_swaps.sweep_conf_target, loopout_swaps.htlc_confirmations, loopout_swaps.outgoing_chan_set, loopout_swaps.prepay_invoice, loopout_swaps.max_prepay_routing_fee, loopout_swaps.publication_deadline, loopout_swaps.single_sweep, loopout_swaps.payment_timeout,
|
||||
htlc_keys.swap_hash, htlc_keys.sender_script_pubkey, htlc_keys.receiver_script_pubkey, htlc_keys.sender_internal_pubkey, htlc_keys.receiver_internal_pubkey, htlc_keys.client_key_family, htlc_keys.client_key_index
|
||||
id, swap_hash, batch_id, outpoint_txid, outpoint_index, amt, completed
|
||||
FROM
|
||||
sweeps
|
||||
JOIN
|
||||
swaps ON sweeps.swap_hash = swaps.swap_hash
|
||||
JOIN
|
||||
loopout_swaps ON sweeps.swap_hash = loopout_swaps.swap_hash
|
||||
JOIN
|
||||
htlc_keys ON sweeps.swap_hash = htlc_keys.swap_hash
|
||||
WHERE
|
||||
sweeps.batch_id = $1
|
||||
batch_id = $1
|
||||
ORDER BY
|
||||
sweeps.id ASC
|
||||
id ASC
|
||||
`
|
||||
|
||||
type GetBatchSweepsRow struct {
|
||||
ID int32
|
||||
SwapHash []byte
|
||||
BatchID int32
|
||||
OutpointTxid []byte
|
||||
OutpointIndex int32
|
||||
Amt int64
|
||||
Completed bool
|
||||
ID_2 int32
|
||||
SwapHash_2 []byte
|
||||
Preimage []byte
|
||||
InitiationTime time.Time
|
||||
AmountRequested int64
|
||||
CltvExpiry int32
|
||||
MaxMinerFee int64
|
||||
MaxSwapFee int64
|
||||
InitiationHeight int32
|
||||
ProtocolVersion int32
|
||||
Label string
|
||||
SwapHash_3 []byte
|
||||
DestAddress string
|
||||
SwapInvoice string
|
||||
MaxSwapRoutingFee int64
|
||||
SweepConfTarget int32
|
||||
HtlcConfirmations int32
|
||||
OutgoingChanSet string
|
||||
PrepayInvoice string
|
||||
MaxPrepayRoutingFee int64
|
||||
PublicationDeadline time.Time
|
||||
SingleSweep bool
|
||||
PaymentTimeout int32
|
||||
SwapHash_4 []byte
|
||||
SenderScriptPubkey []byte
|
||||
ReceiverScriptPubkey []byte
|
||||
SenderInternalPubkey []byte
|
||||
ReceiverInternalPubkey []byte
|
||||
ClientKeyFamily int32
|
||||
ClientKeyIndex int32
|
||||
}
|
||||
|
||||
func (q *Queries) GetBatchSweeps(ctx context.Context, batchID int32) ([]GetBatchSweepsRow, error) {
|
||||
func (q *Queries) GetBatchSweeps(ctx context.Context, batchID int32) ([]Sweep, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getBatchSweeps, batchID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetBatchSweepsRow
|
||||
var items []Sweep
|
||||
for rows.Next() {
|
||||
var i GetBatchSweepsRow
|
||||
var i Sweep
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.SwapHash,
|
||||
|
|
@ -111,36 +61,6 @@ func (q *Queries) GetBatchSweeps(ctx context.Context, batchID int32) ([]GetBatch
|
|||
&i.OutpointIndex,
|
||||
&i.Amt,
|
||||
&i.Completed,
|
||||
&i.ID_2,
|
||||
&i.SwapHash_2,
|
||||
&i.Preimage,
|
||||
&i.InitiationTime,
|
||||
&i.AmountRequested,
|
||||
&i.CltvExpiry,
|
||||
&i.MaxMinerFee,
|
||||
&i.MaxSwapFee,
|
||||
&i.InitiationHeight,
|
||||
&i.ProtocolVersion,
|
||||
&i.Label,
|
||||
&i.SwapHash_3,
|
||||
&i.DestAddress,
|
||||
&i.SwapInvoice,
|
||||
&i.MaxSwapRoutingFee,
|
||||
&i.SweepConfTarget,
|
||||
&i.HtlcConfirmations,
|
||||
&i.OutgoingChanSet,
|
||||
&i.PrepayInvoice,
|
||||
&i.MaxPrepayRoutingFee,
|
||||
&i.PublicationDeadline,
|
||||
&i.SingleSweep,
|
||||
&i.PaymentTimeout,
|
||||
&i.SwapHash_4,
|
||||
&i.SenderScriptPubkey,
|
||||
&i.ReceiverScriptPubkey,
|
||||
&i.SenderInternalPubkey,
|
||||
&i.ReceiverInternalPubkey,
|
||||
&i.ClientKeyFamily,
|
||||
&i.ClientKeyIndex,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ type Querier interface {
|
|||
CreateReservation(ctx context.Context, arg CreateReservationParams) error
|
||||
DropBatch(ctx context.Context, id int32) error
|
||||
FetchLiquidityParams(ctx context.Context) ([]byte, error)
|
||||
GetBatchSweeps(ctx context.Context, batchID int32) ([]GetBatchSweepsRow, error)
|
||||
GetBatchSweeps(ctx context.Context, batchID int32) ([]Sweep, error)
|
||||
GetBatchSweptAmount(ctx context.Context, batchID int32) (int64, error)
|
||||
GetInstantOutSwap(ctx context.Context, swapHash []byte) (GetInstantOutSwapRow, error)
|
||||
GetInstantOutSwapUpdates(ctx context.Context, swapHash []byte) ([]InstantoutUpdate, error)
|
||||
|
|
|
|||
|
|
@ -91,22 +91,13 @@ AND
|
|||
|
||||
-- name: GetBatchSweeps :many
|
||||
SELECT
|
||||
sweeps.*,
|
||||
swaps.*,
|
||||
loopout_swaps.*,
|
||||
htlc_keys.*
|
||||
*
|
||||
FROM
|
||||
sweeps
|
||||
JOIN
|
||||
swaps ON sweeps.swap_hash = swaps.swap_hash
|
||||
JOIN
|
||||
loopout_swaps ON sweeps.swap_hash = loopout_swaps.swap_hash
|
||||
JOIN
|
||||
htlc_keys ON sweeps.swap_hash = htlc_keys.swap_hash
|
||||
WHERE
|
||||
sweeps.batch_id = $1
|
||||
batch_id = $1
|
||||
ORDER BY
|
||||
sweeps.id ASC;
|
||||
id ASC;
|
||||
|
||||
-- name: GetSweepStatus :one
|
||||
SELECT
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ type BaseDB interface {
|
|||
|
||||
// GetBatchSweeps fetches all the sweeps that are part a batch.
|
||||
GetBatchSweeps(ctx context.Context, batchID int32) (
|
||||
[]sqlc.GetBatchSweepsRow, error)
|
||||
[]sqlc.Sweep, error)
|
||||
|
||||
// GetBatchSweptAmount returns the total amount of sats swept by a
|
||||
// (confirmed) batch.
|
||||
|
|
@ -34,10 +34,6 @@ type BaseDB interface {
|
|||
GetParentBatch(ctx context.Context, swapHash []byte) (sqlc.SweepBatch,
|
||||
error)
|
||||
|
||||
// GetSwapUpdates fetches all the updates for a swap.
|
||||
GetSwapUpdates(ctx context.Context, swapHash []byte) (
|
||||
[]sqlc.SwapUpdate, error)
|
||||
|
||||
// GetUnconfirmedBatches fetches all the batches from the
|
||||
// database that are not in a confirmed state.
|
||||
GetUnconfirmedBatches(ctx context.Context) ([]sqlc.SweepBatch, error)
|
||||
|
|
@ -154,14 +150,7 @@ func (s *SQLStore) FetchBatchSweeps(ctx context.Context, id int32) (
|
|||
}
|
||||
|
||||
for _, dbSweep := range dbSweeps {
|
||||
updates, err := s.baseDb.GetSwapUpdates(
|
||||
ctx, dbSweep.SwapHash,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sweep, err := s.convertSweepRow(dbSweep, updates)
|
||||
sweep, err := s.convertSweepRow(dbSweep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -260,9 +249,6 @@ type dbSweep struct {
|
|||
|
||||
// Completed indicates whether this sweep is completed.
|
||||
Completed bool
|
||||
|
||||
// LoopOut is the loop out that the sweep belongs to.
|
||||
LoopOut *loopdb.LoopOut
|
||||
}
|
||||
|
||||
// convertBatchRow converts a batch row from db to a sweepbatcher.Batch struct.
|
||||
|
|
@ -354,9 +340,7 @@ func batchToUpdateArgs(batch dbBatch) sqlc.UpdateBatchParams {
|
|||
}
|
||||
|
||||
// convertSweepRow converts a sweep row from db to a sweep struct.
|
||||
func (s *SQLStore) convertSweepRow(row sqlc.GetBatchSweepsRow,
|
||||
updates []sqlc.SwapUpdate) (dbSweep, error) {
|
||||
|
||||
func (s *SQLStore) convertSweepRow(row sqlc.Sweep) (dbSweep, error) {
|
||||
sweep := dbSweep{
|
||||
ID: row.ID,
|
||||
BatchID: row.BatchID,
|
||||
|
|
@ -380,40 +364,7 @@ func (s *SQLStore) convertSweepRow(row sqlc.GetBatchSweepsRow,
|
|||
Index: uint32(row.OutpointIndex),
|
||||
}
|
||||
|
||||
sweep.LoopOut, err = loopdb.ConvertLoopOutRow(
|
||||
s.network,
|
||||
sqlc.GetLoopOutSwapRow{
|
||||
ID: row.ID,
|
||||
SwapHash: row.SwapHash,
|
||||
Preimage: row.Preimage,
|
||||
InitiationTime: row.InitiationTime,
|
||||
AmountRequested: row.AmountRequested,
|
||||
CltvExpiry: row.CltvExpiry,
|
||||
MaxMinerFee: row.MaxMinerFee,
|
||||
MaxSwapFee: row.MaxSwapFee,
|
||||
InitiationHeight: row.InitiationHeight,
|
||||
ProtocolVersion: row.ProtocolVersion,
|
||||
Label: row.Label,
|
||||
DestAddress: row.DestAddress,
|
||||
SwapInvoice: row.SwapInvoice,
|
||||
MaxSwapRoutingFee: row.MaxSwapRoutingFee,
|
||||
SweepConfTarget: row.SweepConfTarget,
|
||||
HtlcConfirmations: row.HtlcConfirmations,
|
||||
OutgoingChanSet: row.OutgoingChanSet,
|
||||
PrepayInvoice: row.PrepayInvoice,
|
||||
MaxPrepayRoutingFee: row.MaxPrepayRoutingFee,
|
||||
PublicationDeadline: row.PublicationDeadline,
|
||||
SingleSweep: row.SingleSweep,
|
||||
SenderScriptPubkey: row.SenderScriptPubkey,
|
||||
ReceiverScriptPubkey: row.ReceiverScriptPubkey,
|
||||
SenderInternalPubkey: row.SenderInternalPubkey,
|
||||
ReceiverInternalPubkey: row.ReceiverInternalPubkey,
|
||||
ClientKeyFamily: row.ClientKeyFamily,
|
||||
ClientKeyIndex: row.ClientKeyIndex,
|
||||
}, updates,
|
||||
)
|
||||
|
||||
return sweep, err
|
||||
return sweep, nil
|
||||
}
|
||||
|
||||
// sweepToUpsertArgs converts a Sweep struct to the arguments needed to insert.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue