mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-17 12:14:21 +01:00
Sqlite - add sqlc and migration (#217)
This commit is contained in:
31
server/internal/infrastructure/db/sqlite/sqlc/queries/db.go
Normal file
31
server/internal/infrastructure/db/sqlite/sqlc/queries/db.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.26.0
|
||||
|
||||
package queries
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
100
server/internal/infrastructure/db/sqlite/sqlc/queries/models.go
Normal file
100
server/internal/infrastructure/db/sqlite/sqlc/queries/models.go
Normal file
@@ -0,0 +1,100 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.26.0
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type Payment struct {
|
||||
ID string
|
||||
RoundID string
|
||||
}
|
||||
|
||||
type PaymentReceiverVw struct {
|
||||
PaymentID sql.NullString
|
||||
Pubkey sql.NullString
|
||||
Amount sql.NullInt64
|
||||
OnchainAddress sql.NullString
|
||||
}
|
||||
|
||||
type PaymentVtxoVw struct {
|
||||
Txid sql.NullString
|
||||
Vout sql.NullInt64
|
||||
Pubkey sql.NullString
|
||||
Amount sql.NullInt64
|
||||
PoolTx sql.NullString
|
||||
SpentBy sql.NullString
|
||||
Spent sql.NullBool
|
||||
Redeemed sql.NullBool
|
||||
Swept sql.NullBool
|
||||
ExpireAt sql.NullInt64
|
||||
PaymentID sql.NullString
|
||||
}
|
||||
|
||||
type Receiver struct {
|
||||
PaymentID string
|
||||
Pubkey string
|
||||
Amount int64
|
||||
OnchainAddress string
|
||||
}
|
||||
|
||||
type Round struct {
|
||||
ID string
|
||||
StartingTimestamp int64
|
||||
EndingTimestamp int64
|
||||
Ended bool
|
||||
Failed bool
|
||||
StageCode int64
|
||||
Txid string
|
||||
UnsignedTx string
|
||||
ConnectorAddress string
|
||||
DustAmount int64
|
||||
Version int64
|
||||
Swept bool
|
||||
}
|
||||
|
||||
type RoundPaymentVw struct {
|
||||
ID sql.NullString
|
||||
RoundID sql.NullString
|
||||
}
|
||||
|
||||
type RoundTxVw struct {
|
||||
ID sql.NullInt64
|
||||
Tx sql.NullString
|
||||
RoundID sql.NullString
|
||||
Type sql.NullString
|
||||
Position sql.NullInt64
|
||||
Txid sql.NullString
|
||||
TreeLevel sql.NullInt64
|
||||
ParentTxid sql.NullString
|
||||
IsLeaf sql.NullBool
|
||||
}
|
||||
|
||||
type Tx struct {
|
||||
ID int64
|
||||
Tx string
|
||||
RoundID string
|
||||
Type string
|
||||
Position int64
|
||||
Txid sql.NullString
|
||||
TreeLevel sql.NullInt64
|
||||
ParentTxid sql.NullString
|
||||
IsLeaf sql.NullBool
|
||||
}
|
||||
|
||||
type Vtxo struct {
|
||||
Txid string
|
||||
Vout int64
|
||||
Pubkey string
|
||||
Amount int64
|
||||
PoolTx string
|
||||
SpentBy string
|
||||
Spent bool
|
||||
Redeemed bool
|
||||
Swept bool
|
||||
ExpireAt int64
|
||||
PaymentID sql.NullString
|
||||
}
|
||||
@@ -0,0 +1,847 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.26.0
|
||||
// source: query.sql
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
const markVtxoAsRedeemed = `-- name: MarkVtxoAsRedeemed :exec
|
||||
UPDATE vtxo SET redeemed = true WHERE txid = ? AND vout = ?
|
||||
`
|
||||
|
||||
type MarkVtxoAsRedeemedParams struct {
|
||||
Txid string
|
||||
Vout int64
|
||||
}
|
||||
|
||||
func (q *Queries) MarkVtxoAsRedeemed(ctx context.Context, arg MarkVtxoAsRedeemedParams) error {
|
||||
_, err := q.db.ExecContext(ctx, markVtxoAsRedeemed, arg.Txid, arg.Vout)
|
||||
return err
|
||||
}
|
||||
|
||||
const markVtxoAsSpent = `-- name: MarkVtxoAsSpent :exec
|
||||
UPDATE vtxo SET spent = true, spent_by = ? WHERE txid = ? AND vout = ?
|
||||
`
|
||||
|
||||
type MarkVtxoAsSpentParams struct {
|
||||
SpentBy string
|
||||
Txid string
|
||||
Vout int64
|
||||
}
|
||||
|
||||
func (q *Queries) MarkVtxoAsSpent(ctx context.Context, arg MarkVtxoAsSpentParams) error {
|
||||
_, err := q.db.ExecContext(ctx, markVtxoAsSpent, arg.SpentBy, arg.Txid, arg.Vout)
|
||||
return err
|
||||
}
|
||||
|
||||
const markVtxoAsSwept = `-- name: MarkVtxoAsSwept :exec
|
||||
UPDATE vtxo SET swept = true WHERE txid = ? AND vout = ?
|
||||
`
|
||||
|
||||
type MarkVtxoAsSweptParams struct {
|
||||
Txid string
|
||||
Vout int64
|
||||
}
|
||||
|
||||
func (q *Queries) MarkVtxoAsSwept(ctx context.Context, arg MarkVtxoAsSweptParams) error {
|
||||
_, err := q.db.ExecContext(ctx, markVtxoAsSwept, arg.Txid, arg.Vout)
|
||||
return err
|
||||
}
|
||||
|
||||
const selectNotRedeemedVtxos = `-- name: SelectNotRedeemedVtxos :many
|
||||
SELECT txid, vout, pubkey, amount, pool_tx, spent_by, spent, redeemed, swept, expire_at, payment_id FROM vtxo WHERE redeemed = false
|
||||
`
|
||||
|
||||
func (q *Queries) SelectNotRedeemedVtxos(ctx context.Context) ([]Vtxo, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectNotRedeemedVtxos)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Vtxo
|
||||
for rows.Next() {
|
||||
var i Vtxo
|
||||
if err := rows.Scan(
|
||||
&i.Txid,
|
||||
&i.Vout,
|
||||
&i.Pubkey,
|
||||
&i.Amount,
|
||||
&i.PoolTx,
|
||||
&i.SpentBy,
|
||||
&i.Spent,
|
||||
&i.Redeemed,
|
||||
&i.Swept,
|
||||
&i.ExpireAt,
|
||||
&i.PaymentID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const selectNotRedeemedVtxosWithPubkey = `-- name: SelectNotRedeemedVtxosWithPubkey :many
|
||||
SELECT txid, vout, pubkey, amount, pool_tx, spent_by, spent, redeemed, swept, expire_at, payment_id FROM vtxo WHERE redeemed = false AND pubkey = ?
|
||||
`
|
||||
|
||||
func (q *Queries) SelectNotRedeemedVtxosWithPubkey(ctx context.Context, pubkey string) ([]Vtxo, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectNotRedeemedVtxosWithPubkey, pubkey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Vtxo
|
||||
for rows.Next() {
|
||||
var i Vtxo
|
||||
if err := rows.Scan(
|
||||
&i.Txid,
|
||||
&i.Vout,
|
||||
&i.Pubkey,
|
||||
&i.Amount,
|
||||
&i.PoolTx,
|
||||
&i.SpentBy,
|
||||
&i.Spent,
|
||||
&i.Redeemed,
|
||||
&i.Swept,
|
||||
&i.ExpireAt,
|
||||
&i.PaymentID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const selectRoundIds = `-- name: SelectRoundIds :many
|
||||
SELECT id FROM round
|
||||
`
|
||||
|
||||
func (q *Queries) SelectRoundIds(ctx context.Context) ([]string, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectRoundIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []string
|
||||
for rows.Next() {
|
||||
var id string
|
||||
if err := rows.Scan(&id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, id)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const selectRoundIdsInRange = `-- name: SelectRoundIdsInRange :many
|
||||
SELECT id FROM round WHERE starting_timestamp > ? AND starting_timestamp < ?
|
||||
`
|
||||
|
||||
type SelectRoundIdsInRangeParams struct {
|
||||
StartingTimestamp int64
|
||||
StartingTimestamp_2 int64
|
||||
}
|
||||
|
||||
func (q *Queries) SelectRoundIdsInRange(ctx context.Context, arg SelectRoundIdsInRangeParams) ([]string, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectRoundIdsInRange, arg.StartingTimestamp, arg.StartingTimestamp_2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []string
|
||||
for rows.Next() {
|
||||
var id string
|
||||
if err := rows.Scan(&id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, id)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const selectRoundWithRoundId = `-- name: SelectRoundWithRoundId :many
|
||||
SELECT round.id, round.starting_timestamp, round.ending_timestamp, round.ended, round.failed, round.stage_code, round.txid, round.unsigned_tx, round.connector_address, round.dust_amount, round.version, round.swept,
|
||||
round_payment_vw.id, round_payment_vw.round_id,
|
||||
round_tx_vw.id, round_tx_vw.tx, round_tx_vw.round_id, round_tx_vw.type, round_tx_vw.position, round_tx_vw.txid, round_tx_vw.tree_level, round_tx_vw.parent_txid, round_tx_vw.is_leaf,
|
||||
payment_receiver_vw.payment_id, payment_receiver_vw.pubkey, payment_receiver_vw.amount, payment_receiver_vw.onchain_address,
|
||||
payment_vtxo_vw.txid, payment_vtxo_vw.vout, payment_vtxo_vw.pubkey, payment_vtxo_vw.amount, payment_vtxo_vw.pool_tx, payment_vtxo_vw.spent_by, payment_vtxo_vw.spent, payment_vtxo_vw.redeemed, payment_vtxo_vw.swept, payment_vtxo_vw.expire_at, payment_vtxo_vw.payment_id
|
||||
FROM round
|
||||
LEFT OUTER JOIN round_payment_vw ON round.id=round_payment_vw.round_id
|
||||
LEFT OUTER JOIN round_tx_vw ON round.id=round_tx_vw.round_id
|
||||
LEFT OUTER JOIN payment_receiver_vw ON round_payment_vw.id=payment_receiver_vw.payment_id
|
||||
LEFT OUTER JOIN payment_vtxo_vw ON round_payment_vw.id=payment_vtxo_vw.payment_id
|
||||
WHERE round.id = ?
|
||||
`
|
||||
|
||||
type SelectRoundWithRoundIdRow struct {
|
||||
Round Round
|
||||
RoundPaymentVw RoundPaymentVw
|
||||
RoundTxVw RoundTxVw
|
||||
PaymentReceiverVw PaymentReceiverVw
|
||||
PaymentVtxoVw PaymentVtxoVw
|
||||
}
|
||||
|
||||
func (q *Queries) SelectRoundWithRoundId(ctx context.Context, id string) ([]SelectRoundWithRoundIdRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectRoundWithRoundId, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []SelectRoundWithRoundIdRow
|
||||
for rows.Next() {
|
||||
var i SelectRoundWithRoundIdRow
|
||||
if err := rows.Scan(
|
||||
&i.Round.ID,
|
||||
&i.Round.StartingTimestamp,
|
||||
&i.Round.EndingTimestamp,
|
||||
&i.Round.Ended,
|
||||
&i.Round.Failed,
|
||||
&i.Round.StageCode,
|
||||
&i.Round.Txid,
|
||||
&i.Round.UnsignedTx,
|
||||
&i.Round.ConnectorAddress,
|
||||
&i.Round.DustAmount,
|
||||
&i.Round.Version,
|
||||
&i.Round.Swept,
|
||||
&i.RoundPaymentVw.ID,
|
||||
&i.RoundPaymentVw.RoundID,
|
||||
&i.RoundTxVw.ID,
|
||||
&i.RoundTxVw.Tx,
|
||||
&i.RoundTxVw.RoundID,
|
||||
&i.RoundTxVw.Type,
|
||||
&i.RoundTxVw.Position,
|
||||
&i.RoundTxVw.Txid,
|
||||
&i.RoundTxVw.TreeLevel,
|
||||
&i.RoundTxVw.ParentTxid,
|
||||
&i.RoundTxVw.IsLeaf,
|
||||
&i.PaymentReceiverVw.PaymentID,
|
||||
&i.PaymentReceiverVw.Pubkey,
|
||||
&i.PaymentReceiverVw.Amount,
|
||||
&i.PaymentReceiverVw.OnchainAddress,
|
||||
&i.PaymentVtxoVw.Txid,
|
||||
&i.PaymentVtxoVw.Vout,
|
||||
&i.PaymentVtxoVw.Pubkey,
|
||||
&i.PaymentVtxoVw.Amount,
|
||||
&i.PaymentVtxoVw.PoolTx,
|
||||
&i.PaymentVtxoVw.SpentBy,
|
||||
&i.PaymentVtxoVw.Spent,
|
||||
&i.PaymentVtxoVw.Redeemed,
|
||||
&i.PaymentVtxoVw.Swept,
|
||||
&i.PaymentVtxoVw.ExpireAt,
|
||||
&i.PaymentVtxoVw.PaymentID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const selectRoundWithRoundTxId = `-- name: SelectRoundWithRoundTxId :many
|
||||
SELECT round.id, round.starting_timestamp, round.ending_timestamp, round.ended, round.failed, round.stage_code, round.txid, round.unsigned_tx, round.connector_address, round.dust_amount, round.version, round.swept,
|
||||
round_payment_vw.id, round_payment_vw.round_id,
|
||||
round_tx_vw.id, round_tx_vw.tx, round_tx_vw.round_id, round_tx_vw.type, round_tx_vw.position, round_tx_vw.txid, round_tx_vw.tree_level, round_tx_vw.parent_txid, round_tx_vw.is_leaf,
|
||||
payment_receiver_vw.payment_id, payment_receiver_vw.pubkey, payment_receiver_vw.amount, payment_receiver_vw.onchain_address,
|
||||
payment_vtxo_vw.txid, payment_vtxo_vw.vout, payment_vtxo_vw.pubkey, payment_vtxo_vw.amount, payment_vtxo_vw.pool_tx, payment_vtxo_vw.spent_by, payment_vtxo_vw.spent, payment_vtxo_vw.redeemed, payment_vtxo_vw.swept, payment_vtxo_vw.expire_at, payment_vtxo_vw.payment_id
|
||||
FROM round
|
||||
LEFT OUTER JOIN round_payment_vw ON round.id=round_payment_vw.round_id
|
||||
LEFT OUTER JOIN round_tx_vw ON round.id=round_tx_vw.round_id
|
||||
LEFT OUTER JOIN payment_receiver_vw ON round_payment_vw.id=payment_receiver_vw.payment_id
|
||||
LEFT OUTER JOIN payment_vtxo_vw ON round_payment_vw.id=payment_vtxo_vw.payment_id
|
||||
WHERE round.txid = ?
|
||||
`
|
||||
|
||||
type SelectRoundWithRoundTxIdRow struct {
|
||||
Round Round
|
||||
RoundPaymentVw RoundPaymentVw
|
||||
RoundTxVw RoundTxVw
|
||||
PaymentReceiverVw PaymentReceiverVw
|
||||
PaymentVtxoVw PaymentVtxoVw
|
||||
}
|
||||
|
||||
func (q *Queries) SelectRoundWithRoundTxId(ctx context.Context, txid string) ([]SelectRoundWithRoundTxIdRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectRoundWithRoundTxId, txid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []SelectRoundWithRoundTxIdRow
|
||||
for rows.Next() {
|
||||
var i SelectRoundWithRoundTxIdRow
|
||||
if err := rows.Scan(
|
||||
&i.Round.ID,
|
||||
&i.Round.StartingTimestamp,
|
||||
&i.Round.EndingTimestamp,
|
||||
&i.Round.Ended,
|
||||
&i.Round.Failed,
|
||||
&i.Round.StageCode,
|
||||
&i.Round.Txid,
|
||||
&i.Round.UnsignedTx,
|
||||
&i.Round.ConnectorAddress,
|
||||
&i.Round.DustAmount,
|
||||
&i.Round.Version,
|
||||
&i.Round.Swept,
|
||||
&i.RoundPaymentVw.ID,
|
||||
&i.RoundPaymentVw.RoundID,
|
||||
&i.RoundTxVw.ID,
|
||||
&i.RoundTxVw.Tx,
|
||||
&i.RoundTxVw.RoundID,
|
||||
&i.RoundTxVw.Type,
|
||||
&i.RoundTxVw.Position,
|
||||
&i.RoundTxVw.Txid,
|
||||
&i.RoundTxVw.TreeLevel,
|
||||
&i.RoundTxVw.ParentTxid,
|
||||
&i.RoundTxVw.IsLeaf,
|
||||
&i.PaymentReceiverVw.PaymentID,
|
||||
&i.PaymentReceiverVw.Pubkey,
|
||||
&i.PaymentReceiverVw.Amount,
|
||||
&i.PaymentReceiverVw.OnchainAddress,
|
||||
&i.PaymentVtxoVw.Txid,
|
||||
&i.PaymentVtxoVw.Vout,
|
||||
&i.PaymentVtxoVw.Pubkey,
|
||||
&i.PaymentVtxoVw.Amount,
|
||||
&i.PaymentVtxoVw.PoolTx,
|
||||
&i.PaymentVtxoVw.SpentBy,
|
||||
&i.PaymentVtxoVw.Spent,
|
||||
&i.PaymentVtxoVw.Redeemed,
|
||||
&i.PaymentVtxoVw.Swept,
|
||||
&i.PaymentVtxoVw.ExpireAt,
|
||||
&i.PaymentVtxoVw.PaymentID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const selectSweepableRounds = `-- name: SelectSweepableRounds :many
|
||||
SELECT round.id, round.starting_timestamp, round.ending_timestamp, round.ended, round.failed, round.stage_code, round.txid, round.unsigned_tx, round.connector_address, round.dust_amount, round.version, round.swept,
|
||||
round_payment_vw.id, round_payment_vw.round_id,
|
||||
round_tx_vw.id, round_tx_vw.tx, round_tx_vw.round_id, round_tx_vw.type, round_tx_vw.position, round_tx_vw.txid, round_tx_vw.tree_level, round_tx_vw.parent_txid, round_tx_vw.is_leaf,
|
||||
payment_receiver_vw.payment_id, payment_receiver_vw.pubkey, payment_receiver_vw.amount, payment_receiver_vw.onchain_address,
|
||||
payment_vtxo_vw.txid, payment_vtxo_vw.vout, payment_vtxo_vw.pubkey, payment_vtxo_vw.amount, payment_vtxo_vw.pool_tx, payment_vtxo_vw.spent_by, payment_vtxo_vw.spent, payment_vtxo_vw.redeemed, payment_vtxo_vw.swept, payment_vtxo_vw.expire_at, payment_vtxo_vw.payment_id
|
||||
FROM round
|
||||
LEFT OUTER JOIN round_payment_vw ON round.id=round_payment_vw.round_id
|
||||
LEFT OUTER JOIN round_tx_vw ON round.id=round_tx_vw.round_id
|
||||
LEFT OUTER JOIN payment_receiver_vw ON round_payment_vw.id=payment_receiver_vw.payment_id
|
||||
LEFT OUTER JOIN payment_vtxo_vw ON round_payment_vw.id=payment_vtxo_vw.payment_id
|
||||
WHERE round.swept = false AND round.ended = true AND round.failed = false
|
||||
`
|
||||
|
||||
type SelectSweepableRoundsRow struct {
|
||||
Round Round
|
||||
RoundPaymentVw RoundPaymentVw
|
||||
RoundTxVw RoundTxVw
|
||||
PaymentReceiverVw PaymentReceiverVw
|
||||
PaymentVtxoVw PaymentVtxoVw
|
||||
}
|
||||
|
||||
func (q *Queries) SelectSweepableRounds(ctx context.Context) ([]SelectSweepableRoundsRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectSweepableRounds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []SelectSweepableRoundsRow
|
||||
for rows.Next() {
|
||||
var i SelectSweepableRoundsRow
|
||||
if err := rows.Scan(
|
||||
&i.Round.ID,
|
||||
&i.Round.StartingTimestamp,
|
||||
&i.Round.EndingTimestamp,
|
||||
&i.Round.Ended,
|
||||
&i.Round.Failed,
|
||||
&i.Round.StageCode,
|
||||
&i.Round.Txid,
|
||||
&i.Round.UnsignedTx,
|
||||
&i.Round.ConnectorAddress,
|
||||
&i.Round.DustAmount,
|
||||
&i.Round.Version,
|
||||
&i.Round.Swept,
|
||||
&i.RoundPaymentVw.ID,
|
||||
&i.RoundPaymentVw.RoundID,
|
||||
&i.RoundTxVw.ID,
|
||||
&i.RoundTxVw.Tx,
|
||||
&i.RoundTxVw.RoundID,
|
||||
&i.RoundTxVw.Type,
|
||||
&i.RoundTxVw.Position,
|
||||
&i.RoundTxVw.Txid,
|
||||
&i.RoundTxVw.TreeLevel,
|
||||
&i.RoundTxVw.ParentTxid,
|
||||
&i.RoundTxVw.IsLeaf,
|
||||
&i.PaymentReceiverVw.PaymentID,
|
||||
&i.PaymentReceiverVw.Pubkey,
|
||||
&i.PaymentReceiverVw.Amount,
|
||||
&i.PaymentReceiverVw.OnchainAddress,
|
||||
&i.PaymentVtxoVw.Txid,
|
||||
&i.PaymentVtxoVw.Vout,
|
||||
&i.PaymentVtxoVw.Pubkey,
|
||||
&i.PaymentVtxoVw.Amount,
|
||||
&i.PaymentVtxoVw.PoolTx,
|
||||
&i.PaymentVtxoVw.SpentBy,
|
||||
&i.PaymentVtxoVw.Spent,
|
||||
&i.PaymentVtxoVw.Redeemed,
|
||||
&i.PaymentVtxoVw.Swept,
|
||||
&i.PaymentVtxoVw.ExpireAt,
|
||||
&i.PaymentVtxoVw.PaymentID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const selectSweepableVtxos = `-- name: SelectSweepableVtxos :many
|
||||
SELECT txid, vout, pubkey, amount, pool_tx, spent_by, spent, redeemed, swept, expire_at, payment_id FROM vtxo WHERE redeemed = false AND swept = false
|
||||
`
|
||||
|
||||
func (q *Queries) SelectSweepableVtxos(ctx context.Context) ([]Vtxo, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectSweepableVtxos)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Vtxo
|
||||
for rows.Next() {
|
||||
var i Vtxo
|
||||
if err := rows.Scan(
|
||||
&i.Txid,
|
||||
&i.Vout,
|
||||
&i.Pubkey,
|
||||
&i.Amount,
|
||||
&i.PoolTx,
|
||||
&i.SpentBy,
|
||||
&i.Spent,
|
||||
&i.Redeemed,
|
||||
&i.Swept,
|
||||
&i.ExpireAt,
|
||||
&i.PaymentID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const selectSweptRounds = `-- name: SelectSweptRounds :many
|
||||
SELECT round.id, round.starting_timestamp, round.ending_timestamp, round.ended, round.failed, round.stage_code, round.txid, round.unsigned_tx, round.connector_address, round.dust_amount, round.version, round.swept,
|
||||
round_payment_vw.id, round_payment_vw.round_id,
|
||||
round_tx_vw.id, round_tx_vw.tx, round_tx_vw.round_id, round_tx_vw.type, round_tx_vw.position, round_tx_vw.txid, round_tx_vw.tree_level, round_tx_vw.parent_txid, round_tx_vw.is_leaf,
|
||||
payment_receiver_vw.payment_id, payment_receiver_vw.pubkey, payment_receiver_vw.amount, payment_receiver_vw.onchain_address,
|
||||
payment_vtxo_vw.txid, payment_vtxo_vw.vout, payment_vtxo_vw.pubkey, payment_vtxo_vw.amount, payment_vtxo_vw.pool_tx, payment_vtxo_vw.spent_by, payment_vtxo_vw.spent, payment_vtxo_vw.redeemed, payment_vtxo_vw.swept, payment_vtxo_vw.expire_at, payment_vtxo_vw.payment_id
|
||||
FROM round
|
||||
LEFT OUTER JOIN round_payment_vw ON round.id=round_payment_vw.round_id
|
||||
LEFT OUTER JOIN round_tx_vw ON round.id=round_tx_vw.round_id
|
||||
LEFT OUTER JOIN payment_receiver_vw ON round_payment_vw.id=payment_receiver_vw.payment_id
|
||||
LEFT OUTER JOIN payment_vtxo_vw ON round_payment_vw.id=payment_vtxo_vw.payment_id
|
||||
WHERE round.swept = true AND round.failed = false AND round.ended = true AND round.connector_address <> ''
|
||||
`
|
||||
|
||||
type SelectSweptRoundsRow struct {
|
||||
Round Round
|
||||
RoundPaymentVw RoundPaymentVw
|
||||
RoundTxVw RoundTxVw
|
||||
PaymentReceiverVw PaymentReceiverVw
|
||||
PaymentVtxoVw PaymentVtxoVw
|
||||
}
|
||||
|
||||
func (q *Queries) SelectSweptRounds(ctx context.Context) ([]SelectSweptRoundsRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectSweptRounds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []SelectSweptRoundsRow
|
||||
for rows.Next() {
|
||||
var i SelectSweptRoundsRow
|
||||
if err := rows.Scan(
|
||||
&i.Round.ID,
|
||||
&i.Round.StartingTimestamp,
|
||||
&i.Round.EndingTimestamp,
|
||||
&i.Round.Ended,
|
||||
&i.Round.Failed,
|
||||
&i.Round.StageCode,
|
||||
&i.Round.Txid,
|
||||
&i.Round.UnsignedTx,
|
||||
&i.Round.ConnectorAddress,
|
||||
&i.Round.DustAmount,
|
||||
&i.Round.Version,
|
||||
&i.Round.Swept,
|
||||
&i.RoundPaymentVw.ID,
|
||||
&i.RoundPaymentVw.RoundID,
|
||||
&i.RoundTxVw.ID,
|
||||
&i.RoundTxVw.Tx,
|
||||
&i.RoundTxVw.RoundID,
|
||||
&i.RoundTxVw.Type,
|
||||
&i.RoundTxVw.Position,
|
||||
&i.RoundTxVw.Txid,
|
||||
&i.RoundTxVw.TreeLevel,
|
||||
&i.RoundTxVw.ParentTxid,
|
||||
&i.RoundTxVw.IsLeaf,
|
||||
&i.PaymentReceiverVw.PaymentID,
|
||||
&i.PaymentReceiverVw.Pubkey,
|
||||
&i.PaymentReceiverVw.Amount,
|
||||
&i.PaymentReceiverVw.OnchainAddress,
|
||||
&i.PaymentVtxoVw.Txid,
|
||||
&i.PaymentVtxoVw.Vout,
|
||||
&i.PaymentVtxoVw.Pubkey,
|
||||
&i.PaymentVtxoVw.Amount,
|
||||
&i.PaymentVtxoVw.PoolTx,
|
||||
&i.PaymentVtxoVw.SpentBy,
|
||||
&i.PaymentVtxoVw.Spent,
|
||||
&i.PaymentVtxoVw.Redeemed,
|
||||
&i.PaymentVtxoVw.Swept,
|
||||
&i.PaymentVtxoVw.ExpireAt,
|
||||
&i.PaymentVtxoVw.PaymentID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const selectVtxoByOutpoint = `-- name: SelectVtxoByOutpoint :one
|
||||
SELECT txid, vout, pubkey, amount, pool_tx, spent_by, spent, redeemed, swept, expire_at, payment_id FROM vtxo WHERE txid = ? AND vout = ?
|
||||
`
|
||||
|
||||
type SelectVtxoByOutpointParams struct {
|
||||
Txid string
|
||||
Vout int64
|
||||
}
|
||||
|
||||
func (q *Queries) SelectVtxoByOutpoint(ctx context.Context, arg SelectVtxoByOutpointParams) (Vtxo, error) {
|
||||
row := q.db.QueryRowContext(ctx, selectVtxoByOutpoint, arg.Txid, arg.Vout)
|
||||
var i Vtxo
|
||||
err := row.Scan(
|
||||
&i.Txid,
|
||||
&i.Vout,
|
||||
&i.Pubkey,
|
||||
&i.Amount,
|
||||
&i.PoolTx,
|
||||
&i.SpentBy,
|
||||
&i.Spent,
|
||||
&i.Redeemed,
|
||||
&i.Swept,
|
||||
&i.ExpireAt,
|
||||
&i.PaymentID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const selectVtxosByPoolTxid = `-- name: SelectVtxosByPoolTxid :many
|
||||
SELECT txid, vout, pubkey, amount, pool_tx, spent_by, spent, redeemed, swept, expire_at, payment_id FROM vtxo WHERE pool_tx = ?
|
||||
`
|
||||
|
||||
func (q *Queries) SelectVtxosByPoolTxid(ctx context.Context, poolTx string) ([]Vtxo, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectVtxosByPoolTxid, poolTx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Vtxo
|
||||
for rows.Next() {
|
||||
var i Vtxo
|
||||
if err := rows.Scan(
|
||||
&i.Txid,
|
||||
&i.Vout,
|
||||
&i.Pubkey,
|
||||
&i.Amount,
|
||||
&i.PoolTx,
|
||||
&i.SpentBy,
|
||||
&i.Spent,
|
||||
&i.Redeemed,
|
||||
&i.Swept,
|
||||
&i.ExpireAt,
|
||||
&i.PaymentID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateVtxoExpireAt = `-- name: UpdateVtxoExpireAt :exec
|
||||
UPDATE vtxo SET expire_at = ? WHERE txid = ? AND vout = ?
|
||||
`
|
||||
|
||||
type UpdateVtxoExpireAtParams struct {
|
||||
ExpireAt int64
|
||||
Txid string
|
||||
Vout int64
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateVtxoExpireAt(ctx context.Context, arg UpdateVtxoExpireAtParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateVtxoExpireAt, arg.ExpireAt, arg.Txid, arg.Vout)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateVtxoPaymentId = `-- name: UpdateVtxoPaymentId :exec
|
||||
UPDATE vtxo SET payment_id = ? WHERE txid = ? AND vout = ?
|
||||
`
|
||||
|
||||
type UpdateVtxoPaymentIdParams struct {
|
||||
PaymentID sql.NullString
|
||||
Txid string
|
||||
Vout int64
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateVtxoPaymentId(ctx context.Context, arg UpdateVtxoPaymentIdParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateVtxoPaymentId, arg.PaymentID, arg.Txid, arg.Vout)
|
||||
return err
|
||||
}
|
||||
|
||||
const upsertPayment = `-- name: UpsertPayment :exec
|
||||
INSERT INTO payment (id, round_id) VALUES (?, ?)
|
||||
ON CONFLICT(id) DO UPDATE SET round_id = EXCLUDED.round_id
|
||||
`
|
||||
|
||||
type UpsertPaymentParams struct {
|
||||
ID string
|
||||
RoundID string
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertPayment(ctx context.Context, arg UpsertPaymentParams) error {
|
||||
_, err := q.db.ExecContext(ctx, upsertPayment, arg.ID, arg.RoundID)
|
||||
return err
|
||||
}
|
||||
|
||||
const upsertReceiver = `-- name: UpsertReceiver :exec
|
||||
INSERT INTO receiver (payment_id, pubkey, amount, onchain_address) VALUES (?, ?, ?, ?)
|
||||
ON CONFLICT(payment_id, pubkey) DO UPDATE SET
|
||||
amount = EXCLUDED.amount,
|
||||
onchain_address = EXCLUDED.onchain_address,
|
||||
pubkey = EXCLUDED.pubkey
|
||||
`
|
||||
|
||||
type UpsertReceiverParams struct {
|
||||
PaymentID string
|
||||
Pubkey string
|
||||
Amount int64
|
||||
OnchainAddress string
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertReceiver(ctx context.Context, arg UpsertReceiverParams) error {
|
||||
_, err := q.db.ExecContext(ctx, upsertReceiver,
|
||||
arg.PaymentID,
|
||||
arg.Pubkey,
|
||||
arg.Amount,
|
||||
arg.OnchainAddress,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const upsertRound = `-- name: UpsertRound :exec
|
||||
INSERT INTO round (
|
||||
id,
|
||||
starting_timestamp,
|
||||
ending_timestamp,
|
||||
ended, failed,
|
||||
stage_code,
|
||||
txid,
|
||||
unsigned_tx,
|
||||
connector_address,
|
||||
dust_amount,
|
||||
version,
|
||||
swept
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(id) DO UPDATE SET
|
||||
starting_timestamp = EXCLUDED.starting_timestamp,
|
||||
ending_timestamp = EXCLUDED.ending_timestamp,
|
||||
ended = EXCLUDED.ended,
|
||||
failed = EXCLUDED.failed,
|
||||
stage_code = EXCLUDED.stage_code,
|
||||
txid = EXCLUDED.txid,
|
||||
unsigned_tx = EXCLUDED.unsigned_tx,
|
||||
connector_address = EXCLUDED.connector_address,
|
||||
dust_amount = EXCLUDED.dust_amount,
|
||||
version = EXCLUDED.version,
|
||||
swept = EXCLUDED.swept
|
||||
`
|
||||
|
||||
type UpsertRoundParams struct {
|
||||
ID string
|
||||
StartingTimestamp int64
|
||||
EndingTimestamp int64
|
||||
Ended bool
|
||||
Failed bool
|
||||
StageCode int64
|
||||
Txid string
|
||||
UnsignedTx string
|
||||
ConnectorAddress string
|
||||
DustAmount int64
|
||||
Version int64
|
||||
Swept bool
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertRound(ctx context.Context, arg UpsertRoundParams) error {
|
||||
_, err := q.db.ExecContext(ctx, upsertRound,
|
||||
arg.ID,
|
||||
arg.StartingTimestamp,
|
||||
arg.EndingTimestamp,
|
||||
arg.Ended,
|
||||
arg.Failed,
|
||||
arg.StageCode,
|
||||
arg.Txid,
|
||||
arg.UnsignedTx,
|
||||
arg.ConnectorAddress,
|
||||
arg.DustAmount,
|
||||
arg.Version,
|
||||
arg.Swept,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const upsertTransaction = `-- name: UpsertTransaction :exec
|
||||
INSERT INTO tx (
|
||||
tx, round_id, type, position, txid, tree_level, parent_txid, is_leaf
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(id) DO UPDATE SET
|
||||
tx = EXCLUDED.tx,
|
||||
round_id = EXCLUDED.round_id,
|
||||
type = EXCLUDED.type,
|
||||
position = EXCLUDED.position,
|
||||
txid = EXCLUDED.txid,
|
||||
tree_level = EXCLUDED.tree_level,
|
||||
parent_txid = EXCLUDED.parent_txid,
|
||||
is_leaf = EXCLUDED.is_leaf
|
||||
`
|
||||
|
||||
type UpsertTransactionParams struct {
|
||||
Tx string
|
||||
RoundID string
|
||||
Type string
|
||||
Position int64
|
||||
Txid sql.NullString
|
||||
TreeLevel sql.NullInt64
|
||||
ParentTxid sql.NullString
|
||||
IsLeaf sql.NullBool
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertTransaction(ctx context.Context, arg UpsertTransactionParams) error {
|
||||
_, err := q.db.ExecContext(ctx, upsertTransaction,
|
||||
arg.Tx,
|
||||
arg.RoundID,
|
||||
arg.Type,
|
||||
arg.Position,
|
||||
arg.Txid,
|
||||
arg.TreeLevel,
|
||||
arg.ParentTxid,
|
||||
arg.IsLeaf,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const upsertVtxo = `-- name: UpsertVtxo :exec
|
||||
INSERT INTO vtxo (txid, vout, pubkey, amount, pool_tx, spent_by, spent, redeemed, swept, expire_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT(txid) DO UPDATE SET
|
||||
vout = excluded.vout,
|
||||
pubkey = excluded.pubkey,
|
||||
amount = excluded.amount,
|
||||
pool_tx = excluded.pool_tx,
|
||||
spent_by = excluded.spent_by,
|
||||
spent = excluded.spent,
|
||||
redeemed = excluded.redeemed,
|
||||
swept = excluded.swept,
|
||||
expire_at = excluded.expire_at
|
||||
`
|
||||
|
||||
type UpsertVtxoParams struct {
|
||||
Txid string
|
||||
Vout int64
|
||||
Pubkey string
|
||||
Amount int64
|
||||
PoolTx string
|
||||
SpentBy string
|
||||
Spent bool
|
||||
Redeemed bool
|
||||
Swept bool
|
||||
ExpireAt int64
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertVtxo(ctx context.Context, arg UpsertVtxoParams) error {
|
||||
_, err := q.db.ExecContext(ctx, upsertVtxo,
|
||||
arg.Txid,
|
||||
arg.Vout,
|
||||
arg.Pubkey,
|
||||
arg.Amount,
|
||||
arg.PoolTx,
|
||||
arg.SpentBy,
|
||||
arg.Spent,
|
||||
arg.Redeemed,
|
||||
arg.Swept,
|
||||
arg.ExpireAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user