mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-18 04:34:19 +01:00
New address encoding (#356)
* [common] rework address encoding * new address encoding * replace offchain address by vtxo output key in DB * merge migrations files into init one * fix txbuilder fixtures * fix transaction events
This commit is contained in:
@@ -21,11 +21,11 @@ CREATE TABLE IF NOT EXISTS payment (
|
||||
|
||||
CREATE TABLE IF NOT EXISTS receiver (
|
||||
payment_id TEXT NOT NULL,
|
||||
pubkey TEXT NOT NULL,
|
||||
pubkey TEXT,
|
||||
onchain_address TEXT,
|
||||
amount INTEGER NOT NULL,
|
||||
onchain_address TEXT NOT NULL,
|
||||
FOREIGN KEY (payment_id) REFERENCES payment(id),
|
||||
PRIMARY KEY (payment_id, pubkey)
|
||||
PRIMARY KEY (payment_id, pubkey, onchain_address)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS tx (
|
||||
@@ -54,6 +54,7 @@ CREATE TABLE IF NOT EXISTS vtxo (
|
||||
expire_at INTEGER NOT NULL,
|
||||
payment_id TEXT,
|
||||
redeem_tx TEXT,
|
||||
pending BOOLEAN NOT NULL,
|
||||
PRIMARY KEY (txid, vout),
|
||||
FOREIGN KEY (payment_id) REFERENCES payment(id)
|
||||
);
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
CREATE TABLE IF NOT EXISTS old_receiver (
|
||||
payment_id TEXT NOT NULL,
|
||||
pubkey TEXT NOT NULL,
|
||||
amount INTEGER NOT NULL,
|
||||
onchain_address TEXT NOT NULL,
|
||||
FOREIGN KEY (payment_id) REFERENCES payment(id),
|
||||
PRIMARY KEY (payment_id, pubkey)
|
||||
);
|
||||
|
||||
INSERT INTO old_receiver SELECT * FROM receiver;
|
||||
|
||||
DROP TABLE receiver;
|
||||
|
||||
ALTER TABLE old_receiver RENAME TO receiver;
|
||||
|
||||
ALTER TABLE vtxo DROP COLUMN descriptor;
|
||||
ALTER TABLE vtxo ADD COLUMN pubkey TEXT NOT NULL;
|
||||
@@ -1,28 +0,0 @@
|
||||
CREATE TABLE IF NOT EXISTS new_receiver (
|
||||
payment_id TEXT NOT NULL,
|
||||
descriptor TEXT NOT NULL,
|
||||
amount INTEGER NOT NULL,
|
||||
onchain_address TEXT NOT NULL,
|
||||
FOREIGN KEY (payment_id) REFERENCES payment(id),
|
||||
PRIMARY KEY (payment_id, descriptor)
|
||||
);
|
||||
|
||||
INSERT INTO new_receiver SELECT * FROM receiver;
|
||||
|
||||
DROP VIEW payment_vtxo_vw;
|
||||
DROP VIEW payment_receiver_vw;
|
||||
DROP TABLE receiver;
|
||||
ALTER TABLE new_receiver RENAME TO receiver;
|
||||
|
||||
ALTER TABLE vtxo ADD COLUMN descriptor TEXT;
|
||||
ALTER TABLE vtxo DROP COLUMN pubkey;
|
||||
|
||||
CREATE VIEW payment_vtxo_vw AS SELECT vtxo.*
|
||||
FROM payment
|
||||
LEFT OUTER JOIN vtxo
|
||||
ON payment.id=vtxo.payment_id;
|
||||
|
||||
CREATE VIEW payment_receiver_vw AS SELECT receiver.*
|
||||
FROM payment
|
||||
LEFT OUTER JOIN receiver
|
||||
ON payment.id=receiver.payment_id;
|
||||
@@ -1 +0,0 @@
|
||||
ALTER TABLE vtxo DROP COLUMN pending;
|
||||
@@ -1,14 +0,0 @@
|
||||
ALTER TABLE vtxo ADD COLUMN pending BOOLEAN NOT NULL;
|
||||
|
||||
DROP VIEW payment_vtxo_vw;
|
||||
DROP VIEW payment_receiver_vw;
|
||||
|
||||
CREATE VIEW payment_vtxo_vw AS SELECT vtxo.*
|
||||
FROM payment
|
||||
LEFT OUTER JOIN vtxo
|
||||
ON payment.id=vtxo.payment_id;
|
||||
|
||||
CREATE VIEW payment_receiver_vw AS SELECT receiver.*
|
||||
FROM payment
|
||||
LEFT OUTER JOIN receiver
|
||||
ON payment.id=receiver.payment_id;
|
||||
@@ -164,10 +164,16 @@ func (r *roundRepository) AddOrUpdateRound(ctx context.Context, round domain.Rou
|
||||
if err := querierWithTx.UpsertReceiver(
|
||||
ctx,
|
||||
queries.UpsertReceiverParams{
|
||||
PaymentID: payment.Id,
|
||||
Descriptor: receiver.Descriptor,
|
||||
Amount: int64(receiver.Amount),
|
||||
OnchainAddress: receiver.OnchainAddress,
|
||||
PaymentID: payment.Id,
|
||||
Amount: int64(receiver.Amount),
|
||||
Pubkey: sql.NullString{
|
||||
String: receiver.Pubkey,
|
||||
Valid: len(receiver.Pubkey) > 0,
|
||||
},
|
||||
OnchainAddress: sql.NullString{
|
||||
String: receiver.OnchainAddress,
|
||||
Valid: len(receiver.OnchainAddress) > 0,
|
||||
},
|
||||
},
|
||||
); err != nil {
|
||||
return fmt.Errorf("failed to upsert receiver: %w", err)
|
||||
@@ -320,8 +326,8 @@ func (r *roundRepository) GetSweptRounds(ctx context.Context) ([]domain.Round, e
|
||||
|
||||
func rowToReceiver(row queries.PaymentReceiverVw) domain.Receiver {
|
||||
return domain.Receiver{
|
||||
Descriptor: row.Descriptor.String,
|
||||
Amount: uint64(row.Amount.Int64),
|
||||
Pubkey: row.Pubkey.String,
|
||||
OnchainAddress: row.OnchainAddress.String,
|
||||
}
|
||||
}
|
||||
@@ -413,8 +419,8 @@ func readRoundRows(rows []roundPaymentTxReceiverVtxoRow) ([]*domain.Round, error
|
||||
|
||||
found := false
|
||||
for _, rcv := range payment.Receivers {
|
||||
if v.receiver.Descriptor.Valid && v.receiver.Amount.Valid {
|
||||
if rcv.Descriptor == v.receiver.Descriptor.String && int64(rcv.Amount) == v.receiver.Amount.Int64 {
|
||||
if (v.receiver.Pubkey.Valid || v.receiver.OnchainAddress.Valid) && v.receiver.Amount.Valid {
|
||||
if rcv.Pubkey == v.receiver.Pubkey.String && rcv.OnchainAddress == v.receiver.OnchainAddress.String && int64(rcv.Amount) == v.receiver.Amount.Int64 {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
@@ -469,10 +475,8 @@ func rowToPaymentVtxoVw(row queries.PaymentVtxoVw) domain.Vtxo {
|
||||
Txid: row.Txid.String,
|
||||
VOut: uint32(row.Vout.Int64),
|
||||
},
|
||||
Receiver: domain.Receiver{
|
||||
Descriptor: row.Descriptor.String,
|
||||
Amount: uint64(row.Amount.Int64),
|
||||
},
|
||||
Amount: uint64(row.Amount.Int64),
|
||||
Pubkey: row.Pubkey.String,
|
||||
RoundTxid: row.PoolTx.String,
|
||||
SpentBy: row.SpentBy.String,
|
||||
Spent: row.Spent.Bool,
|
||||
|
||||
@@ -15,32 +15,32 @@ type Payment struct {
|
||||
|
||||
type PaymentReceiverVw struct {
|
||||
PaymentID sql.NullString
|
||||
Descriptor sql.NullString
|
||||
Amount sql.NullInt64
|
||||
Pubkey sql.NullString
|
||||
OnchainAddress sql.NullString
|
||||
Amount sql.NullInt64
|
||||
}
|
||||
|
||||
type PaymentVtxoVw struct {
|
||||
Txid sql.NullString
|
||||
Vout sql.NullInt64
|
||||
Amount sql.NullInt64
|
||||
PoolTx sql.NullString
|
||||
SpentBy sql.NullString
|
||||
Spent sql.NullBool
|
||||
Redeemed sql.NullBool
|
||||
Swept sql.NullBool
|
||||
ExpireAt sql.NullInt64
|
||||
PaymentID sql.NullString
|
||||
RedeemTx sql.NullString
|
||||
Descriptor sql.NullString
|
||||
Pending sql.NullBool
|
||||
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
|
||||
RedeemTx sql.NullString
|
||||
Pending sql.NullBool
|
||||
}
|
||||
|
||||
type Receiver struct {
|
||||
PaymentID string
|
||||
Descriptor string
|
||||
Pubkey sql.NullString
|
||||
OnchainAddress sql.NullString
|
||||
Amount int64
|
||||
OnchainAddress string
|
||||
}
|
||||
|
||||
type Round struct {
|
||||
@@ -88,17 +88,17 @@ type Tx struct {
|
||||
}
|
||||
|
||||
type Vtxo struct {
|
||||
Txid string
|
||||
Vout int64
|
||||
Amount int64
|
||||
PoolTx string
|
||||
SpentBy string
|
||||
Spent bool
|
||||
Redeemed bool
|
||||
Swept bool
|
||||
ExpireAt int64
|
||||
PaymentID sql.NullString
|
||||
RedeemTx sql.NullString
|
||||
Descriptor sql.NullString
|
||||
Pending bool
|
||||
Txid string
|
||||
Vout int64
|
||||
Pubkey string
|
||||
Amount int64
|
||||
PoolTx string
|
||||
SpentBy string
|
||||
Spent bool
|
||||
Redeemed bool
|
||||
Swept bool
|
||||
ExpireAt int64
|
||||
PaymentID sql.NullString
|
||||
RedeemTx sql.NullString
|
||||
Pending bool
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func (q *Queries) MarkVtxoAsSwept(ctx context.Context, arg MarkVtxoAsSweptParams
|
||||
}
|
||||
|
||||
const selectNotRedeemedVtxos = `-- name: SelectNotRedeemedVtxos :many
|
||||
SELECT vtxo.txid, vtxo.vout, vtxo.amount, vtxo.pool_tx, vtxo.spent_by, vtxo.spent, vtxo.redeemed, vtxo.swept, vtxo.expire_at, vtxo.payment_id, vtxo.redeem_tx, vtxo.descriptor, vtxo.pending FROM vtxo
|
||||
SELECT vtxo.txid, vtxo.vout, vtxo.pubkey, vtxo.amount, vtxo.pool_tx, vtxo.spent_by, vtxo.spent, vtxo.redeemed, vtxo.swept, vtxo.expire_at, vtxo.payment_id, vtxo.redeem_tx, vtxo.pending FROM vtxo
|
||||
WHERE redeemed = false
|
||||
`
|
||||
|
||||
@@ -74,6 +74,7 @@ func (q *Queries) SelectNotRedeemedVtxos(ctx context.Context) ([]SelectNotRedeem
|
||||
if err := rows.Scan(
|
||||
&i.Vtxo.Txid,
|
||||
&i.Vtxo.Vout,
|
||||
&i.Vtxo.Pubkey,
|
||||
&i.Vtxo.Amount,
|
||||
&i.Vtxo.PoolTx,
|
||||
&i.Vtxo.SpentBy,
|
||||
@@ -83,7 +84,6 @@ func (q *Queries) SelectNotRedeemedVtxos(ctx context.Context) ([]SelectNotRedeem
|
||||
&i.Vtxo.ExpireAt,
|
||||
&i.Vtxo.PaymentID,
|
||||
&i.Vtxo.RedeemTx,
|
||||
&i.Vtxo.Descriptor,
|
||||
&i.Vtxo.Pending,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@@ -100,16 +100,16 @@ func (q *Queries) SelectNotRedeemedVtxos(ctx context.Context) ([]SelectNotRedeem
|
||||
}
|
||||
|
||||
const selectNotRedeemedVtxosWithPubkey = `-- name: SelectNotRedeemedVtxosWithPubkey :many
|
||||
SELECT vtxo.txid, vtxo.vout, vtxo.amount, vtxo.pool_tx, vtxo.spent_by, vtxo.spent, vtxo.redeemed, vtxo.swept, vtxo.expire_at, vtxo.payment_id, vtxo.redeem_tx, vtxo.descriptor, vtxo.pending FROM vtxo
|
||||
WHERE redeemed = false AND INSTR(descriptor, ?) > 0
|
||||
SELECT vtxo.txid, vtxo.vout, vtxo.pubkey, vtxo.amount, vtxo.pool_tx, vtxo.spent_by, vtxo.spent, vtxo.redeemed, vtxo.swept, vtxo.expire_at, vtxo.payment_id, vtxo.redeem_tx, vtxo.pending FROM vtxo
|
||||
WHERE redeemed = false AND pubkey = ?
|
||||
`
|
||||
|
||||
type SelectNotRedeemedVtxosWithPubkeyRow struct {
|
||||
Vtxo Vtxo
|
||||
}
|
||||
|
||||
func (q *Queries) SelectNotRedeemedVtxosWithPubkey(ctx context.Context, instr string) ([]SelectNotRedeemedVtxosWithPubkeyRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectNotRedeemedVtxosWithPubkey, instr)
|
||||
func (q *Queries) SelectNotRedeemedVtxosWithPubkey(ctx context.Context, pubkey string) ([]SelectNotRedeemedVtxosWithPubkeyRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectNotRedeemedVtxosWithPubkey, pubkey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -120,6 +120,7 @@ func (q *Queries) SelectNotRedeemedVtxosWithPubkey(ctx context.Context, instr st
|
||||
if err := rows.Scan(
|
||||
&i.Vtxo.Txid,
|
||||
&i.Vtxo.Vout,
|
||||
&i.Vtxo.Pubkey,
|
||||
&i.Vtxo.Amount,
|
||||
&i.Vtxo.PoolTx,
|
||||
&i.Vtxo.SpentBy,
|
||||
@@ -129,7 +130,6 @@ func (q *Queries) SelectNotRedeemedVtxosWithPubkey(ctx context.Context, instr st
|
||||
&i.Vtxo.ExpireAt,
|
||||
&i.Vtxo.PaymentID,
|
||||
&i.Vtxo.RedeemTx,
|
||||
&i.Vtxo.Descriptor,
|
||||
&i.Vtxo.Pending,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@@ -208,8 +208,8 @@ 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.descriptor, payment_receiver_vw.amount, payment_receiver_vw.onchain_address,
|
||||
payment_vtxo_vw.txid, payment_vtxo_vw.vout, 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, payment_vtxo_vw.redeem_tx, payment_vtxo_vw.descriptor, payment_vtxo_vw.pending
|
||||
payment_receiver_vw.payment_id, payment_receiver_vw.pubkey, payment_receiver_vw.onchain_address, payment_receiver_vw.amount,
|
||||
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, payment_vtxo_vw.redeem_tx, payment_vtxo_vw.pending
|
||||
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
|
||||
@@ -260,11 +260,12 @@ func (q *Queries) SelectRoundWithRoundId(ctx context.Context, id string) ([]Sele
|
||||
&i.RoundTxVw.ParentTxid,
|
||||
&i.RoundTxVw.IsLeaf,
|
||||
&i.PaymentReceiverVw.PaymentID,
|
||||
&i.PaymentReceiverVw.Descriptor,
|
||||
&i.PaymentReceiverVw.Amount,
|
||||
&i.PaymentReceiverVw.Pubkey,
|
||||
&i.PaymentReceiverVw.OnchainAddress,
|
||||
&i.PaymentReceiverVw.Amount,
|
||||
&i.PaymentVtxoVw.Txid,
|
||||
&i.PaymentVtxoVw.Vout,
|
||||
&i.PaymentVtxoVw.Pubkey,
|
||||
&i.PaymentVtxoVw.Amount,
|
||||
&i.PaymentVtxoVw.PoolTx,
|
||||
&i.PaymentVtxoVw.SpentBy,
|
||||
@@ -274,7 +275,6 @@ func (q *Queries) SelectRoundWithRoundId(ctx context.Context, id string) ([]Sele
|
||||
&i.PaymentVtxoVw.ExpireAt,
|
||||
&i.PaymentVtxoVw.PaymentID,
|
||||
&i.PaymentVtxoVw.RedeemTx,
|
||||
&i.PaymentVtxoVw.Descriptor,
|
||||
&i.PaymentVtxoVw.Pending,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@@ -294,8 +294,8 @@ 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.descriptor, payment_receiver_vw.amount, payment_receiver_vw.onchain_address,
|
||||
payment_vtxo_vw.txid, payment_vtxo_vw.vout, 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, payment_vtxo_vw.redeem_tx, payment_vtxo_vw.descriptor, payment_vtxo_vw.pending
|
||||
payment_receiver_vw.payment_id, payment_receiver_vw.pubkey, payment_receiver_vw.onchain_address, payment_receiver_vw.amount,
|
||||
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, payment_vtxo_vw.redeem_tx, payment_vtxo_vw.pending
|
||||
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
|
||||
@@ -346,11 +346,12 @@ func (q *Queries) SelectRoundWithRoundTxId(ctx context.Context, txid string) ([]
|
||||
&i.RoundTxVw.ParentTxid,
|
||||
&i.RoundTxVw.IsLeaf,
|
||||
&i.PaymentReceiverVw.PaymentID,
|
||||
&i.PaymentReceiverVw.Descriptor,
|
||||
&i.PaymentReceiverVw.Amount,
|
||||
&i.PaymentReceiverVw.Pubkey,
|
||||
&i.PaymentReceiverVw.OnchainAddress,
|
||||
&i.PaymentReceiverVw.Amount,
|
||||
&i.PaymentVtxoVw.Txid,
|
||||
&i.PaymentVtxoVw.Vout,
|
||||
&i.PaymentVtxoVw.Pubkey,
|
||||
&i.PaymentVtxoVw.Amount,
|
||||
&i.PaymentVtxoVw.PoolTx,
|
||||
&i.PaymentVtxoVw.SpentBy,
|
||||
@@ -360,7 +361,6 @@ func (q *Queries) SelectRoundWithRoundTxId(ctx context.Context, txid string) ([]
|
||||
&i.PaymentVtxoVw.ExpireAt,
|
||||
&i.PaymentVtxoVw.PaymentID,
|
||||
&i.PaymentVtxoVw.RedeemTx,
|
||||
&i.PaymentVtxoVw.Descriptor,
|
||||
&i.PaymentVtxoVw.Pending,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@@ -380,8 +380,8 @@ 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.descriptor, payment_receiver_vw.amount, payment_receiver_vw.onchain_address,
|
||||
payment_vtxo_vw.txid, payment_vtxo_vw.vout, 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, payment_vtxo_vw.redeem_tx, payment_vtxo_vw.descriptor, payment_vtxo_vw.pending
|
||||
payment_receiver_vw.payment_id, payment_receiver_vw.pubkey, payment_receiver_vw.onchain_address, payment_receiver_vw.amount,
|
||||
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, payment_vtxo_vw.redeem_tx, payment_vtxo_vw.pending
|
||||
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
|
||||
@@ -432,11 +432,12 @@ func (q *Queries) SelectSweepableRounds(ctx context.Context) ([]SelectSweepableR
|
||||
&i.RoundTxVw.ParentTxid,
|
||||
&i.RoundTxVw.IsLeaf,
|
||||
&i.PaymentReceiverVw.PaymentID,
|
||||
&i.PaymentReceiverVw.Descriptor,
|
||||
&i.PaymentReceiverVw.Amount,
|
||||
&i.PaymentReceiverVw.Pubkey,
|
||||
&i.PaymentReceiverVw.OnchainAddress,
|
||||
&i.PaymentReceiverVw.Amount,
|
||||
&i.PaymentVtxoVw.Txid,
|
||||
&i.PaymentVtxoVw.Vout,
|
||||
&i.PaymentVtxoVw.Pubkey,
|
||||
&i.PaymentVtxoVw.Amount,
|
||||
&i.PaymentVtxoVw.PoolTx,
|
||||
&i.PaymentVtxoVw.SpentBy,
|
||||
@@ -446,7 +447,6 @@ func (q *Queries) SelectSweepableRounds(ctx context.Context) ([]SelectSweepableR
|
||||
&i.PaymentVtxoVw.ExpireAt,
|
||||
&i.PaymentVtxoVw.PaymentID,
|
||||
&i.PaymentVtxoVw.RedeemTx,
|
||||
&i.PaymentVtxoVw.Descriptor,
|
||||
&i.PaymentVtxoVw.Pending,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@@ -463,7 +463,7 @@ func (q *Queries) SelectSweepableRounds(ctx context.Context) ([]SelectSweepableR
|
||||
}
|
||||
|
||||
const selectSweepableVtxos = `-- name: SelectSweepableVtxos :many
|
||||
SELECT vtxo.txid, vtxo.vout, vtxo.amount, vtxo.pool_tx, vtxo.spent_by, vtxo.spent, vtxo.redeemed, vtxo.swept, vtxo.expire_at, vtxo.payment_id, vtxo.redeem_tx, vtxo.descriptor, vtxo.pending FROM vtxo
|
||||
SELECT vtxo.txid, vtxo.vout, vtxo.pubkey, vtxo.amount, vtxo.pool_tx, vtxo.spent_by, vtxo.spent, vtxo.redeemed, vtxo.swept, vtxo.expire_at, vtxo.payment_id, vtxo.redeem_tx, vtxo.pending FROM vtxo
|
||||
WHERE redeemed = false AND swept = false
|
||||
`
|
||||
|
||||
@@ -483,6 +483,7 @@ func (q *Queries) SelectSweepableVtxos(ctx context.Context) ([]SelectSweepableVt
|
||||
if err := rows.Scan(
|
||||
&i.Vtxo.Txid,
|
||||
&i.Vtxo.Vout,
|
||||
&i.Vtxo.Pubkey,
|
||||
&i.Vtxo.Amount,
|
||||
&i.Vtxo.PoolTx,
|
||||
&i.Vtxo.SpentBy,
|
||||
@@ -492,7 +493,6 @@ func (q *Queries) SelectSweepableVtxos(ctx context.Context) ([]SelectSweepableVt
|
||||
&i.Vtxo.ExpireAt,
|
||||
&i.Vtxo.PaymentID,
|
||||
&i.Vtxo.RedeemTx,
|
||||
&i.Vtxo.Descriptor,
|
||||
&i.Vtxo.Pending,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@@ -512,8 +512,8 @@ 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.descriptor, payment_receiver_vw.amount, payment_receiver_vw.onchain_address,
|
||||
payment_vtxo_vw.txid, payment_vtxo_vw.vout, 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, payment_vtxo_vw.redeem_tx, payment_vtxo_vw.descriptor, payment_vtxo_vw.pending
|
||||
payment_receiver_vw.payment_id, payment_receiver_vw.pubkey, payment_receiver_vw.onchain_address, payment_receiver_vw.amount,
|
||||
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, payment_vtxo_vw.redeem_tx, payment_vtxo_vw.pending
|
||||
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
|
||||
@@ -564,11 +564,12 @@ func (q *Queries) SelectSweptRounds(ctx context.Context) ([]SelectSweptRoundsRow
|
||||
&i.RoundTxVw.ParentTxid,
|
||||
&i.RoundTxVw.IsLeaf,
|
||||
&i.PaymentReceiverVw.PaymentID,
|
||||
&i.PaymentReceiverVw.Descriptor,
|
||||
&i.PaymentReceiverVw.Amount,
|
||||
&i.PaymentReceiverVw.Pubkey,
|
||||
&i.PaymentReceiverVw.OnchainAddress,
|
||||
&i.PaymentReceiverVw.Amount,
|
||||
&i.PaymentVtxoVw.Txid,
|
||||
&i.PaymentVtxoVw.Vout,
|
||||
&i.PaymentVtxoVw.Pubkey,
|
||||
&i.PaymentVtxoVw.Amount,
|
||||
&i.PaymentVtxoVw.PoolTx,
|
||||
&i.PaymentVtxoVw.SpentBy,
|
||||
@@ -578,7 +579,6 @@ func (q *Queries) SelectSweptRounds(ctx context.Context) ([]SelectSweptRoundsRow
|
||||
&i.PaymentVtxoVw.ExpireAt,
|
||||
&i.PaymentVtxoVw.PaymentID,
|
||||
&i.PaymentVtxoVw.RedeemTx,
|
||||
&i.PaymentVtxoVw.Descriptor,
|
||||
&i.PaymentVtxoVw.Pending,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@@ -595,7 +595,7 @@ func (q *Queries) SelectSweptRounds(ctx context.Context) ([]SelectSweptRoundsRow
|
||||
}
|
||||
|
||||
const selectVtxoByOutpoint = `-- name: SelectVtxoByOutpoint :one
|
||||
SELECT vtxo.txid, vtxo.vout, vtxo.amount, vtxo.pool_tx, vtxo.spent_by, vtxo.spent, vtxo.redeemed, vtxo.swept, vtxo.expire_at, vtxo.payment_id, vtxo.redeem_tx, vtxo.descriptor, vtxo.pending FROM vtxo
|
||||
SELECT vtxo.txid, vtxo.vout, vtxo.pubkey, vtxo.amount, vtxo.pool_tx, vtxo.spent_by, vtxo.spent, vtxo.redeemed, vtxo.swept, vtxo.expire_at, vtxo.payment_id, vtxo.redeem_tx, vtxo.pending FROM vtxo
|
||||
WHERE txid = ? AND vout = ?
|
||||
`
|
||||
|
||||
@@ -614,6 +614,7 @@ func (q *Queries) SelectVtxoByOutpoint(ctx context.Context, arg SelectVtxoByOutp
|
||||
err := row.Scan(
|
||||
&i.Vtxo.Txid,
|
||||
&i.Vtxo.Vout,
|
||||
&i.Vtxo.Pubkey,
|
||||
&i.Vtxo.Amount,
|
||||
&i.Vtxo.PoolTx,
|
||||
&i.Vtxo.SpentBy,
|
||||
@@ -623,14 +624,13 @@ func (q *Queries) SelectVtxoByOutpoint(ctx context.Context, arg SelectVtxoByOutp
|
||||
&i.Vtxo.ExpireAt,
|
||||
&i.Vtxo.PaymentID,
|
||||
&i.Vtxo.RedeemTx,
|
||||
&i.Vtxo.Descriptor,
|
||||
&i.Vtxo.Pending,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const selectVtxosByPoolTxid = `-- name: SelectVtxosByPoolTxid :many
|
||||
SELECT vtxo.txid, vtxo.vout, vtxo.amount, vtxo.pool_tx, vtxo.spent_by, vtxo.spent, vtxo.redeemed, vtxo.swept, vtxo.expire_at, vtxo.payment_id, vtxo.redeem_tx, vtxo.descriptor, vtxo.pending FROM vtxo
|
||||
SELECT vtxo.txid, vtxo.vout, vtxo.pubkey, vtxo.amount, vtxo.pool_tx, vtxo.spent_by, vtxo.spent, vtxo.redeemed, vtxo.swept, vtxo.expire_at, vtxo.payment_id, vtxo.redeem_tx, vtxo.pending FROM vtxo
|
||||
WHERE pool_tx = ?
|
||||
`
|
||||
|
||||
@@ -650,6 +650,7 @@ func (q *Queries) SelectVtxosByPoolTxid(ctx context.Context, poolTx string) ([]S
|
||||
if err := rows.Scan(
|
||||
&i.Vtxo.Txid,
|
||||
&i.Vtxo.Vout,
|
||||
&i.Vtxo.Pubkey,
|
||||
&i.Vtxo.Amount,
|
||||
&i.Vtxo.PoolTx,
|
||||
&i.Vtxo.SpentBy,
|
||||
@@ -659,7 +660,6 @@ func (q *Queries) SelectVtxosByPoolTxid(ctx context.Context, poolTx string) ([]S
|
||||
&i.Vtxo.ExpireAt,
|
||||
&i.Vtxo.PaymentID,
|
||||
&i.Vtxo.RedeemTx,
|
||||
&i.Vtxo.Descriptor,
|
||||
&i.Vtxo.Pending,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@@ -721,26 +721,26 @@ func (q *Queries) UpsertPayment(ctx context.Context, arg UpsertPaymentParams) er
|
||||
}
|
||||
|
||||
const upsertReceiver = `-- name: UpsertReceiver :exec
|
||||
INSERT INTO receiver (payment_id, descriptor, amount, onchain_address) VALUES (?, ?, ?, ?)
|
||||
ON CONFLICT(payment_id, descriptor) DO UPDATE SET
|
||||
INSERT INTO receiver (payment_id, pubkey, onchain_address, amount) VALUES (?, ?, ?, ?)
|
||||
ON CONFLICT(payment_id, pubkey, onchain_address) DO UPDATE SET
|
||||
amount = EXCLUDED.amount,
|
||||
onchain_address = EXCLUDED.onchain_address,
|
||||
descriptor = EXCLUDED.descriptor
|
||||
pubkey = EXCLUDED.pubkey,
|
||||
onchain_address = EXCLUDED.onchain_address
|
||||
`
|
||||
|
||||
type UpsertReceiverParams struct {
|
||||
PaymentID string
|
||||
Descriptor string
|
||||
Pubkey sql.NullString
|
||||
OnchainAddress sql.NullString
|
||||
Amount int64
|
||||
OnchainAddress string
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertReceiver(ctx context.Context, arg UpsertReceiverParams) error {
|
||||
_, err := q.db.ExecContext(ctx, upsertReceiver,
|
||||
arg.PaymentID,
|
||||
arg.Descriptor,
|
||||
arg.Amount,
|
||||
arg.Pubkey,
|
||||
arg.OnchainAddress,
|
||||
arg.Amount,
|
||||
)
|
||||
return err
|
||||
}
|
||||
@@ -847,9 +847,9 @@ func (q *Queries) UpsertTransaction(ctx context.Context, arg UpsertTransactionPa
|
||||
}
|
||||
|
||||
const upsertVtxo = `-- name: UpsertVtxo :exec
|
||||
INSERT INTO vtxo (txid, vout, descriptor, amount, pool_tx, spent_by, spent, redeemed, swept, expire_at, redeem_tx, pending)
|
||||
INSERT INTO vtxo (txid, vout, pubkey, amount, pool_tx, spent_by, spent, redeemed, swept, expire_at, redeem_tx, pending)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT(txid, vout) DO UPDATE SET
|
||||
descriptor = EXCLUDED.descriptor,
|
||||
pubkey = EXCLUDED.pubkey,
|
||||
amount = EXCLUDED.amount,
|
||||
pool_tx = EXCLUDED.pool_tx,
|
||||
spent_by = EXCLUDED.spent_by,
|
||||
@@ -862,25 +862,25 @@ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT(txid, vout) DO UPDATE SE
|
||||
`
|
||||
|
||||
type UpsertVtxoParams struct {
|
||||
Txid string
|
||||
Vout int64
|
||||
Descriptor sql.NullString
|
||||
Amount int64
|
||||
PoolTx string
|
||||
SpentBy string
|
||||
Spent bool
|
||||
Redeemed bool
|
||||
Swept bool
|
||||
ExpireAt int64
|
||||
RedeemTx sql.NullString
|
||||
Pending bool
|
||||
Txid string
|
||||
Vout int64
|
||||
Pubkey string
|
||||
Amount int64
|
||||
PoolTx string
|
||||
SpentBy string
|
||||
Spent bool
|
||||
Redeemed bool
|
||||
Swept bool
|
||||
ExpireAt int64
|
||||
RedeemTx sql.NullString
|
||||
Pending bool
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertVtxo(ctx context.Context, arg UpsertVtxoParams) error {
|
||||
_, err := q.db.ExecContext(ctx, upsertVtxo,
|
||||
arg.Txid,
|
||||
arg.Vout,
|
||||
arg.Descriptor,
|
||||
arg.Pubkey,
|
||||
arg.Amount,
|
||||
arg.PoolTx,
|
||||
arg.SpentBy,
|
||||
|
||||
@@ -44,11 +44,11 @@ INSERT INTO payment (id, round_id) VALUES (?, ?)
|
||||
ON CONFLICT(id) DO UPDATE SET round_id = EXCLUDED.round_id;
|
||||
|
||||
-- name: UpsertReceiver :exec
|
||||
INSERT INTO receiver (payment_id, descriptor, amount, onchain_address) VALUES (?, ?, ?, ?)
|
||||
ON CONFLICT(payment_id, descriptor) DO UPDATE SET
|
||||
INSERT INTO receiver (payment_id, pubkey, onchain_address, amount) VALUES (?, ?, ?, ?)
|
||||
ON CONFLICT(payment_id, pubkey, onchain_address) DO UPDATE SET
|
||||
amount = EXCLUDED.amount,
|
||||
onchain_address = EXCLUDED.onchain_address,
|
||||
descriptor = EXCLUDED.descriptor;
|
||||
pubkey = EXCLUDED.pubkey,
|
||||
onchain_address = EXCLUDED.onchain_address;
|
||||
|
||||
-- name: UpdateVtxoPaymentId :exec
|
||||
UPDATE vtxo SET payment_id = ? WHERE txid = ? AND vout = ?;
|
||||
@@ -112,9 +112,9 @@ SELECT id FROM round WHERE starting_timestamp > ? AND starting_timestamp < ?;
|
||||
SELECT id FROM round;
|
||||
|
||||
-- name: UpsertVtxo :exec
|
||||
INSERT INTO vtxo (txid, vout, descriptor, amount, pool_tx, spent_by, spent, redeemed, swept, expire_at, redeem_tx, pending)
|
||||
INSERT INTO vtxo (txid, vout, pubkey, amount, pool_tx, spent_by, spent, redeemed, swept, expire_at, redeem_tx, pending)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT(txid, vout) DO UPDATE SET
|
||||
descriptor = EXCLUDED.descriptor,
|
||||
pubkey = EXCLUDED.pubkey,
|
||||
amount = EXCLUDED.amount,
|
||||
pool_tx = EXCLUDED.pool_tx,
|
||||
spent_by = EXCLUDED.spent_by,
|
||||
@@ -135,7 +135,7 @@ WHERE redeemed = false;
|
||||
|
||||
-- name: SelectNotRedeemedVtxosWithPubkey :many
|
||||
SELECT sqlc.embed(vtxo) FROM vtxo
|
||||
WHERE redeemed = false AND INSTR(descriptor, ?) > 0;
|
||||
WHERE redeemed = false AND pubkey = ?;
|
||||
|
||||
-- name: SelectVtxoByOutpoint :one
|
||||
SELECT sqlc.embed(vtxo) FROM vtxo
|
||||
|
||||
@@ -37,20 +37,21 @@ func (v *vxtoRepository) AddVtxos(ctx context.Context, vtxos []domain.Vtxo) erro
|
||||
txBody := func(querierWithTx *queries.Queries) error {
|
||||
for i := range vtxos {
|
||||
vtxo := vtxos[i]
|
||||
|
||||
if err := querierWithTx.UpsertVtxo(
|
||||
ctx, queries.UpsertVtxoParams{
|
||||
Txid: vtxo.Txid,
|
||||
Vout: int64(vtxo.VOut),
|
||||
Descriptor: sql.NullString{String: vtxo.Descriptor, Valid: true},
|
||||
Amount: int64(vtxo.Amount),
|
||||
PoolTx: vtxo.RoundTxid,
|
||||
SpentBy: vtxo.SpentBy,
|
||||
Spent: vtxo.Spent,
|
||||
Redeemed: vtxo.Redeemed,
|
||||
Swept: vtxo.Swept,
|
||||
ExpireAt: vtxo.ExpireAt,
|
||||
RedeemTx: sql.NullString{String: vtxo.RedeemTx, Valid: true},
|
||||
Pending: vtxo.Pending,
|
||||
Txid: vtxo.Txid,
|
||||
Vout: int64(vtxo.VOut),
|
||||
Pubkey: vtxo.Pubkey,
|
||||
Amount: int64(vtxo.Amount),
|
||||
PoolTx: vtxo.RoundTxid,
|
||||
SpentBy: vtxo.SpentBy,
|
||||
Spent: vtxo.Spent,
|
||||
Redeemed: vtxo.Redeemed,
|
||||
Swept: vtxo.Swept,
|
||||
ExpireAt: vtxo.ExpireAt,
|
||||
RedeemTx: sql.NullString{String: vtxo.RedeemTx, Valid: true},
|
||||
Pending: vtxo.Pending,
|
||||
},
|
||||
); err != nil {
|
||||
return err
|
||||
@@ -81,10 +82,6 @@ func (v *vxtoRepository) GetAllVtxos(ctx context.Context, pubkey string) ([]doma
|
||||
|
||||
var rows []queries.Vtxo
|
||||
if withPubkey {
|
||||
if len(pubkey) == 66 {
|
||||
pubkey = pubkey[2:]
|
||||
}
|
||||
|
||||
res, err := v.querier.SelectNotRedeemedVtxosWithPubkey(ctx, pubkey)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -253,10 +250,8 @@ func rowToVtxo(row queries.Vtxo) domain.Vtxo {
|
||||
Txid: row.Txid,
|
||||
VOut: uint32(row.Vout),
|
||||
},
|
||||
Receiver: domain.Receiver{
|
||||
Descriptor: row.Descriptor.String,
|
||||
Amount: uint64(row.Amount),
|
||||
},
|
||||
Amount: uint64(row.Amount),
|
||||
Pubkey: row.Pubkey,
|
||||
RoundTxid: row.PoolTx,
|
||||
SpentBy: row.SpentBy,
|
||||
Spent: row.Spent,
|
||||
|
||||
Reference in New Issue
Block a user