mirror of
https://github.com/alexgo-io/gaze-indexer.git
synced 2026-01-12 22:43:22 +08:00
@@ -1,6 +1,6 @@
|
|||||||
BEGIN;
|
BEGIN;
|
||||||
|
|
||||||
CREATE EXTENSION pg_trgm;
|
CREATE EXTENSION IF NOT EXISTS pg_trgm;
|
||||||
-- Indexer Client Information
|
-- Indexer Client Information
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS "runes_indexer_stats" (
|
CREATE TABLE IF NOT EXISTS "runes_indexer_stats" (
|
||||||
|
|||||||
104
modules/runes/database/postgresql/queries/batch.sql
Normal file
104
modules/runes/database/postgresql/queries/batch.sql
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
-- name: BatchCreateRunesBalances :exec
|
||||||
|
INSERT INTO runes_balances ("pkscript", "block_height", "rune_id", "amount")
|
||||||
|
VALUES(
|
||||||
|
unnest(@pkscript_arr::TEXT[]),
|
||||||
|
unnest(@block_height_arr::INT[]),
|
||||||
|
unnest(@rune_id_arr::TEXT[]),
|
||||||
|
unnest(@amount_arr::DECIMAL[])
|
||||||
|
);
|
||||||
|
|
||||||
|
-- name: BatchCreateRuneEntries :exec
|
||||||
|
INSERT INTO runes_entries ("rune_id", "rune", "number", "spacers", "premine", "symbol", "divisibility", "terms", "terms_amount", "terms_cap", "terms_height_start", "terms_height_end", "terms_offset_start", "terms_offset_end", "turbo", "etching_block", "etching_tx_hash", "etched_at")
|
||||||
|
VALUES(
|
||||||
|
unnest(@rune_id_arr::TEXT[]),
|
||||||
|
unnest(@rune_arr::TEXT[]),
|
||||||
|
unnest(@number_arr::BIGINT[]),
|
||||||
|
unnest(@spacers_arr::INT[]),
|
||||||
|
unnest(@premine_arr::DECIMAL[]),
|
||||||
|
unnest(@symbol_arr::INT[]),
|
||||||
|
unnest(@divisibility_arr::SMALLINT[]),
|
||||||
|
unnest(@terms_arr::BOOLEAN[]),
|
||||||
|
unnest(@terms_amount_arr::DECIMAL[]),
|
||||||
|
unnest(@terms_cap_arr::DECIMAL[]),
|
||||||
|
unnest(@terms_height_start_arr::INT[]), -- nullable (need patch)
|
||||||
|
unnest(@terms_height_end_arr::INT[]), -- nullable (need patch)
|
||||||
|
unnest(@terms_offset_start_arr::INT[]), -- nullable (need patch)
|
||||||
|
unnest(@terms_offset_end_arr::INT[]), -- nullable (need patch)
|
||||||
|
unnest(@turbo_arr::BOOLEAN[]),
|
||||||
|
unnest(@etching_block_arr::INT[]),
|
||||||
|
unnest(@etching_tx_hash_arr::TEXT[]),
|
||||||
|
unnest(@etched_at_arr::TIMESTAMP[])
|
||||||
|
);
|
||||||
|
|
||||||
|
-- name: BatchCreateRuneEntryStates :exec
|
||||||
|
INSERT INTO runes_entry_states ("rune_id", "block_height", "mints", "burned_amount", "completed_at", "completed_at_height")
|
||||||
|
VALUES(
|
||||||
|
unnest(@rune_id_arr::TEXT[]),
|
||||||
|
unnest(@block_height_arr::INT[]),
|
||||||
|
unnest(@mints_arr::DECIMAL[]),
|
||||||
|
unnest(@burned_amount_arr::DECIMAL[]),
|
||||||
|
unnest(@completed_at_arr::TIMESTAMP[]),
|
||||||
|
unnest(@completed_at_height_arr::INT[]) -- nullable (need patch)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- name: BatchCreateRunesOutpointBalances :exec
|
||||||
|
INSERT INTO runes_outpoint_balances ("rune_id", "pkscript", "tx_hash", "tx_idx", "amount", "block_height", "spent_height")
|
||||||
|
VALUES(
|
||||||
|
unnest(@rune_id_arr::TEXT[]),
|
||||||
|
unnest(@pkscript_arr::TEXT[]),
|
||||||
|
unnest(@tx_hash_arr::TEXT[]),
|
||||||
|
unnest(@tx_idx_arr::INT[]),
|
||||||
|
unnest(@amount_arr::DECIMAL[]),
|
||||||
|
unnest(@block_height_arr::INT[]),
|
||||||
|
unnest(@spent_height_arr::INT[]) -- nullable (need patch)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- name: BatchSpendOutpointBalances :exec
|
||||||
|
UPDATE runes_outpoint_balances
|
||||||
|
SET "spent_height" = @spent_height::INT
|
||||||
|
FROM (
|
||||||
|
SELECT
|
||||||
|
unnest(@tx_hash_arr::TEXT[]) AS tx_hash,
|
||||||
|
unnest(@tx_idx_arr::INT[]) AS tx_idx
|
||||||
|
) AS input
|
||||||
|
WHERE "runes_outpoint_balances"."tx_hash" = "input"."tx_hash" AND "runes_outpoint_balances"."tx_idx" = "input"."tx_idx";
|
||||||
|
|
||||||
|
-- name: BatchCreateRunestones :exec
|
||||||
|
INSERT INTO runes_runestones ("tx_hash", "block_height", "etching", "etching_divisibility", "etching_premine", "etching_rune", "etching_spacers", "etching_symbol", "etching_terms", "etching_terms_amount", "etching_terms_cap", "etching_terms_height_start", "etching_terms_height_end", "etching_terms_offset_start", "etching_terms_offset_end", "etching_turbo", "edicts", "mint", "pointer", "cenotaph", "flaws")
|
||||||
|
VALUES(
|
||||||
|
unnest(@tx_hash_arr::TEXT[]),
|
||||||
|
unnest(@block_height_arr::INT[]),
|
||||||
|
unnest(@etching_arr::BOOLEAN[]),
|
||||||
|
unnest(@etching_divisibility_arr::SMALLINT[]), -- nullable (need patch)
|
||||||
|
unnest(@etching_premine_arr::DECIMAL[]),
|
||||||
|
unnest(@etching_rune_arr::TEXT[]), -- nullable (need patch)
|
||||||
|
unnest(@etching_spacers_arr::INT[]), -- nullable (need patch)
|
||||||
|
unnest(@etching_symbol_arr::INT[]), -- nullable (need patch)
|
||||||
|
unnest(@etching_terms_arr::BOOLEAN[]), -- nullable (need patch)
|
||||||
|
unnest(@etching_terms_amount_arr::DECIMAL[]),
|
||||||
|
unnest(@etching_terms_cap_arr::DECIMAL[]),
|
||||||
|
unnest(@etching_terms_height_start_arr::INT[]), -- nullable (need patch)
|
||||||
|
unnest(@etching_terms_height_end_arr::INT[]), -- nullable (need patch)
|
||||||
|
unnest(@etching_terms_offset_start_arr::INT[]), -- nullable (need patch)
|
||||||
|
unnest(@etching_terms_offset_end_arr::INT[]), -- nullable (need patch)
|
||||||
|
unnest(@etching_turbo_arr::BOOLEAN[]), -- nullable (need patch)
|
||||||
|
unnest(@edicts_arr::JSONB[]),
|
||||||
|
unnest(@mint_arr::TEXT[]), -- nullable (need patch)
|
||||||
|
unnest(@pointer_arr::INT[]), -- nullable (need patch)
|
||||||
|
unnest(@cenotaph_arr::BOOLEAN[]),
|
||||||
|
unnest(@flaws_arr::INT[])
|
||||||
|
);
|
||||||
|
|
||||||
|
-- name: BatchCreateRuneTransactions :exec
|
||||||
|
INSERT INTO runes_transactions ("hash", "block_height", "index", "timestamp", "inputs", "outputs", "mints", "burns", "rune_etched")
|
||||||
|
VALUES (
|
||||||
|
unnest(@hash_arr::TEXT[]),
|
||||||
|
unnest(@block_height_arr::INT[]),
|
||||||
|
unnest(@index_arr::INT[]),
|
||||||
|
unnest(@timestamp_arr::TIMESTAMP[]),
|
||||||
|
unnest(@inputs_arr::JSONB[]),
|
||||||
|
unnest(@outputs_arr::JSONB[]),
|
||||||
|
unnest(@mints_arr::JSONB[]),
|
||||||
|
unnest(@burns_arr::JSONB[]),
|
||||||
|
unnest(@rune_etched_arr::BOOLEAN[])
|
||||||
|
);
|
||||||
@@ -136,27 +136,27 @@ SELECT * FROM runes_transactions
|
|||||||
-- name: CountRuneEntries :one
|
-- name: CountRuneEntries :one
|
||||||
SELECT COUNT(*) FROM runes_entries;
|
SELECT COUNT(*) FROM runes_entries;
|
||||||
|
|
||||||
-- name: CreateRuneEntries :batchexec
|
-- name: CreateRuneEntry :exec
|
||||||
INSERT INTO runes_entries (rune_id, rune, number, spacers, premine, symbol, divisibility, terms, terms_amount, terms_cap, terms_height_start, terms_height_end, terms_offset_start, terms_offset_end, turbo, etching_block, etching_tx_hash, etched_at)
|
INSERT INTO runes_entries (rune_id, rune, number, spacers, premine, symbol, divisibility, terms, terms_amount, terms_cap, terms_height_start, terms_height_end, terms_offset_start, terms_offset_end, turbo, etching_block, etching_tx_hash, etched_at)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18);
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18);
|
||||||
|
|
||||||
-- name: CreateRuneEntryStates :batchexec
|
-- name: CreateRuneEntryState :exec
|
||||||
INSERT INTO runes_entry_states (rune_id, block_height, mints, burned_amount, completed_at, completed_at_height) VALUES ($1, $2, $3, $4, $5, $6);
|
INSERT INTO runes_entry_states (rune_id, block_height, mints, burned_amount, completed_at, completed_at_height) VALUES ($1, $2, $3, $4, $5, $6);
|
||||||
|
|
||||||
-- name: CreateRuneTransactions :batchexec
|
-- name: CreateRuneTransaction :exec
|
||||||
INSERT INTO runes_transactions (hash, block_height, index, timestamp, inputs, outputs, mints, burns, rune_etched) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9);
|
INSERT INTO runes_transactions (hash, block_height, index, timestamp, inputs, outputs, mints, burns, rune_etched) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9);
|
||||||
|
|
||||||
-- name: CreateRunestones :batchexec
|
-- name: CreateRunestone :exec
|
||||||
INSERT INTO runes_runestones (tx_hash, block_height, etching, etching_divisibility, etching_premine, etching_rune, etching_spacers, etching_symbol, etching_terms, etching_terms_amount, etching_terms_cap, etching_terms_height_start, etching_terms_height_end, etching_terms_offset_start, etching_terms_offset_end, etching_turbo, edicts, mint, pointer, cenotaph, flaws)
|
INSERT INTO runes_runestones (tx_hash, block_height, etching, etching_divisibility, etching_premine, etching_rune, etching_spacers, etching_symbol, etching_terms, etching_terms_amount, etching_terms_cap, etching_terms_height_start, etching_terms_height_end, etching_terms_offset_start, etching_terms_offset_end, etching_turbo, edicts, mint, pointer, cenotaph, flaws)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21);
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21);
|
||||||
|
|
||||||
-- name: CreateOutPointBalances :batchexec
|
-- name: CreateOutPointBalance :exec
|
||||||
INSERT INTO runes_outpoint_balances (rune_id, pkscript, tx_hash, tx_idx, amount, block_height, spent_height) VALUES ($1, $2, $3, $4, $5, $6, $7);
|
INSERT INTO runes_outpoint_balances (rune_id, pkscript, tx_hash, tx_idx, amount, block_height, spent_height) VALUES ($1, $2, $3, $4, $5, $6, $7);
|
||||||
|
|
||||||
-- name: SpendOutPointBalancesBatch :batchexec
|
-- name: SpendOutPointBalance :exec
|
||||||
UPDATE runes_outpoint_balances SET spent_height = $1 WHERE tx_hash = $2 AND tx_idx = $3;
|
UPDATE runes_outpoint_balances SET spent_height = $1 WHERE tx_hash = $2 AND tx_idx = $3;
|
||||||
|
|
||||||
-- name: CreateRuneBalanceAtBlock :batchexec
|
-- name: CreateRuneBalance :exec
|
||||||
INSERT INTO runes_balances (pkscript, block_height, rune_id, amount) VALUES ($1, $2, $3, $4);
|
INSERT INTO runes_balances (pkscript, block_height, rune_id, amount) VALUES ($1, $2, $3, $4);
|
||||||
|
|
||||||
-- name: GetLatestIndexedBlock :one
|
-- name: GetLatestIndexedBlock :one
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/gaze-network/indexer-network/core/types"
|
"github.com/gaze-network/indexer-network/core/types"
|
||||||
"github.com/gaze-network/indexer-network/modules/runes/internal/entity"
|
"github.com/gaze-network/indexer-network/modules/runes/internal/entity"
|
||||||
"github.com/gaze-network/indexer-network/modules/runes/runes"
|
"github.com/gaze-network/indexer-network/modules/runes/runes"
|
||||||
"github.com/gaze-network/uint128"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type RunesDataGateway interface {
|
type RunesDataGateway interface {
|
||||||
@@ -65,11 +64,11 @@ type RunesReaderDataGateway interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RunesWriterDataGateway interface {
|
type RunesWriterDataGateway interface {
|
||||||
CreateRuneEntries(ctx context.Context, entries []*runes.RuneEntry, blockHeight uint64) error
|
CreateRuneEntries(ctx context.Context, entries []*runes.RuneEntry) error
|
||||||
CreateRuneEntryStates(ctx context.Context, entries []*runes.RuneEntry, blockHeight uint64) error
|
CreateRuneEntryStates(ctx context.Context, entries []*runes.RuneEntry, blockHeight uint64) error
|
||||||
CreateOutPointBalances(ctx context.Context, outPointBalances []*entity.OutPointBalance) error
|
CreateOutPointBalances(ctx context.Context, outPointBalances []*entity.OutPointBalance) error
|
||||||
SpendOutPointBalancesBatch(ctx context.Context, outPoints []wire.OutPoint, blockHeight uint64) error
|
SpendOutPointBalancesBatch(ctx context.Context, outPoints []wire.OutPoint, blockHeight uint64) error
|
||||||
CreateRuneBalances(ctx context.Context, params []CreateRuneBalancesParams) error
|
CreateRuneBalances(ctx context.Context, params []*entity.Balance) error
|
||||||
CreateRuneTransactions(ctx context.Context, txs []*entity.RuneTransaction) error
|
CreateRuneTransactions(ctx context.Context, txs []*entity.RuneTransaction) error
|
||||||
CreateIndexedBlock(ctx context.Context, block *entity.IndexedBlock) error
|
CreateIndexedBlock(ctx context.Context, block *entity.IndexedBlock) error
|
||||||
|
|
||||||
@@ -83,10 +82,3 @@ type RunesWriterDataGateway interface {
|
|||||||
UnspendOutPointBalancesSinceHeight(ctx context.Context, height uint64) error
|
UnspendOutPointBalancesSinceHeight(ctx context.Context, height uint64) error
|
||||||
DeleteRuneBalancesSinceHeight(ctx context.Context, height uint64) error
|
DeleteRuneBalancesSinceHeight(ctx context.Context, height uint64) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateRuneBalancesParams struct {
|
|
||||||
PkScript []byte
|
|
||||||
RuneId runes.RuneId
|
|
||||||
Balance uint128.Uint128
|
|
||||||
BlockHeight uint64
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ func (p *Processor) ensureGenesisRune(ctx context.Context, network common.Networ
|
|||||||
EtchingTxHash: genesisRuneConfig.EtchingTxHash,
|
EtchingTxHash: genesisRuneConfig.EtchingTxHash,
|
||||||
EtchedAt: genesisRuneConfig.EtchedAt,
|
EtchedAt: genesisRuneConfig.EtchedAt,
|
||||||
}
|
}
|
||||||
if err := p.runesDg.CreateRuneEntries(ctx, []*runes.RuneEntry{runeEntry}, genesisRuneConfig.RuneId.BlockHeight); err != nil {
|
if err := p.runesDg.CreateRuneEntries(ctx, []*runes.RuneEntry{runeEntry}); err != nil {
|
||||||
return errors.Wrap(err, "failed to create genesis rune entry")
|
return errors.Wrap(err, "failed to create genesis rune entry")
|
||||||
}
|
}
|
||||||
if err := p.runesDg.CreateRuneEntryStates(ctx, []*runes.RuneEntry{runeEntry}, genesisRuneConfig.RuneId.BlockHeight); err != nil {
|
if err := p.runesDg.CreateRuneEntryStates(ctx, []*runes.RuneEntry{runeEntry}, genesisRuneConfig.RuneId.BlockHeight); err != nil {
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import (
|
|||||||
"github.com/gaze-network/indexer-network/common/errs"
|
"github.com/gaze-network/indexer-network/common/errs"
|
||||||
"github.com/gaze-network/indexer-network/core/types"
|
"github.com/gaze-network/indexer-network/core/types"
|
||||||
"github.com/gaze-network/indexer-network/modules/runes/constants"
|
"github.com/gaze-network/indexer-network/modules/runes/constants"
|
||||||
"github.com/gaze-network/indexer-network/modules/runes/datagateway"
|
|
||||||
"github.com/gaze-network/indexer-network/modules/runes/internal/entity"
|
"github.com/gaze-network/indexer-network/modules/runes/internal/entity"
|
||||||
"github.com/gaze-network/indexer-network/modules/runes/runes"
|
"github.com/gaze-network/indexer-network/modules/runes/runes"
|
||||||
"github.com/gaze-network/indexer-network/pkg/logger"
|
"github.com/gaze-network/indexer-network/pkg/logger"
|
||||||
@@ -724,7 +723,7 @@ func (p *Processor) flushBlock(ctx context.Context, blockHeader types.BlockHeade
|
|||||||
}
|
}
|
||||||
// flush new rune entries
|
// flush new rune entries
|
||||||
newRuneEntries := lo.Values(p.newRuneEntries)
|
newRuneEntries := lo.Values(p.newRuneEntries)
|
||||||
if err := runesDgTx.CreateRuneEntries(ctx, newRuneEntries, uint64(blockHeader.Height)); err != nil {
|
if err := runesDgTx.CreateRuneEntries(ctx, newRuneEntries); err != nil {
|
||||||
return errors.Wrap(err, "failed to create rune entry")
|
return errors.Wrap(err, "failed to create rune entry")
|
||||||
}
|
}
|
||||||
p.newRuneEntries = make(map[runes.RuneId]*runes.RuneEntry)
|
p.newRuneEntries = make(map[runes.RuneId]*runes.RuneEntry)
|
||||||
@@ -737,11 +736,11 @@ func (p *Processor) flushBlock(ctx context.Context, blockHeader types.BlockHeade
|
|||||||
p.newRuneEntryStates = make(map[runes.RuneId]*runes.RuneEntry)
|
p.newRuneEntryStates = make(map[runes.RuneId]*runes.RuneEntry)
|
||||||
|
|
||||||
// flush new outpoint balances
|
// flush new outpoint balances
|
||||||
newBalances := make([]*entity.OutPointBalance, 0)
|
newOutpointBalances := make([]*entity.OutPointBalance, 0)
|
||||||
for _, balances := range p.newOutPointBalances {
|
for _, balances := range p.newOutPointBalances {
|
||||||
newBalances = append(newBalances, balances...)
|
newOutpointBalances = append(newOutpointBalances, balances...)
|
||||||
}
|
}
|
||||||
if err := runesDgTx.CreateOutPointBalances(ctx, newBalances); err != nil {
|
if err := runesDgTx.CreateOutPointBalances(ctx, newOutpointBalances); err != nil {
|
||||||
return errors.Wrap(err, "failed to create outpoint balances")
|
return errors.Wrap(err, "failed to create outpoint balances")
|
||||||
}
|
}
|
||||||
p.newOutPointBalances = make(map[wire.OutPoint][]*entity.OutPointBalance)
|
p.newOutPointBalances = make(map[wire.OutPoint][]*entity.OutPointBalance)
|
||||||
@@ -753,23 +752,23 @@ func (p *Processor) flushBlock(ctx context.Context, blockHeader types.BlockHeade
|
|||||||
}
|
}
|
||||||
p.newSpendOutPoints = make([]wire.OutPoint, 0)
|
p.newSpendOutPoints = make([]wire.OutPoint, 0)
|
||||||
|
|
||||||
// flush new balances
|
// flush new newBalances
|
||||||
params := make([]datagateway.CreateRuneBalancesParams, 0)
|
newBalances := make([]*entity.Balance, 0)
|
||||||
for pkScriptStr, balances := range p.newBalances {
|
for pkScriptStr, balances := range p.newBalances {
|
||||||
pkScript, err := hex.DecodeString(pkScriptStr)
|
pkScript, err := hex.DecodeString(pkScriptStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to decode pk script")
|
return errors.Wrap(err, "failed to decode pk script")
|
||||||
}
|
}
|
||||||
for runeId, balance := range balances {
|
for runeId, balance := range balances {
|
||||||
params = append(params, datagateway.CreateRuneBalancesParams{
|
newBalances = append(newBalances, &entity.Balance{
|
||||||
PkScript: pkScript,
|
PkScript: pkScript,
|
||||||
RuneId: runeId,
|
RuneId: runeId,
|
||||||
Balance: balance,
|
Amount: balance,
|
||||||
BlockHeight: uint64(blockHeader.Height),
|
BlockHeight: uint64(blockHeader.Height),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := runesDgTx.CreateRuneBalances(ctx, params); err != nil {
|
if err := runesDgTx.CreateRuneBalances(ctx, newBalances); err != nil {
|
||||||
return errors.Wrap(err, "failed to create balances at block")
|
return errors.Wrap(err, "failed to create balances at block")
|
||||||
}
|
}
|
||||||
p.newBalances = make(map[string]map[runes.RuneId]uint128.Uint128)
|
p.newBalances = make(map[string]map[runes.RuneId]uint128.Uint128)
|
||||||
@@ -793,9 +792,9 @@ func (p *Processor) flushBlock(ctx context.Context, blockHeader types.BlockHeade
|
|||||||
slog.String("cumulative_event_hash", hex.EncodeToString(cumulativeEventHash[:])),
|
slog.String("cumulative_event_hash", hex.EncodeToString(cumulativeEventHash[:])),
|
||||||
slog.Int("new_rune_entries", len(newRuneEntries)),
|
slog.Int("new_rune_entries", len(newRuneEntries)),
|
||||||
slog.Int("new_rune_entry_states", len(newRuneEntryStates)),
|
slog.Int("new_rune_entry_states", len(newRuneEntryStates)),
|
||||||
slog.Int("new_outpoint_balances", len(newBalances)),
|
slog.Int("new_outpoint_balances", len(newOutpointBalances)),
|
||||||
slog.Int("new_spend_outpoints", len(newSpendOutPoints)),
|
slog.Int("new_spend_outpoints", len(newSpendOutPoints)),
|
||||||
slog.Int("new_balances", len(params)),
|
slog.Int("new_balances", len(newBalances)),
|
||||||
slog.Int("new_rune_txs", len(newRuneTxs)),
|
slog.Int("new_rune_txs", len(newRuneTxs)),
|
||||||
slogx.Duration("time_taken", timeTaken),
|
slogx.Duration("time_taken", timeTaken),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,471 +0,0 @@
|
|||||||
// Code generated by sqlc. DO NOT EDIT.
|
|
||||||
// versions:
|
|
||||||
// sqlc v1.27.0
|
|
||||||
// source: batch.go
|
|
||||||
|
|
||||||
package gen
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/jackc/pgx/v5"
|
|
||||||
"github.com/jackc/pgx/v5/pgtype"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
ErrBatchAlreadyClosed = errors.New("batch already closed")
|
|
||||||
)
|
|
||||||
|
|
||||||
const createOutPointBalances = `-- name: CreateOutPointBalances :batchexec
|
|
||||||
INSERT INTO runes_outpoint_balances (rune_id, pkscript, tx_hash, tx_idx, amount, block_height, spent_height) VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
||||||
`
|
|
||||||
|
|
||||||
type CreateOutPointBalancesBatchResults struct {
|
|
||||||
br pgx.BatchResults
|
|
||||||
tot int
|
|
||||||
closed bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type CreateOutPointBalancesParams struct {
|
|
||||||
RuneID string
|
|
||||||
Pkscript string
|
|
||||||
TxHash string
|
|
||||||
TxIdx int32
|
|
||||||
Amount pgtype.Numeric
|
|
||||||
BlockHeight int32
|
|
||||||
SpentHeight pgtype.Int4
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *Queries) CreateOutPointBalances(ctx context.Context, arg []CreateOutPointBalancesParams) *CreateOutPointBalancesBatchResults {
|
|
||||||
batch := &pgx.Batch{}
|
|
||||||
for _, a := range arg {
|
|
||||||
vals := []interface{}{
|
|
||||||
a.RuneID,
|
|
||||||
a.Pkscript,
|
|
||||||
a.TxHash,
|
|
||||||
a.TxIdx,
|
|
||||||
a.Amount,
|
|
||||||
a.BlockHeight,
|
|
||||||
a.SpentHeight,
|
|
||||||
}
|
|
||||||
batch.Queue(createOutPointBalances, vals...)
|
|
||||||
}
|
|
||||||
br := q.db.SendBatch(ctx, batch)
|
|
||||||
return &CreateOutPointBalancesBatchResults{br, len(arg), false}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *CreateOutPointBalancesBatchResults) Exec(f func(int, error)) {
|
|
||||||
defer b.br.Close()
|
|
||||||
for t := 0; t < b.tot; t++ {
|
|
||||||
if b.closed {
|
|
||||||
if f != nil {
|
|
||||||
f(t, ErrBatchAlreadyClosed)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
_, err := b.br.Exec()
|
|
||||||
if f != nil {
|
|
||||||
f(t, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *CreateOutPointBalancesBatchResults) Close() error {
|
|
||||||
b.closed = true
|
|
||||||
return b.br.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
const createRuneBalanceAtBlock = `-- name: CreateRuneBalanceAtBlock :batchexec
|
|
||||||
INSERT INTO runes_balances (pkscript, block_height, rune_id, amount) VALUES ($1, $2, $3, $4)
|
|
||||||
`
|
|
||||||
|
|
||||||
type CreateRuneBalanceAtBlockBatchResults struct {
|
|
||||||
br pgx.BatchResults
|
|
||||||
tot int
|
|
||||||
closed bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type CreateRuneBalanceAtBlockParams struct {
|
|
||||||
Pkscript string
|
|
||||||
BlockHeight int32
|
|
||||||
RuneID string
|
|
||||||
Amount pgtype.Numeric
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *Queries) CreateRuneBalanceAtBlock(ctx context.Context, arg []CreateRuneBalanceAtBlockParams) *CreateRuneBalanceAtBlockBatchResults {
|
|
||||||
batch := &pgx.Batch{}
|
|
||||||
for _, a := range arg {
|
|
||||||
vals := []interface{}{
|
|
||||||
a.Pkscript,
|
|
||||||
a.BlockHeight,
|
|
||||||
a.RuneID,
|
|
||||||
a.Amount,
|
|
||||||
}
|
|
||||||
batch.Queue(createRuneBalanceAtBlock, vals...)
|
|
||||||
}
|
|
||||||
br := q.db.SendBatch(ctx, batch)
|
|
||||||
return &CreateRuneBalanceAtBlockBatchResults{br, len(arg), false}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *CreateRuneBalanceAtBlockBatchResults) Exec(f func(int, error)) {
|
|
||||||
defer b.br.Close()
|
|
||||||
for t := 0; t < b.tot; t++ {
|
|
||||||
if b.closed {
|
|
||||||
if f != nil {
|
|
||||||
f(t, ErrBatchAlreadyClosed)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
_, err := b.br.Exec()
|
|
||||||
if f != nil {
|
|
||||||
f(t, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *CreateRuneBalanceAtBlockBatchResults) Close() error {
|
|
||||||
b.closed = true
|
|
||||||
return b.br.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
const createRuneEntries = `-- name: CreateRuneEntries :batchexec
|
|
||||||
INSERT INTO runes_entries (rune_id, rune, number, spacers, premine, symbol, divisibility, terms, terms_amount, terms_cap, terms_height_start, terms_height_end, terms_offset_start, terms_offset_end, turbo, etching_block, etching_tx_hash, etched_at)
|
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)
|
|
||||||
`
|
|
||||||
|
|
||||||
type CreateRuneEntriesBatchResults struct {
|
|
||||||
br pgx.BatchResults
|
|
||||||
tot int
|
|
||||||
closed bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type CreateRuneEntriesParams struct {
|
|
||||||
RuneID string
|
|
||||||
Rune string
|
|
||||||
Number int64
|
|
||||||
Spacers int32
|
|
||||||
Premine pgtype.Numeric
|
|
||||||
Symbol int32
|
|
||||||
Divisibility int16
|
|
||||||
Terms bool
|
|
||||||
TermsAmount pgtype.Numeric
|
|
||||||
TermsCap pgtype.Numeric
|
|
||||||
TermsHeightStart pgtype.Int4
|
|
||||||
TermsHeightEnd pgtype.Int4
|
|
||||||
TermsOffsetStart pgtype.Int4
|
|
||||||
TermsOffsetEnd pgtype.Int4
|
|
||||||
Turbo bool
|
|
||||||
EtchingBlock int32
|
|
||||||
EtchingTxHash string
|
|
||||||
EtchedAt pgtype.Timestamp
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *Queries) CreateRuneEntries(ctx context.Context, arg []CreateRuneEntriesParams) *CreateRuneEntriesBatchResults {
|
|
||||||
batch := &pgx.Batch{}
|
|
||||||
for _, a := range arg {
|
|
||||||
vals := []interface{}{
|
|
||||||
a.RuneID,
|
|
||||||
a.Rune,
|
|
||||||
a.Number,
|
|
||||||
a.Spacers,
|
|
||||||
a.Premine,
|
|
||||||
a.Symbol,
|
|
||||||
a.Divisibility,
|
|
||||||
a.Terms,
|
|
||||||
a.TermsAmount,
|
|
||||||
a.TermsCap,
|
|
||||||
a.TermsHeightStart,
|
|
||||||
a.TermsHeightEnd,
|
|
||||||
a.TermsOffsetStart,
|
|
||||||
a.TermsOffsetEnd,
|
|
||||||
a.Turbo,
|
|
||||||
a.EtchingBlock,
|
|
||||||
a.EtchingTxHash,
|
|
||||||
a.EtchedAt,
|
|
||||||
}
|
|
||||||
batch.Queue(createRuneEntries, vals...)
|
|
||||||
}
|
|
||||||
br := q.db.SendBatch(ctx, batch)
|
|
||||||
return &CreateRuneEntriesBatchResults{br, len(arg), false}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *CreateRuneEntriesBatchResults) Exec(f func(int, error)) {
|
|
||||||
defer b.br.Close()
|
|
||||||
for t := 0; t < b.tot; t++ {
|
|
||||||
if b.closed {
|
|
||||||
if f != nil {
|
|
||||||
f(t, ErrBatchAlreadyClosed)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
_, err := b.br.Exec()
|
|
||||||
if f != nil {
|
|
||||||
f(t, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *CreateRuneEntriesBatchResults) Close() error {
|
|
||||||
b.closed = true
|
|
||||||
return b.br.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
const createRuneEntryStates = `-- name: CreateRuneEntryStates :batchexec
|
|
||||||
INSERT INTO runes_entry_states (rune_id, block_height, mints, burned_amount, completed_at, completed_at_height) VALUES ($1, $2, $3, $4, $5, $6)
|
|
||||||
`
|
|
||||||
|
|
||||||
type CreateRuneEntryStatesBatchResults struct {
|
|
||||||
br pgx.BatchResults
|
|
||||||
tot int
|
|
||||||
closed bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type CreateRuneEntryStatesParams struct {
|
|
||||||
RuneID string
|
|
||||||
BlockHeight int32
|
|
||||||
Mints pgtype.Numeric
|
|
||||||
BurnedAmount pgtype.Numeric
|
|
||||||
CompletedAt pgtype.Timestamp
|
|
||||||
CompletedAtHeight pgtype.Int4
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *Queries) CreateRuneEntryStates(ctx context.Context, arg []CreateRuneEntryStatesParams) *CreateRuneEntryStatesBatchResults {
|
|
||||||
batch := &pgx.Batch{}
|
|
||||||
for _, a := range arg {
|
|
||||||
vals := []interface{}{
|
|
||||||
a.RuneID,
|
|
||||||
a.BlockHeight,
|
|
||||||
a.Mints,
|
|
||||||
a.BurnedAmount,
|
|
||||||
a.CompletedAt,
|
|
||||||
a.CompletedAtHeight,
|
|
||||||
}
|
|
||||||
batch.Queue(createRuneEntryStates, vals...)
|
|
||||||
}
|
|
||||||
br := q.db.SendBatch(ctx, batch)
|
|
||||||
return &CreateRuneEntryStatesBatchResults{br, len(arg), false}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *CreateRuneEntryStatesBatchResults) Exec(f func(int, error)) {
|
|
||||||
defer b.br.Close()
|
|
||||||
for t := 0; t < b.tot; t++ {
|
|
||||||
if b.closed {
|
|
||||||
if f != nil {
|
|
||||||
f(t, ErrBatchAlreadyClosed)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
_, err := b.br.Exec()
|
|
||||||
if f != nil {
|
|
||||||
f(t, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *CreateRuneEntryStatesBatchResults) Close() error {
|
|
||||||
b.closed = true
|
|
||||||
return b.br.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
const createRuneTransactions = `-- name: CreateRuneTransactions :batchexec
|
|
||||||
INSERT INTO runes_transactions (hash, block_height, index, timestamp, inputs, outputs, mints, burns, rune_etched) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
||||||
`
|
|
||||||
|
|
||||||
type CreateRuneTransactionsBatchResults struct {
|
|
||||||
br pgx.BatchResults
|
|
||||||
tot int
|
|
||||||
closed bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type CreateRuneTransactionsParams struct {
|
|
||||||
Hash string
|
|
||||||
BlockHeight int32
|
|
||||||
Index int32
|
|
||||||
Timestamp pgtype.Timestamp
|
|
||||||
Inputs []byte
|
|
||||||
Outputs []byte
|
|
||||||
Mints []byte
|
|
||||||
Burns []byte
|
|
||||||
RuneEtched bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *Queries) CreateRuneTransactions(ctx context.Context, arg []CreateRuneTransactionsParams) *CreateRuneTransactionsBatchResults {
|
|
||||||
batch := &pgx.Batch{}
|
|
||||||
for _, a := range arg {
|
|
||||||
vals := []interface{}{
|
|
||||||
a.Hash,
|
|
||||||
a.BlockHeight,
|
|
||||||
a.Index,
|
|
||||||
a.Timestamp,
|
|
||||||
a.Inputs,
|
|
||||||
a.Outputs,
|
|
||||||
a.Mints,
|
|
||||||
a.Burns,
|
|
||||||
a.RuneEtched,
|
|
||||||
}
|
|
||||||
batch.Queue(createRuneTransactions, vals...)
|
|
||||||
}
|
|
||||||
br := q.db.SendBatch(ctx, batch)
|
|
||||||
return &CreateRuneTransactionsBatchResults{br, len(arg), false}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *CreateRuneTransactionsBatchResults) Exec(f func(int, error)) {
|
|
||||||
defer b.br.Close()
|
|
||||||
for t := 0; t < b.tot; t++ {
|
|
||||||
if b.closed {
|
|
||||||
if f != nil {
|
|
||||||
f(t, ErrBatchAlreadyClosed)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
_, err := b.br.Exec()
|
|
||||||
if f != nil {
|
|
||||||
f(t, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *CreateRuneTransactionsBatchResults) Close() error {
|
|
||||||
b.closed = true
|
|
||||||
return b.br.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
const createRunestones = `-- name: CreateRunestones :batchexec
|
|
||||||
INSERT INTO runes_runestones (tx_hash, block_height, etching, etching_divisibility, etching_premine, etching_rune, etching_spacers, etching_symbol, etching_terms, etching_terms_amount, etching_terms_cap, etching_terms_height_start, etching_terms_height_end, etching_terms_offset_start, etching_terms_offset_end, etching_turbo, edicts, mint, pointer, cenotaph, flaws)
|
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21)
|
|
||||||
`
|
|
||||||
|
|
||||||
type CreateRunestonesBatchResults struct {
|
|
||||||
br pgx.BatchResults
|
|
||||||
tot int
|
|
||||||
closed bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type CreateRunestonesParams struct {
|
|
||||||
TxHash string
|
|
||||||
BlockHeight int32
|
|
||||||
Etching bool
|
|
||||||
EtchingDivisibility pgtype.Int2
|
|
||||||
EtchingPremine pgtype.Numeric
|
|
||||||
EtchingRune pgtype.Text
|
|
||||||
EtchingSpacers pgtype.Int4
|
|
||||||
EtchingSymbol pgtype.Int4
|
|
||||||
EtchingTerms pgtype.Bool
|
|
||||||
EtchingTermsAmount pgtype.Numeric
|
|
||||||
EtchingTermsCap pgtype.Numeric
|
|
||||||
EtchingTermsHeightStart pgtype.Int4
|
|
||||||
EtchingTermsHeightEnd pgtype.Int4
|
|
||||||
EtchingTermsOffsetStart pgtype.Int4
|
|
||||||
EtchingTermsOffsetEnd pgtype.Int4
|
|
||||||
EtchingTurbo pgtype.Bool
|
|
||||||
Edicts []byte
|
|
||||||
Mint pgtype.Text
|
|
||||||
Pointer pgtype.Int4
|
|
||||||
Cenotaph bool
|
|
||||||
Flaws int32
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *Queries) CreateRunestones(ctx context.Context, arg []CreateRunestonesParams) *CreateRunestonesBatchResults {
|
|
||||||
batch := &pgx.Batch{}
|
|
||||||
for _, a := range arg {
|
|
||||||
vals := []interface{}{
|
|
||||||
a.TxHash,
|
|
||||||
a.BlockHeight,
|
|
||||||
a.Etching,
|
|
||||||
a.EtchingDivisibility,
|
|
||||||
a.EtchingPremine,
|
|
||||||
a.EtchingRune,
|
|
||||||
a.EtchingSpacers,
|
|
||||||
a.EtchingSymbol,
|
|
||||||
a.EtchingTerms,
|
|
||||||
a.EtchingTermsAmount,
|
|
||||||
a.EtchingTermsCap,
|
|
||||||
a.EtchingTermsHeightStart,
|
|
||||||
a.EtchingTermsHeightEnd,
|
|
||||||
a.EtchingTermsOffsetStart,
|
|
||||||
a.EtchingTermsOffsetEnd,
|
|
||||||
a.EtchingTurbo,
|
|
||||||
a.Edicts,
|
|
||||||
a.Mint,
|
|
||||||
a.Pointer,
|
|
||||||
a.Cenotaph,
|
|
||||||
a.Flaws,
|
|
||||||
}
|
|
||||||
batch.Queue(createRunestones, vals...)
|
|
||||||
}
|
|
||||||
br := q.db.SendBatch(ctx, batch)
|
|
||||||
return &CreateRunestonesBatchResults{br, len(arg), false}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *CreateRunestonesBatchResults) Exec(f func(int, error)) {
|
|
||||||
defer b.br.Close()
|
|
||||||
for t := 0; t < b.tot; t++ {
|
|
||||||
if b.closed {
|
|
||||||
if f != nil {
|
|
||||||
f(t, ErrBatchAlreadyClosed)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
_, err := b.br.Exec()
|
|
||||||
if f != nil {
|
|
||||||
f(t, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *CreateRunestonesBatchResults) Close() error {
|
|
||||||
b.closed = true
|
|
||||||
return b.br.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
const spendOutPointBalancesBatch = `-- name: SpendOutPointBalancesBatch :batchexec
|
|
||||||
UPDATE runes_outpoint_balances SET spent_height = $1 WHERE tx_hash = $2 AND tx_idx = $3
|
|
||||||
`
|
|
||||||
|
|
||||||
type SpendOutPointBalancesBatchBatchResults struct {
|
|
||||||
br pgx.BatchResults
|
|
||||||
tot int
|
|
||||||
closed bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type SpendOutPointBalancesBatchParams struct {
|
|
||||||
SpentHeight pgtype.Int4
|
|
||||||
TxHash string
|
|
||||||
TxIdx int32
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *Queries) SpendOutPointBalancesBatch(ctx context.Context, arg []SpendOutPointBalancesBatchParams) *SpendOutPointBalancesBatchBatchResults {
|
|
||||||
batch := &pgx.Batch{}
|
|
||||||
for _, a := range arg {
|
|
||||||
vals := []interface{}{
|
|
||||||
a.SpentHeight,
|
|
||||||
a.TxHash,
|
|
||||||
a.TxIdx,
|
|
||||||
}
|
|
||||||
batch.Queue(spendOutPointBalancesBatch, vals...)
|
|
||||||
}
|
|
||||||
br := q.db.SendBatch(ctx, batch)
|
|
||||||
return &SpendOutPointBalancesBatchBatchResults{br, len(arg), false}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *SpendOutPointBalancesBatchBatchResults) Exec(f func(int, error)) {
|
|
||||||
defer b.br.Close()
|
|
||||||
for t := 0; t < b.tot; t++ {
|
|
||||||
if b.closed {
|
|
||||||
if f != nil {
|
|
||||||
f(t, ErrBatchAlreadyClosed)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
_, err := b.br.Exec()
|
|
||||||
if f != nil {
|
|
||||||
f(t, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *SpendOutPointBalancesBatchBatchResults) Close() error {
|
|
||||||
b.closed = true
|
|
||||||
return b.br.Close()
|
|
||||||
}
|
|
||||||
319
modules/runes/repository/postgres/gen/batch.sql.go
Normal file
319
modules/runes/repository/postgres/gen/batch.sql.go
Normal file
@@ -0,0 +1,319 @@
|
|||||||
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// sqlc v1.27.0
|
||||||
|
// source: batch.sql
|
||||||
|
|
||||||
|
package gen
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
|
)
|
||||||
|
|
||||||
|
const batchCreateRuneEntries = `-- name: BatchCreateRuneEntries :exec
|
||||||
|
INSERT INTO runes_entries ("rune_id", "rune", "number", "spacers", "premine", "symbol", "divisibility", "terms", "terms_amount", "terms_cap", "terms_height_start", "terms_height_end", "terms_offset_start", "terms_offset_end", "turbo", "etching_block", "etching_tx_hash", "etched_at")
|
||||||
|
VALUES(
|
||||||
|
unnest($1::TEXT[]),
|
||||||
|
unnest($2::TEXT[]),
|
||||||
|
unnest($3::BIGINT[]),
|
||||||
|
unnest($4::INT[]),
|
||||||
|
unnest($5::DECIMAL[]),
|
||||||
|
unnest($6::INT[]),
|
||||||
|
unnest($7::SMALLINT[]),
|
||||||
|
unnest($8::BOOLEAN[]),
|
||||||
|
unnest($9::DECIMAL[]),
|
||||||
|
unnest($10::DECIMAL[]),
|
||||||
|
unnest($11::INT[]), -- nullable (need patch)
|
||||||
|
unnest($12::INT[]), -- nullable (need patch)
|
||||||
|
unnest($13::INT[]), -- nullable (need patch)
|
||||||
|
unnest($14::INT[]), -- nullable (need patch)
|
||||||
|
unnest($15::BOOLEAN[]),
|
||||||
|
unnest($16::INT[]),
|
||||||
|
unnest($17::TEXT[]),
|
||||||
|
unnest($18::TIMESTAMP[])
|
||||||
|
)
|
||||||
|
`
|
||||||
|
|
||||||
|
type BatchCreateRuneEntriesParams struct {
|
||||||
|
RuneIDArr []string
|
||||||
|
RuneArr []string
|
||||||
|
NumberArr []int64
|
||||||
|
SpacersArr []int32
|
||||||
|
PremineArr []pgtype.Numeric
|
||||||
|
SymbolArr []int32
|
||||||
|
DivisibilityArr []int16
|
||||||
|
TermsArr []bool
|
||||||
|
TermsAmountArr []pgtype.Numeric
|
||||||
|
TermsCapArr []pgtype.Numeric
|
||||||
|
TermsHeightStartArr []int32
|
||||||
|
TermsHeightEndArr []int32
|
||||||
|
TermsOffsetStartArr []int32
|
||||||
|
TermsOffsetEndArr []int32
|
||||||
|
TurboArr []bool
|
||||||
|
EtchingBlockArr []int32
|
||||||
|
EtchingTxHashArr []string
|
||||||
|
EtchedAtArr []pgtype.Timestamp
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) BatchCreateRuneEntries(ctx context.Context, arg BatchCreateRuneEntriesParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, batchCreateRuneEntries,
|
||||||
|
arg.RuneIDArr,
|
||||||
|
arg.RuneArr,
|
||||||
|
arg.NumberArr,
|
||||||
|
arg.SpacersArr,
|
||||||
|
arg.PremineArr,
|
||||||
|
arg.SymbolArr,
|
||||||
|
arg.DivisibilityArr,
|
||||||
|
arg.TermsArr,
|
||||||
|
arg.TermsAmountArr,
|
||||||
|
arg.TermsCapArr,
|
||||||
|
arg.TermsHeightStartArr,
|
||||||
|
arg.TermsHeightEndArr,
|
||||||
|
arg.TermsOffsetStartArr,
|
||||||
|
arg.TermsOffsetEndArr,
|
||||||
|
arg.TurboArr,
|
||||||
|
arg.EtchingBlockArr,
|
||||||
|
arg.EtchingTxHashArr,
|
||||||
|
arg.EtchedAtArr,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const batchCreateRuneEntryStates = `-- name: BatchCreateRuneEntryStates :exec
|
||||||
|
INSERT INTO runes_entry_states ("rune_id", "block_height", "mints", "burned_amount", "completed_at", "completed_at_height")
|
||||||
|
VALUES(
|
||||||
|
unnest($1::TEXT[]),
|
||||||
|
unnest($2::INT[]),
|
||||||
|
unnest($3::DECIMAL[]),
|
||||||
|
unnest($4::DECIMAL[]),
|
||||||
|
unnest($5::TIMESTAMP[]),
|
||||||
|
unnest($6::INT[]) -- nullable (need patch)
|
||||||
|
)
|
||||||
|
`
|
||||||
|
|
||||||
|
type BatchCreateRuneEntryStatesParams struct {
|
||||||
|
RuneIDArr []string
|
||||||
|
BlockHeightArr []int32
|
||||||
|
MintsArr []pgtype.Numeric
|
||||||
|
BurnedAmountArr []pgtype.Numeric
|
||||||
|
CompletedAtArr []pgtype.Timestamp
|
||||||
|
CompletedAtHeightArr []int32
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) BatchCreateRuneEntryStates(ctx context.Context, arg BatchCreateRuneEntryStatesParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, batchCreateRuneEntryStates,
|
||||||
|
arg.RuneIDArr,
|
||||||
|
arg.BlockHeightArr,
|
||||||
|
arg.MintsArr,
|
||||||
|
arg.BurnedAmountArr,
|
||||||
|
arg.CompletedAtArr,
|
||||||
|
arg.CompletedAtHeightArr,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const batchCreateRuneTransactions = `-- name: BatchCreateRuneTransactions :exec
|
||||||
|
INSERT INTO runes_transactions ("hash", "block_height", "index", "timestamp", "inputs", "outputs", "mints", "burns", "rune_etched")
|
||||||
|
VALUES (
|
||||||
|
unnest($1::TEXT[]),
|
||||||
|
unnest($2::INT[]),
|
||||||
|
unnest($3::INT[]),
|
||||||
|
unnest($4::TIMESTAMP[]),
|
||||||
|
unnest($5::JSONB[]),
|
||||||
|
unnest($6::JSONB[]),
|
||||||
|
unnest($7::JSONB[]),
|
||||||
|
unnest($8::JSONB[]),
|
||||||
|
unnest($9::BOOLEAN[])
|
||||||
|
)
|
||||||
|
`
|
||||||
|
|
||||||
|
type BatchCreateRuneTransactionsParams struct {
|
||||||
|
HashArr []string
|
||||||
|
BlockHeightArr []int32
|
||||||
|
IndexArr []int32
|
||||||
|
TimestampArr []pgtype.Timestamp
|
||||||
|
InputsArr [][]byte
|
||||||
|
OutputsArr [][]byte
|
||||||
|
MintsArr [][]byte
|
||||||
|
BurnsArr [][]byte
|
||||||
|
RuneEtchedArr []bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) BatchCreateRuneTransactions(ctx context.Context, arg BatchCreateRuneTransactionsParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, batchCreateRuneTransactions,
|
||||||
|
arg.HashArr,
|
||||||
|
arg.BlockHeightArr,
|
||||||
|
arg.IndexArr,
|
||||||
|
arg.TimestampArr,
|
||||||
|
arg.InputsArr,
|
||||||
|
arg.OutputsArr,
|
||||||
|
arg.MintsArr,
|
||||||
|
arg.BurnsArr,
|
||||||
|
arg.RuneEtchedArr,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const batchCreateRunesBalances = `-- name: BatchCreateRunesBalances :exec
|
||||||
|
INSERT INTO runes_balances ("pkscript", "block_height", "rune_id", "amount")
|
||||||
|
VALUES(
|
||||||
|
unnest($1::TEXT[]),
|
||||||
|
unnest($2::INT[]),
|
||||||
|
unnest($3::TEXT[]),
|
||||||
|
unnest($4::DECIMAL[])
|
||||||
|
)
|
||||||
|
`
|
||||||
|
|
||||||
|
type BatchCreateRunesBalancesParams struct {
|
||||||
|
PkscriptArr []string
|
||||||
|
BlockHeightArr []int32
|
||||||
|
RuneIDArr []string
|
||||||
|
AmountArr []pgtype.Numeric
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) BatchCreateRunesBalances(ctx context.Context, arg BatchCreateRunesBalancesParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, batchCreateRunesBalances,
|
||||||
|
arg.PkscriptArr,
|
||||||
|
arg.BlockHeightArr,
|
||||||
|
arg.RuneIDArr,
|
||||||
|
arg.AmountArr,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const batchCreateRunesOutpointBalances = `-- name: BatchCreateRunesOutpointBalances :exec
|
||||||
|
INSERT INTO runes_outpoint_balances ("rune_id", "pkscript", "tx_hash", "tx_idx", "amount", "block_height", "spent_height")
|
||||||
|
VALUES(
|
||||||
|
unnest($1::TEXT[]),
|
||||||
|
unnest($2::TEXT[]),
|
||||||
|
unnest($3::TEXT[]),
|
||||||
|
unnest($4::INT[]),
|
||||||
|
unnest($5::DECIMAL[]),
|
||||||
|
unnest($6::INT[]),
|
||||||
|
unnest($7::INT[]) -- nullable (need patch)
|
||||||
|
)
|
||||||
|
`
|
||||||
|
|
||||||
|
type BatchCreateRunesOutpointBalancesParams struct {
|
||||||
|
RuneIDArr []string
|
||||||
|
PkscriptArr []string
|
||||||
|
TxHashArr []string
|
||||||
|
TxIdxArr []int32
|
||||||
|
AmountArr []pgtype.Numeric
|
||||||
|
BlockHeightArr []int32
|
||||||
|
SpentHeightArr []int32
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) BatchCreateRunesOutpointBalances(ctx context.Context, arg BatchCreateRunesOutpointBalancesParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, batchCreateRunesOutpointBalances,
|
||||||
|
arg.RuneIDArr,
|
||||||
|
arg.PkscriptArr,
|
||||||
|
arg.TxHashArr,
|
||||||
|
arg.TxIdxArr,
|
||||||
|
arg.AmountArr,
|
||||||
|
arg.BlockHeightArr,
|
||||||
|
arg.SpentHeightArr,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const batchCreateRunestones = `-- name: BatchCreateRunestones :exec
|
||||||
|
INSERT INTO runes_runestones ("tx_hash", "block_height", "etching", "etching_divisibility", "etching_premine", "etching_rune", "etching_spacers", "etching_symbol", "etching_terms", "etching_terms_amount", "etching_terms_cap", "etching_terms_height_start", "etching_terms_height_end", "etching_terms_offset_start", "etching_terms_offset_end", "etching_turbo", "edicts", "mint", "pointer", "cenotaph", "flaws")
|
||||||
|
VALUES(
|
||||||
|
unnest($1::TEXT[]),
|
||||||
|
unnest($2::INT[]),
|
||||||
|
unnest($3::BOOLEAN[]),
|
||||||
|
unnest($4::SMALLINT[]), -- nullable (need patch)
|
||||||
|
unnest($5::DECIMAL[]),
|
||||||
|
unnest($6::TEXT[]), -- nullable (need patch)
|
||||||
|
unnest($7::INT[]), -- nullable (need patch)
|
||||||
|
unnest($8::INT[]), -- nullable (need patch)
|
||||||
|
unnest($9::BOOLEAN[]), -- nullable (need patch)
|
||||||
|
unnest($10::DECIMAL[]),
|
||||||
|
unnest($11::DECIMAL[]),
|
||||||
|
unnest($12::INT[]), -- nullable (need patch)
|
||||||
|
unnest($13::INT[]), -- nullable (need patch)
|
||||||
|
unnest($14::INT[]), -- nullable (need patch)
|
||||||
|
unnest($15::INT[]), -- nullable (need patch)
|
||||||
|
unnest($16::BOOLEAN[]), -- nullable (need patch)
|
||||||
|
unnest($17::JSONB[]),
|
||||||
|
unnest($18::TEXT[]), -- nullable (need patch)
|
||||||
|
unnest($19::INT[]), -- nullable (need patch)
|
||||||
|
unnest($20::BOOLEAN[]),
|
||||||
|
unnest($21::INT[])
|
||||||
|
)
|
||||||
|
`
|
||||||
|
|
||||||
|
type BatchCreateRunestonesParams struct {
|
||||||
|
TxHashArr []string
|
||||||
|
BlockHeightArr []int32
|
||||||
|
EtchingArr []bool
|
||||||
|
EtchingDivisibilityArr []int16
|
||||||
|
EtchingPremineArr []pgtype.Numeric
|
||||||
|
EtchingRuneArr []string
|
||||||
|
EtchingSpacersArr []int32
|
||||||
|
EtchingSymbolArr []int32
|
||||||
|
EtchingTermsArr []bool
|
||||||
|
EtchingTermsAmountArr []pgtype.Numeric
|
||||||
|
EtchingTermsCapArr []pgtype.Numeric
|
||||||
|
EtchingTermsHeightStartArr []int32
|
||||||
|
EtchingTermsHeightEndArr []int32
|
||||||
|
EtchingTermsOffsetStartArr []int32
|
||||||
|
EtchingTermsOffsetEndArr []int32
|
||||||
|
EtchingTurboArr []bool
|
||||||
|
EdictsArr [][]byte
|
||||||
|
MintArr []string
|
||||||
|
PointerArr []int32
|
||||||
|
CenotaphArr []bool
|
||||||
|
FlawsArr []int32
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) BatchCreateRunestones(ctx context.Context, arg BatchCreateRunestonesParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, batchCreateRunestones,
|
||||||
|
arg.TxHashArr,
|
||||||
|
arg.BlockHeightArr,
|
||||||
|
arg.EtchingArr,
|
||||||
|
arg.EtchingDivisibilityArr,
|
||||||
|
arg.EtchingPremineArr,
|
||||||
|
arg.EtchingRuneArr,
|
||||||
|
arg.EtchingSpacersArr,
|
||||||
|
arg.EtchingSymbolArr,
|
||||||
|
arg.EtchingTermsArr,
|
||||||
|
arg.EtchingTermsAmountArr,
|
||||||
|
arg.EtchingTermsCapArr,
|
||||||
|
arg.EtchingTermsHeightStartArr,
|
||||||
|
arg.EtchingTermsHeightEndArr,
|
||||||
|
arg.EtchingTermsOffsetStartArr,
|
||||||
|
arg.EtchingTermsOffsetEndArr,
|
||||||
|
arg.EtchingTurboArr,
|
||||||
|
arg.EdictsArr,
|
||||||
|
arg.MintArr,
|
||||||
|
arg.PointerArr,
|
||||||
|
arg.CenotaphArr,
|
||||||
|
arg.FlawsArr,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const batchSpendOutpointBalances = `-- name: BatchSpendOutpointBalances :exec
|
||||||
|
UPDATE runes_outpoint_balances
|
||||||
|
SET "spent_height" = $1::INT
|
||||||
|
FROM (
|
||||||
|
SELECT
|
||||||
|
unnest($2::TEXT[]) AS tx_hash,
|
||||||
|
unnest($3::INT[]) AS tx_idx
|
||||||
|
) AS input
|
||||||
|
WHERE "runes_outpoint_balances"."tx_hash" = "input"."tx_hash" AND "runes_outpoint_balances"."tx_idx" = "input"."tx_idx"
|
||||||
|
`
|
||||||
|
|
||||||
|
type BatchSpendOutpointBalancesParams struct {
|
||||||
|
SpentHeight int32
|
||||||
|
TxHashArr []string
|
||||||
|
TxIdxArr []int32
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) BatchSpendOutpointBalances(ctx context.Context, arg BatchSpendOutpointBalancesParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, batchSpendOutpointBalances, arg.SpentHeight, arg.TxHashArr, arg.TxIdxArr)
|
||||||
|
return err
|
||||||
|
}
|
||||||
118
modules/runes/repository/postgres/gen/batch.sql.patch.go
Normal file
118
modules/runes/repository/postgres/gen/batch.sql.patch.go
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
package gen
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/cockroachdb/errors"
|
||||||
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BatchCreateRuneEntriesPatchedParams struct {
|
||||||
|
BatchCreateRuneEntriesParams
|
||||||
|
TermsHeightStartArr []pgtype.Int4
|
||||||
|
TermsHeightEndArr []pgtype.Int4
|
||||||
|
TermsOffsetStartArr []pgtype.Int4
|
||||||
|
TermsOffsetEndArr []pgtype.Int4
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) BatchCreateRuneEntriesPatched(ctx context.Context, arg BatchCreateRuneEntriesPatchedParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, batchCreateRuneEntries,
|
||||||
|
arg.RuneIDArr,
|
||||||
|
arg.RuneArr,
|
||||||
|
arg.NumberArr,
|
||||||
|
arg.SpacersArr,
|
||||||
|
arg.PremineArr,
|
||||||
|
arg.SymbolArr,
|
||||||
|
arg.DivisibilityArr,
|
||||||
|
arg.TermsArr,
|
||||||
|
arg.TermsAmountArr,
|
||||||
|
arg.TermsCapArr,
|
||||||
|
arg.TermsHeightStartArr,
|
||||||
|
arg.TermsHeightEndArr,
|
||||||
|
arg.TermsOffsetStartArr,
|
||||||
|
arg.TermsOffsetEndArr,
|
||||||
|
arg.TurboArr,
|
||||||
|
arg.EtchingBlockArr,
|
||||||
|
arg.EtchingTxHashArr,
|
||||||
|
arg.EtchedAtArr,
|
||||||
|
)
|
||||||
|
return errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
type BatchCreateRuneEntryStatesPatchedParams struct {
|
||||||
|
BatchCreateRuneEntryStatesParams
|
||||||
|
CompletedAtHeightArr []pgtype.Int4
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) BatchCreateRuneEntryStatesPatched(ctx context.Context, arg BatchCreateRuneEntryStatesPatchedParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, batchCreateRuneEntryStates,
|
||||||
|
arg.RuneIDArr,
|
||||||
|
arg.BlockHeightArr,
|
||||||
|
arg.MintsArr,
|
||||||
|
arg.BurnedAmountArr,
|
||||||
|
arg.CompletedAtArr,
|
||||||
|
arg.CompletedAtHeightArr,
|
||||||
|
)
|
||||||
|
return errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
type BatchCreateRunesOutpointBalancesPatchedParams struct {
|
||||||
|
BatchCreateRunesOutpointBalancesParams
|
||||||
|
SpentHeightArr []pgtype.Int4
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) BatchCreateRunesOutpointBalancesPatched(ctx context.Context, arg BatchCreateRunesOutpointBalancesPatchedParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, batchCreateRunesOutpointBalances,
|
||||||
|
arg.RuneIDArr,
|
||||||
|
arg.PkscriptArr,
|
||||||
|
arg.TxHashArr,
|
||||||
|
arg.TxIdxArr,
|
||||||
|
arg.AmountArr,
|
||||||
|
arg.BlockHeightArr,
|
||||||
|
arg.SpentHeightArr,
|
||||||
|
)
|
||||||
|
return errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
type BatchCreateRunestonesPatchedParams struct {
|
||||||
|
BatchCreateRunestonesParams
|
||||||
|
EtchingDivisibilityArr []pgtype.Int2
|
||||||
|
EtchingRuneArr []pgtype.Text
|
||||||
|
EtchingSpacersArr []pgtype.Int4
|
||||||
|
EtchingSymbolArr []pgtype.Int4
|
||||||
|
EtchingTermsArr []pgtype.Bool
|
||||||
|
EtchingTermsHeightStartArr []pgtype.Int4
|
||||||
|
EtchingTermsHeightEndArr []pgtype.Int4
|
||||||
|
EtchingTermsOffsetStartArr []pgtype.Int4
|
||||||
|
EtchingTermsOffsetEndArr []pgtype.Int4
|
||||||
|
EtchingTurboArr []pgtype.Bool
|
||||||
|
MintArr []pgtype.Text
|
||||||
|
PointerArr []pgtype.Int4
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) BatchCreateRunestonesPatched(ctx context.Context, arg BatchCreateRunestonesPatchedParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, batchCreateRunestones,
|
||||||
|
arg.TxHashArr,
|
||||||
|
arg.BlockHeightArr,
|
||||||
|
arg.EtchingArr,
|
||||||
|
arg.EtchingDivisibilityArr,
|
||||||
|
arg.EtchingPremineArr,
|
||||||
|
arg.EtchingRuneArr,
|
||||||
|
arg.EtchingSpacersArr,
|
||||||
|
arg.EtchingSymbolArr,
|
||||||
|
arg.EtchingTermsArr,
|
||||||
|
arg.EtchingTermsAmountArr,
|
||||||
|
arg.EtchingTermsCapArr,
|
||||||
|
arg.EtchingTermsHeightStartArr,
|
||||||
|
arg.EtchingTermsHeightEndArr,
|
||||||
|
arg.EtchingTermsOffsetStartArr,
|
||||||
|
arg.EtchingTermsOffsetEndArr,
|
||||||
|
arg.EtchingTurboArr,
|
||||||
|
arg.EdictsArr,
|
||||||
|
arg.MintArr,
|
||||||
|
arg.PointerArr,
|
||||||
|
arg.CenotaphArr,
|
||||||
|
arg.FlawsArr,
|
||||||
|
)
|
||||||
|
return errors.WithStack(err)
|
||||||
|
}
|
||||||
@@ -45,6 +45,216 @@ func (q *Queries) CreateIndexedBlock(ctx context.Context, arg CreateIndexedBlock
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const createOutPointBalance = `-- name: CreateOutPointBalance :exec
|
||||||
|
INSERT INTO runes_outpoint_balances (rune_id, pkscript, tx_hash, tx_idx, amount, block_height, spent_height) VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateOutPointBalanceParams struct {
|
||||||
|
RuneID string
|
||||||
|
Pkscript string
|
||||||
|
TxHash string
|
||||||
|
TxIdx int32
|
||||||
|
Amount pgtype.Numeric
|
||||||
|
BlockHeight int32
|
||||||
|
SpentHeight pgtype.Int4
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateOutPointBalance(ctx context.Context, arg CreateOutPointBalanceParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, createOutPointBalance,
|
||||||
|
arg.RuneID,
|
||||||
|
arg.Pkscript,
|
||||||
|
arg.TxHash,
|
||||||
|
arg.TxIdx,
|
||||||
|
arg.Amount,
|
||||||
|
arg.BlockHeight,
|
||||||
|
arg.SpentHeight,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const createRuneBalance = `-- name: CreateRuneBalance :exec
|
||||||
|
INSERT INTO runes_balances (pkscript, block_height, rune_id, amount) VALUES ($1, $2, $3, $4)
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateRuneBalanceParams struct {
|
||||||
|
Pkscript string
|
||||||
|
BlockHeight int32
|
||||||
|
RuneID string
|
||||||
|
Amount pgtype.Numeric
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateRuneBalance(ctx context.Context, arg CreateRuneBalanceParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, createRuneBalance,
|
||||||
|
arg.Pkscript,
|
||||||
|
arg.BlockHeight,
|
||||||
|
arg.RuneID,
|
||||||
|
arg.Amount,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const createRuneEntry = `-- name: CreateRuneEntry :exec
|
||||||
|
INSERT INTO runes_entries (rune_id, rune, number, spacers, premine, symbol, divisibility, terms, terms_amount, terms_cap, terms_height_start, terms_height_end, terms_offset_start, terms_offset_end, turbo, etching_block, etching_tx_hash, etched_at)
|
||||||
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateRuneEntryParams struct {
|
||||||
|
RuneID string
|
||||||
|
Rune string
|
||||||
|
Number int64
|
||||||
|
Spacers int32
|
||||||
|
Premine pgtype.Numeric
|
||||||
|
Symbol int32
|
||||||
|
Divisibility int16
|
||||||
|
Terms bool
|
||||||
|
TermsAmount pgtype.Numeric
|
||||||
|
TermsCap pgtype.Numeric
|
||||||
|
TermsHeightStart pgtype.Int4
|
||||||
|
TermsHeightEnd pgtype.Int4
|
||||||
|
TermsOffsetStart pgtype.Int4
|
||||||
|
TermsOffsetEnd pgtype.Int4
|
||||||
|
Turbo bool
|
||||||
|
EtchingBlock int32
|
||||||
|
EtchingTxHash string
|
||||||
|
EtchedAt pgtype.Timestamp
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateRuneEntry(ctx context.Context, arg CreateRuneEntryParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, createRuneEntry,
|
||||||
|
arg.RuneID,
|
||||||
|
arg.Rune,
|
||||||
|
arg.Number,
|
||||||
|
arg.Spacers,
|
||||||
|
arg.Premine,
|
||||||
|
arg.Symbol,
|
||||||
|
arg.Divisibility,
|
||||||
|
arg.Terms,
|
||||||
|
arg.TermsAmount,
|
||||||
|
arg.TermsCap,
|
||||||
|
arg.TermsHeightStart,
|
||||||
|
arg.TermsHeightEnd,
|
||||||
|
arg.TermsOffsetStart,
|
||||||
|
arg.TermsOffsetEnd,
|
||||||
|
arg.Turbo,
|
||||||
|
arg.EtchingBlock,
|
||||||
|
arg.EtchingTxHash,
|
||||||
|
arg.EtchedAt,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const createRuneEntryState = `-- name: CreateRuneEntryState :exec
|
||||||
|
INSERT INTO runes_entry_states (rune_id, block_height, mints, burned_amount, completed_at, completed_at_height) VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateRuneEntryStateParams struct {
|
||||||
|
RuneID string
|
||||||
|
BlockHeight int32
|
||||||
|
Mints pgtype.Numeric
|
||||||
|
BurnedAmount pgtype.Numeric
|
||||||
|
CompletedAt pgtype.Timestamp
|
||||||
|
CompletedAtHeight pgtype.Int4
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateRuneEntryState(ctx context.Context, arg CreateRuneEntryStateParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, createRuneEntryState,
|
||||||
|
arg.RuneID,
|
||||||
|
arg.BlockHeight,
|
||||||
|
arg.Mints,
|
||||||
|
arg.BurnedAmount,
|
||||||
|
arg.CompletedAt,
|
||||||
|
arg.CompletedAtHeight,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const createRuneTransaction = `-- name: CreateRuneTransaction :exec
|
||||||
|
INSERT INTO runes_transactions (hash, block_height, index, timestamp, inputs, outputs, mints, burns, rune_etched) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateRuneTransactionParams struct {
|
||||||
|
Hash string
|
||||||
|
BlockHeight int32
|
||||||
|
Index int32
|
||||||
|
Timestamp pgtype.Timestamp
|
||||||
|
Inputs []byte
|
||||||
|
Outputs []byte
|
||||||
|
Mints []byte
|
||||||
|
Burns []byte
|
||||||
|
RuneEtched bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateRuneTransaction(ctx context.Context, arg CreateRuneTransactionParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, createRuneTransaction,
|
||||||
|
arg.Hash,
|
||||||
|
arg.BlockHeight,
|
||||||
|
arg.Index,
|
||||||
|
arg.Timestamp,
|
||||||
|
arg.Inputs,
|
||||||
|
arg.Outputs,
|
||||||
|
arg.Mints,
|
||||||
|
arg.Burns,
|
||||||
|
arg.RuneEtched,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const createRunestone = `-- name: CreateRunestone :exec
|
||||||
|
INSERT INTO runes_runestones (tx_hash, block_height, etching, etching_divisibility, etching_premine, etching_rune, etching_spacers, etching_symbol, etching_terms, etching_terms_amount, etching_terms_cap, etching_terms_height_start, etching_terms_height_end, etching_terms_offset_start, etching_terms_offset_end, etching_turbo, edicts, mint, pointer, cenotaph, flaws)
|
||||||
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21)
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateRunestoneParams struct {
|
||||||
|
TxHash string
|
||||||
|
BlockHeight int32
|
||||||
|
Etching bool
|
||||||
|
EtchingDivisibility pgtype.Int2
|
||||||
|
EtchingPremine pgtype.Numeric
|
||||||
|
EtchingRune pgtype.Text
|
||||||
|
EtchingSpacers pgtype.Int4
|
||||||
|
EtchingSymbol pgtype.Int4
|
||||||
|
EtchingTerms pgtype.Bool
|
||||||
|
EtchingTermsAmount pgtype.Numeric
|
||||||
|
EtchingTermsCap pgtype.Numeric
|
||||||
|
EtchingTermsHeightStart pgtype.Int4
|
||||||
|
EtchingTermsHeightEnd pgtype.Int4
|
||||||
|
EtchingTermsOffsetStart pgtype.Int4
|
||||||
|
EtchingTermsOffsetEnd pgtype.Int4
|
||||||
|
EtchingTurbo pgtype.Bool
|
||||||
|
Edicts []byte
|
||||||
|
Mint pgtype.Text
|
||||||
|
Pointer pgtype.Int4
|
||||||
|
Cenotaph bool
|
||||||
|
Flaws int32
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateRunestone(ctx context.Context, arg CreateRunestoneParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, createRunestone,
|
||||||
|
arg.TxHash,
|
||||||
|
arg.BlockHeight,
|
||||||
|
arg.Etching,
|
||||||
|
arg.EtchingDivisibility,
|
||||||
|
arg.EtchingPremine,
|
||||||
|
arg.EtchingRune,
|
||||||
|
arg.EtchingSpacers,
|
||||||
|
arg.EtchingSymbol,
|
||||||
|
arg.EtchingTerms,
|
||||||
|
arg.EtchingTermsAmount,
|
||||||
|
arg.EtchingTermsCap,
|
||||||
|
arg.EtchingTermsHeightStart,
|
||||||
|
arg.EtchingTermsHeightEnd,
|
||||||
|
arg.EtchingTermsOffsetStart,
|
||||||
|
arg.EtchingTermsOffsetEnd,
|
||||||
|
arg.EtchingTurbo,
|
||||||
|
arg.Edicts,
|
||||||
|
arg.Mint,
|
||||||
|
arg.Pointer,
|
||||||
|
arg.Cenotaph,
|
||||||
|
arg.Flaws,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const deleteIndexedBlockSinceHeight = `-- name: DeleteIndexedBlockSinceHeight :exec
|
const deleteIndexedBlockSinceHeight = `-- name: DeleteIndexedBlockSinceHeight :exec
|
||||||
DELETE FROM runes_indexed_blocks WHERE height >= $1
|
DELETE FROM runes_indexed_blocks WHERE height >= $1
|
||||||
`
|
`
|
||||||
@@ -1059,6 +1269,21 @@ func (q *Queries) GetTotalHoldersByRuneIds(ctx context.Context, arg GetTotalHold
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const spendOutPointBalance = `-- name: SpendOutPointBalance :exec
|
||||||
|
UPDATE runes_outpoint_balances SET spent_height = $1 WHERE tx_hash = $2 AND tx_idx = $3
|
||||||
|
`
|
||||||
|
|
||||||
|
type SpendOutPointBalanceParams struct {
|
||||||
|
SpentHeight pgtype.Int4
|
||||||
|
TxHash string
|
||||||
|
TxIdx int32
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) SpendOutPointBalance(ctx context.Context, arg SpendOutPointBalanceParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, spendOutPointBalance, arg.SpentHeight, arg.TxHash, arg.TxIdx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const unspendOutPointBalancesSinceHeight = `-- name: UnspendOutPointBalancesSinceHeight :exec
|
const unspendOutPointBalancesSinceHeight = `-- name: UnspendOutPointBalancesSinceHeight :exec
|
||||||
UPDATE runes_outpoint_balances SET spent_height = NULL WHERE spent_height >= $1
|
UPDATE runes_outpoint_balances SET spent_height = NULL WHERE spent_height >= $1
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ type DBTX interface {
|
|||||||
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
|
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
|
||||||
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
|
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
|
||||||
QueryRow(context.Context, string, ...interface{}) pgx.Row
|
QueryRow(context.Context, string, ...interface{}) pgx.Row
|
||||||
SendBatch(context.Context, *pgx.Batch) pgx.BatchResults
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(db DBTX) *Queries {
|
func New(db DBTX) *Queries {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/gaze-network/indexer-network/modules/runes/internal/entity"
|
"github.com/gaze-network/indexer-network/modules/runes/internal/entity"
|
||||||
"github.com/gaze-network/indexer-network/modules/runes/repository/postgres/gen"
|
"github.com/gaze-network/indexer-network/modules/runes/repository/postgres/gen"
|
||||||
"github.com/gaze-network/indexer-network/modules/runes/runes"
|
"github.com/gaze-network/indexer-network/modules/runes/runes"
|
||||||
|
|
||||||
"github.com/gaze-network/uint128"
|
"github.com/gaze-network/uint128"
|
||||||
"github.com/jackc/pgx/v5/pgtype"
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
@@ -47,7 +48,7 @@ func numericFromUint128(src *uint128.Uint128) (pgtype.Numeric, error) {
|
|||||||
func mapIndexerStateModelToType(src gen.RunesIndexerState) entity.IndexerState {
|
func mapIndexerStateModelToType(src gen.RunesIndexerState) entity.IndexerState {
|
||||||
var createdAt time.Time
|
var createdAt time.Time
|
||||||
if src.CreatedAt.Valid {
|
if src.CreatedAt.Valid {
|
||||||
createdAt = src.CreatedAt.Time
|
createdAt = src.CreatedAt.Time.UTC()
|
||||||
}
|
}
|
||||||
return entity.IndexerState{
|
return entity.IndexerState{
|
||||||
DBVersion: src.DbVersion,
|
DBVersion: src.DbVersion,
|
||||||
@@ -86,7 +87,7 @@ func mapRuneEntryModelToType(src gen.GetRuneEntriesRow) (runes.RuneEntry, error)
|
|||||||
}
|
}
|
||||||
var completedAt time.Time
|
var completedAt time.Time
|
||||||
if src.CompletedAt.Valid {
|
if src.CompletedAt.Valid {
|
||||||
completedAt = src.CompletedAt.Time
|
completedAt = src.CompletedAt.Time.UTC()
|
||||||
}
|
}
|
||||||
var completedAtHeight *uint64
|
var completedAtHeight *uint64
|
||||||
if src.CompletedAtHeight.Valid {
|
if src.CompletedAtHeight.Valid {
|
||||||
@@ -132,7 +133,7 @@ func mapRuneEntryModelToType(src gen.GetRuneEntriesRow) (runes.RuneEntry, error)
|
|||||||
}
|
}
|
||||||
var etchedAt time.Time
|
var etchedAt time.Time
|
||||||
if src.EtchedAt.Valid {
|
if src.EtchedAt.Valid {
|
||||||
etchedAt = src.EtchedAt.Time
|
etchedAt = src.EtchedAt.Time.UTC()
|
||||||
}
|
}
|
||||||
return runes.RuneEntry{
|
return runes.RuneEntry{
|
||||||
RuneId: runeId,
|
RuneId: runeId,
|
||||||
@@ -153,31 +154,13 @@ func mapRuneEntryModelToType(src gen.GetRuneEntriesRow) (runes.RuneEntry, error)
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapRuneEntryTypeToParams(src runes.RuneEntry, blockHeight uint64) (gen.CreateRuneEntriesParams, gen.CreateRuneEntryStatesParams, error) {
|
func mapRuneEntryTypeToParams(src runes.RuneEntry) (gen.CreateRuneEntryParams, error) {
|
||||||
runeId := src.RuneId.String()
|
runeId := src.RuneId.String()
|
||||||
rune := src.SpacedRune.Rune.String()
|
rune := src.SpacedRune.Rune.String()
|
||||||
spacers := int32(src.SpacedRune.Spacers)
|
spacers := int32(src.SpacedRune.Spacers)
|
||||||
mints, err := numericFromUint128(&src.Mints)
|
|
||||||
if err != nil {
|
|
||||||
return gen.CreateRuneEntriesParams{}, gen.CreateRuneEntryStatesParams{}, errors.Wrap(err, "failed to parse mints")
|
|
||||||
}
|
|
||||||
burnedAmount, err := numericFromUint128(&src.BurnedAmount)
|
|
||||||
if err != nil {
|
|
||||||
return gen.CreateRuneEntriesParams{}, gen.CreateRuneEntryStatesParams{}, errors.Wrap(err, "failed to parse burned amount")
|
|
||||||
}
|
|
||||||
premine, err := numericFromUint128(&src.Premine)
|
premine, err := numericFromUint128(&src.Premine)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gen.CreateRuneEntriesParams{}, gen.CreateRuneEntryStatesParams{}, errors.Wrap(err, "failed to parse premine")
|
return gen.CreateRuneEntryParams{}, errors.Wrap(err, "failed to parse premine")
|
||||||
}
|
|
||||||
var completedAt pgtype.Timestamp
|
|
||||||
if !src.CompletedAt.IsZero() {
|
|
||||||
completedAt.Time = src.CompletedAt
|
|
||||||
completedAt.Valid = true
|
|
||||||
}
|
|
||||||
var completedAtHeight pgtype.Int4
|
|
||||||
if src.CompletedAtHeight != nil {
|
|
||||||
completedAtHeight.Int32 = int32(*src.CompletedAtHeight)
|
|
||||||
completedAtHeight.Valid = true
|
|
||||||
}
|
}
|
||||||
var terms bool
|
var terms bool
|
||||||
var termsAmount, termsCap pgtype.Numeric
|
var termsAmount, termsCap pgtype.Numeric
|
||||||
@@ -187,13 +170,13 @@ func mapRuneEntryTypeToParams(src runes.RuneEntry, blockHeight uint64) (gen.Crea
|
|||||||
if src.Terms.Amount != nil {
|
if src.Terms.Amount != nil {
|
||||||
termsAmount, err = numericFromUint128(src.Terms.Amount)
|
termsAmount, err = numericFromUint128(src.Terms.Amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gen.CreateRuneEntriesParams{}, gen.CreateRuneEntryStatesParams{}, errors.Wrap(err, "failed to parse terms amount")
|
return gen.CreateRuneEntryParams{}, errors.Wrap(err, "failed to parse terms amount")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if src.Terms.Cap != nil {
|
if src.Terms.Cap != nil {
|
||||||
termsCap, err = numericFromUint128(src.Terms.Cap)
|
termsCap, err = numericFromUint128(src.Terms.Cap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gen.CreateRuneEntriesParams{}, gen.CreateRuneEntryStatesParams{}, errors.Wrap(err, "failed to parse terms cap")
|
return gen.CreateRuneEntryParams{}, errors.Wrap(err, "failed to parse terms cap")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if src.Terms.HeightStart != nil {
|
if src.Terms.HeightStart != nil {
|
||||||
@@ -221,51 +204,150 @@ func mapRuneEntryTypeToParams(src runes.RuneEntry, blockHeight uint64) (gen.Crea
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
etchedAt := pgtype.Timestamp{Time: src.EtchedAt, Valid: true}
|
etchedAt := pgtype.Timestamp{Time: src.EtchedAt.UTC(), Valid: true}
|
||||||
|
|
||||||
return gen.CreateRuneEntriesParams{
|
return gen.CreateRuneEntryParams{
|
||||||
RuneID: runeId,
|
RuneID: runeId,
|
||||||
Rune: rune,
|
Rune: rune,
|
||||||
Number: int64(src.Number),
|
Number: int64(src.Number),
|
||||||
Spacers: spacers,
|
Spacers: spacers,
|
||||||
Premine: premine,
|
Premine: premine,
|
||||||
Symbol: src.Symbol,
|
Symbol: src.Symbol,
|
||||||
Divisibility: int16(src.Divisibility),
|
Divisibility: int16(src.Divisibility),
|
||||||
Terms: terms,
|
Terms: terms,
|
||||||
TermsAmount: termsAmount,
|
TermsAmount: termsAmount,
|
||||||
TermsCap: termsCap,
|
TermsCap: termsCap,
|
||||||
TermsHeightStart: termsHeightStart,
|
TermsHeightStart: termsHeightStart,
|
||||||
TermsHeightEnd: termsHeightEnd,
|
TermsHeightEnd: termsHeightEnd,
|
||||||
TermsOffsetStart: termsOffsetStart,
|
TermsOffsetStart: termsOffsetStart,
|
||||||
TermsOffsetEnd: termsOffsetEnd,
|
TermsOffsetEnd: termsOffsetEnd,
|
||||||
Turbo: src.Turbo,
|
Turbo: src.Turbo,
|
||||||
EtchingBlock: int32(src.EtchingBlock),
|
EtchingBlock: int32(src.EtchingBlock),
|
||||||
EtchingTxHash: src.EtchingTxHash.String(),
|
EtchingTxHash: src.EtchingTxHash.String(),
|
||||||
EtchedAt: etchedAt,
|
EtchedAt: etchedAt,
|
||||||
}, gen.CreateRuneEntryStatesParams{
|
}, nil
|
||||||
BlockHeight: int32(blockHeight),
|
|
||||||
RuneID: runeId,
|
|
||||||
Mints: mints,
|
|
||||||
BurnedAmount: burnedAmount,
|
|
||||||
CompletedAt: completedAt,
|
|
||||||
CompletedAtHeight: completedAtHeight,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// mapRuneTransactionModelToType returns params for creating a new rune transaction and (optionally) a runestone.
|
func mapRuneEntryStatesTypeToParams(src runes.RuneEntry, blockHeight uint64) (gen.CreateRuneEntryStateParams, error) {
|
||||||
func mapRuneTransactionTypeToParams(src entity.RuneTransaction) (gen.CreateRuneTransactionsParams, *gen.CreateRunestonesParams, error) {
|
runeId := src.RuneId.String()
|
||||||
|
mints, err := numericFromUint128(&src.Mints)
|
||||||
|
if err != nil {
|
||||||
|
return gen.CreateRuneEntryStateParams{}, errors.Wrap(err, "failed to parse mints")
|
||||||
|
}
|
||||||
|
burnedAmount, err := numericFromUint128(&src.BurnedAmount)
|
||||||
|
if err != nil {
|
||||||
|
return gen.CreateRuneEntryStateParams{}, errors.Wrap(err, "failed to parse burned amount")
|
||||||
|
}
|
||||||
|
var completedAt pgtype.Timestamp
|
||||||
|
if !src.CompletedAt.IsZero() {
|
||||||
|
completedAt.Time = src.CompletedAt.UTC()
|
||||||
|
completedAt.Valid = true
|
||||||
|
}
|
||||||
|
var completedAtHeight pgtype.Int4
|
||||||
|
if src.CompletedAtHeight != nil {
|
||||||
|
completedAtHeight.Int32 = int32(*src.CompletedAtHeight)
|
||||||
|
completedAtHeight.Valid = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return gen.CreateRuneEntryStateParams{
|
||||||
|
BlockHeight: int32(blockHeight),
|
||||||
|
RuneID: runeId,
|
||||||
|
Mints: mints,
|
||||||
|
BurnedAmount: burnedAmount,
|
||||||
|
CompletedAt: completedAt,
|
||||||
|
CompletedAtHeight: completedAtHeight,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func mapRuneEntryTypeToParamsBatch(srcs []*runes.RuneEntry) (gen.BatchCreateRuneEntriesPatchedParams, error) {
|
||||||
|
var batchParams gen.BatchCreateRuneEntriesPatchedParams
|
||||||
|
batchParams.RuneIDArr = make([]string, 0, len(srcs))
|
||||||
|
batchParams.RuneArr = make([]string, 0, len(srcs))
|
||||||
|
batchParams.NumberArr = make([]int64, 0, len(srcs))
|
||||||
|
batchParams.SpacersArr = make([]int32, 0, len(srcs))
|
||||||
|
batchParams.PremineArr = make([]pgtype.Numeric, 0, len(srcs))
|
||||||
|
batchParams.SymbolArr = make([]int32, 0, len(srcs))
|
||||||
|
batchParams.DivisibilityArr = make([]int16, 0, len(srcs))
|
||||||
|
batchParams.TermsArr = make([]bool, 0, len(srcs))
|
||||||
|
batchParams.TermsAmountArr = make([]pgtype.Numeric, 0, len(srcs))
|
||||||
|
batchParams.TermsCapArr = make([]pgtype.Numeric, 0, len(srcs))
|
||||||
|
batchParams.TermsHeightStartArr = make([]pgtype.Int4, 0, len(srcs))
|
||||||
|
batchParams.TermsHeightEndArr = make([]pgtype.Int4, 0, len(srcs))
|
||||||
|
batchParams.TermsOffsetStartArr = make([]pgtype.Int4, 0, len(srcs))
|
||||||
|
batchParams.TermsOffsetEndArr = make([]pgtype.Int4, 0, len(srcs))
|
||||||
|
batchParams.TurboArr = make([]bool, 0, len(srcs))
|
||||||
|
batchParams.EtchingBlockArr = make([]int32, 0, len(srcs))
|
||||||
|
batchParams.EtchingTxHashArr = make([]string, 0, len(srcs))
|
||||||
|
batchParams.EtchedAtArr = make([]pgtype.Timestamp, 0, len(srcs))
|
||||||
|
|
||||||
|
for i, src := range srcs {
|
||||||
|
param, err := mapRuneEntryTypeToParams(*src)
|
||||||
|
if err != nil {
|
||||||
|
return gen.BatchCreateRuneEntriesPatchedParams{}, errors.Wrapf(err, "failed to map rune entry to params batch at index %d", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
batchParams.RuneIDArr = append(batchParams.RuneIDArr, param.RuneID)
|
||||||
|
batchParams.RuneArr = append(batchParams.RuneArr, param.Rune)
|
||||||
|
batchParams.NumberArr = append(batchParams.NumberArr, param.Number)
|
||||||
|
batchParams.SpacersArr = append(batchParams.SpacersArr, param.Spacers)
|
||||||
|
batchParams.PremineArr = append(batchParams.PremineArr, param.Premine)
|
||||||
|
batchParams.SymbolArr = append(batchParams.SymbolArr, param.Symbol)
|
||||||
|
batchParams.DivisibilityArr = append(batchParams.DivisibilityArr, param.Divisibility)
|
||||||
|
batchParams.TermsArr = append(batchParams.TermsArr, param.Terms)
|
||||||
|
batchParams.TermsAmountArr = append(batchParams.TermsAmountArr, param.TermsAmount)
|
||||||
|
batchParams.TermsCapArr = append(batchParams.TermsCapArr, param.TermsCap)
|
||||||
|
batchParams.TermsHeightStartArr = append(batchParams.TermsHeightStartArr, param.TermsHeightStart)
|
||||||
|
batchParams.TermsHeightEndArr = append(batchParams.TermsHeightEndArr, param.TermsHeightEnd)
|
||||||
|
batchParams.TermsOffsetStartArr = append(batchParams.TermsOffsetStartArr, param.TermsOffsetStart)
|
||||||
|
batchParams.TermsOffsetEndArr = append(batchParams.TermsOffsetEndArr, param.TermsOffsetEnd)
|
||||||
|
batchParams.TurboArr = append(batchParams.TurboArr, param.Turbo)
|
||||||
|
batchParams.EtchingBlockArr = append(batchParams.EtchingBlockArr, param.EtchingBlock)
|
||||||
|
batchParams.EtchingTxHashArr = append(batchParams.EtchingTxHashArr, param.EtchingTxHash)
|
||||||
|
batchParams.EtchedAtArr = append(batchParams.EtchedAtArr, param.EtchedAt)
|
||||||
|
}
|
||||||
|
|
||||||
|
return batchParams, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func mapRuneEntryStatesTypeToParamsBatch(srcs []*runes.RuneEntry, blockHeight uint64) (gen.BatchCreateRuneEntryStatesPatchedParams, error) {
|
||||||
|
var batchParams gen.BatchCreateRuneEntryStatesPatchedParams
|
||||||
|
batchParams.RuneIDArr = make([]string, 0, len(srcs))
|
||||||
|
batchParams.BlockHeightArr = make([]int32, 0, len(srcs))
|
||||||
|
batchParams.MintsArr = make([]pgtype.Numeric, 0, len(srcs))
|
||||||
|
batchParams.BurnedAmountArr = make([]pgtype.Numeric, 0, len(srcs))
|
||||||
|
batchParams.CompletedAtArr = make([]pgtype.Timestamp, 0, len(srcs))
|
||||||
|
batchParams.CompletedAtHeightArr = make([]pgtype.Int4, 0, len(srcs))
|
||||||
|
|
||||||
|
for i, src := range srcs {
|
||||||
|
param, err := mapRuneEntryStatesTypeToParams(*src, blockHeight)
|
||||||
|
if err != nil {
|
||||||
|
return gen.BatchCreateRuneEntryStatesPatchedParams{}, errors.Wrapf(err, "failed to map rune entry states to params batch at index %d", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
batchParams.RuneIDArr = append(batchParams.RuneIDArr, param.RuneID)
|
||||||
|
batchParams.BlockHeightArr = append(batchParams.BlockHeightArr, param.BlockHeight)
|
||||||
|
batchParams.MintsArr = append(batchParams.MintsArr, param.Mints)
|
||||||
|
batchParams.BurnedAmountArr = append(batchParams.BurnedAmountArr, param.BurnedAmount)
|
||||||
|
batchParams.CompletedAtArr = append(batchParams.CompletedAtArr, param.CompletedAt)
|
||||||
|
batchParams.CompletedAtHeightArr = append(batchParams.CompletedAtHeightArr, param.CompletedAtHeight)
|
||||||
|
}
|
||||||
|
|
||||||
|
return batchParams, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func mapRuneTransactionTypeToParams(src entity.RuneTransaction) (gen.CreateRuneTransactionParams, error) {
|
||||||
var timestamp pgtype.Timestamp
|
var timestamp pgtype.Timestamp
|
||||||
if !src.Timestamp.IsZero() {
|
if !src.Timestamp.IsZero() {
|
||||||
timestamp.Time = src.Timestamp
|
timestamp.Time = src.Timestamp.UTC()
|
||||||
timestamp.Valid = true
|
timestamp.Valid = true
|
||||||
}
|
}
|
||||||
inputsBytes, err := json.Marshal(src.Inputs)
|
inputsBytes, err := json.Marshal(src.Inputs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gen.CreateRuneTransactionsParams{}, nil, errors.Wrap(err, "failed to marshal inputs")
|
return gen.CreateRuneTransactionParams{}, errors.Wrap(err, "failed to marshal inputs")
|
||||||
}
|
}
|
||||||
outputsBytes, err := json.Marshal(src.Outputs)
|
outputsBytes, err := json.Marshal(src.Outputs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gen.CreateRuneTransactionsParams{}, nil, errors.Wrap(err, "failed to marshal outputs")
|
return gen.CreateRuneTransactionParams{}, errors.Wrap(err, "failed to marshal outputs")
|
||||||
}
|
}
|
||||||
mints := make(map[string]uint128.Uint128)
|
mints := make(map[string]uint128.Uint128)
|
||||||
for key, value := range src.Mints {
|
for key, value := range src.Mints {
|
||||||
@@ -273,7 +355,7 @@ func mapRuneTransactionTypeToParams(src entity.RuneTransaction) (gen.CreateRuneT
|
|||||||
}
|
}
|
||||||
mintsBytes, err := json.Marshal(mints)
|
mintsBytes, err := json.Marshal(mints)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gen.CreateRuneTransactionsParams{}, nil, errors.Wrap(err, "failed to marshal mints")
|
return gen.CreateRuneTransactionParams{}, errors.Wrap(err, "failed to marshal mints")
|
||||||
}
|
}
|
||||||
burns := make(map[string]uint128.Uint128)
|
burns := make(map[string]uint128.Uint128)
|
||||||
for key, value := range src.Burns {
|
for key, value := range src.Burns {
|
||||||
@@ -281,19 +363,10 @@ func mapRuneTransactionTypeToParams(src entity.RuneTransaction) (gen.CreateRuneT
|
|||||||
}
|
}
|
||||||
burnsBytes, err := json.Marshal(burns)
|
burnsBytes, err := json.Marshal(burns)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gen.CreateRuneTransactionsParams{}, nil, errors.Wrap(err, "failed to marshal burns")
|
return gen.CreateRuneTransactionParams{}, errors.Wrap(err, "failed to marshal burns")
|
||||||
}
|
}
|
||||||
|
|
||||||
var runestoneParams *gen.CreateRunestonesParams
|
return gen.CreateRuneTransactionParams{
|
||||||
if src.Runestone != nil {
|
|
||||||
params, err := mapRunestoneTypeToParams(*src.Runestone, src.Hash, src.BlockHeight)
|
|
||||||
if err != nil {
|
|
||||||
return gen.CreateRuneTransactionsParams{}, nil, errors.Wrap(err, "failed to map runestone to params")
|
|
||||||
}
|
|
||||||
runestoneParams = ¶ms
|
|
||||||
}
|
|
||||||
|
|
||||||
return gen.CreateRuneTransactionsParams{
|
|
||||||
Hash: src.Hash.String(),
|
Hash: src.Hash.String(),
|
||||||
BlockHeight: int32(src.BlockHeight),
|
BlockHeight: int32(src.BlockHeight),
|
||||||
Index: int32(src.Index),
|
Index: int32(src.Index),
|
||||||
@@ -303,7 +376,46 @@ func mapRuneTransactionTypeToParams(src entity.RuneTransaction) (gen.CreateRuneT
|
|||||||
Mints: mintsBytes,
|
Mints: mintsBytes,
|
||||||
Burns: burnsBytes,
|
Burns: burnsBytes,
|
||||||
RuneEtched: src.RuneEtched,
|
RuneEtched: src.RuneEtched,
|
||||||
}, runestoneParams, nil
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func mapRuneTransactionTypeToParamsBatch(srcs []*entity.RuneTransaction) (gen.BatchCreateRuneTransactionsParams, error) {
|
||||||
|
batchParams := gen.BatchCreateRuneTransactionsParams{
|
||||||
|
HashArr: make([]string, 0, len(srcs)),
|
||||||
|
BlockHeightArr: make([]int32, 0, len(srcs)),
|
||||||
|
IndexArr: make([]int32, 0, len(srcs)),
|
||||||
|
TimestampArr: make([]pgtype.Timestamp, 0, len(srcs)),
|
||||||
|
RuneEtchedArr: make([]bool, 0, len(srcs)),
|
||||||
|
}
|
||||||
|
inputsArr := make([][]byte, 0, len(srcs))
|
||||||
|
outputsArr := make([][]byte, 0, len(srcs))
|
||||||
|
mintsArr := make([][]byte, 0, len(srcs))
|
||||||
|
burnsArr := make([][]byte, 0, len(srcs))
|
||||||
|
|
||||||
|
for i, src := range srcs {
|
||||||
|
param, err := mapRuneTransactionTypeToParams(*src)
|
||||||
|
if err != nil {
|
||||||
|
return gen.BatchCreateRuneTransactionsParams{}, errors.Wrapf(err, "failed to map rune transaction to params batch at index %d", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
batchParams.HashArr = append(batchParams.HashArr, param.Hash)
|
||||||
|
batchParams.BlockHeightArr = append(batchParams.BlockHeightArr, param.BlockHeight)
|
||||||
|
batchParams.IndexArr = append(batchParams.IndexArr, param.Index)
|
||||||
|
batchParams.TimestampArr = append(batchParams.TimestampArr, param.Timestamp)
|
||||||
|
batchParams.RuneEtchedArr = append(batchParams.RuneEtchedArr, param.RuneEtched)
|
||||||
|
|
||||||
|
inputsArr = append(inputsArr, param.Inputs)
|
||||||
|
outputsArr = append(outputsArr, param.Outputs)
|
||||||
|
mintsArr = append(mintsArr, param.Mints)
|
||||||
|
burnsArr = append(burnsArr, param.Burns)
|
||||||
|
}
|
||||||
|
|
||||||
|
batchParams.InputsArr = inputsArr
|
||||||
|
batchParams.OutputsArr = outputsArr
|
||||||
|
batchParams.MintsArr = mintsArr
|
||||||
|
batchParams.BurnsArr = burnsArr
|
||||||
|
|
||||||
|
return batchParams, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractModelRuneTxAndRunestone(src gen.GetRuneTransactionsRow) (gen.RunesTransaction, *gen.RunesRunestone, error) {
|
func extractModelRuneTxAndRunestone(src gen.GetRuneTransactionsRow) (gen.RunesTransaction, *gen.RunesRunestone, error) {
|
||||||
@@ -409,15 +521,15 @@ func mapRuneTransactionModelToType(src gen.RunesTransaction) (entity.RuneTransac
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapRunestoneTypeToParams(src runes.Runestone, txHash chainhash.Hash, blockHeight uint64) (gen.CreateRunestonesParams, error) {
|
func mapRunestoneTypeToParams(src runes.Runestone, txHash chainhash.Hash, blockHeight uint64) (gen.CreateRunestoneParams, error) {
|
||||||
var runestoneParams gen.CreateRunestonesParams
|
var runestoneParams gen.CreateRunestoneParams
|
||||||
|
|
||||||
// TODO: optimize serialized edicts
|
// TODO: optimize serialized edicts
|
||||||
edictsBytes, err := json.Marshal(src.Edicts)
|
edictsBytes, err := json.Marshal(src.Edicts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gen.CreateRunestonesParams{}, errors.Wrap(err, "failed to marshal runestone edicts")
|
return gen.CreateRunestoneParams{}, errors.Wrap(err, "failed to marshal runestone edicts")
|
||||||
}
|
}
|
||||||
runestoneParams = gen.CreateRunestonesParams{
|
runestoneParams = gen.CreateRunestoneParams{
|
||||||
TxHash: txHash.String(),
|
TxHash: txHash.String(),
|
||||||
BlockHeight: int32(blockHeight),
|
BlockHeight: int32(blockHeight),
|
||||||
Edicts: edictsBytes,
|
Edicts: edictsBytes,
|
||||||
@@ -433,7 +545,7 @@ func mapRunestoneTypeToParams(src runes.Runestone, txHash chainhash.Hash, blockH
|
|||||||
if etching.Premine != nil {
|
if etching.Premine != nil {
|
||||||
premine, err := numericFromUint128(etching.Premine)
|
premine, err := numericFromUint128(etching.Premine)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gen.CreateRunestonesParams{}, errors.Wrap(err, "failed to parse etching premine")
|
return gen.CreateRunestoneParams{}, errors.Wrap(err, "failed to parse etching premine")
|
||||||
}
|
}
|
||||||
runestoneParams.EtchingPremine = premine
|
runestoneParams.EtchingPremine = premine
|
||||||
}
|
}
|
||||||
@@ -452,14 +564,14 @@ func mapRunestoneTypeToParams(src runes.Runestone, txHash chainhash.Hash, blockH
|
|||||||
if terms.Amount != nil {
|
if terms.Amount != nil {
|
||||||
amount, err := numericFromUint128(terms.Amount)
|
amount, err := numericFromUint128(terms.Amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gen.CreateRunestonesParams{}, errors.Wrap(err, "failed to parse etching terms amount")
|
return gen.CreateRunestoneParams{}, errors.Wrap(err, "failed to parse etching terms amount")
|
||||||
}
|
}
|
||||||
runestoneParams.EtchingTermsAmount = amount
|
runestoneParams.EtchingTermsAmount = amount
|
||||||
}
|
}
|
||||||
if terms.Cap != nil {
|
if terms.Cap != nil {
|
||||||
cap, err := numericFromUint128(terms.Cap)
|
cap, err := numericFromUint128(terms.Cap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gen.CreateRunestonesParams{}, errors.Wrap(err, "failed to parse etching terms cap")
|
return gen.CreateRunestoneParams{}, errors.Wrap(err, "failed to parse etching terms cap")
|
||||||
}
|
}
|
||||||
runestoneParams.EtchingTermsCap = cap
|
runestoneParams.EtchingTermsCap = cap
|
||||||
}
|
}
|
||||||
@@ -488,6 +600,65 @@ func mapRunestoneTypeToParams(src runes.Runestone, txHash chainhash.Hash, blockH
|
|||||||
return runestoneParams, nil
|
return runestoneParams, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mapRunestoneTypeToParamsBatch(srcs []*entity.RuneTransaction) (gen.BatchCreateRunestonesPatchedParams, error) {
|
||||||
|
var batchParams gen.BatchCreateRunestonesPatchedParams
|
||||||
|
batchParams.TxHashArr = make([]string, 0, len(srcs))
|
||||||
|
batchParams.BlockHeightArr = make([]int32, 0, len(srcs))
|
||||||
|
batchParams.EtchingArr = make([]bool, 0, len(srcs))
|
||||||
|
batchParams.EtchingDivisibilityArr = make([]pgtype.Int2, 0, len(srcs))
|
||||||
|
batchParams.EtchingPremineArr = make([]pgtype.Numeric, 0, len(srcs))
|
||||||
|
batchParams.EtchingRuneArr = make([]pgtype.Text, 0, len(srcs))
|
||||||
|
batchParams.EtchingSpacersArr = make([]pgtype.Int4, 0, len(srcs))
|
||||||
|
batchParams.EtchingSymbolArr = make([]pgtype.Int4, 0, len(srcs))
|
||||||
|
batchParams.EtchingTermsArr = make([]pgtype.Bool, 0, len(srcs))
|
||||||
|
batchParams.EtchingTermsAmountArr = make([]pgtype.Numeric, 0, len(srcs))
|
||||||
|
batchParams.EtchingTermsCapArr = make([]pgtype.Numeric, 0, len(srcs))
|
||||||
|
batchParams.EtchingTermsHeightStartArr = make([]pgtype.Int4, 0, len(srcs))
|
||||||
|
batchParams.EtchingTermsHeightEndArr = make([]pgtype.Int4, 0, len(srcs))
|
||||||
|
batchParams.EtchingTermsOffsetStartArr = make([]pgtype.Int4, 0, len(srcs))
|
||||||
|
batchParams.EtchingTermsOffsetEndArr = make([]pgtype.Int4, 0, len(srcs))
|
||||||
|
batchParams.EtchingTurboArr = make([]pgtype.Bool, 0, len(srcs))
|
||||||
|
batchParams.EdictsArr = make([][]byte, 0, len(srcs))
|
||||||
|
batchParams.MintArr = make([]pgtype.Text, 0, len(srcs))
|
||||||
|
batchParams.PointerArr = make([]pgtype.Int4, 0, len(srcs))
|
||||||
|
batchParams.CenotaphArr = make([]bool, 0, len(srcs))
|
||||||
|
batchParams.FlawsArr = make([]int32, 0, len(srcs))
|
||||||
|
|
||||||
|
for i, src := range srcs {
|
||||||
|
if src.Runestone == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
param, err := mapRunestoneTypeToParams(*src.Runestone, src.Hash, src.BlockHeight)
|
||||||
|
if err != nil {
|
||||||
|
return gen.BatchCreateRunestonesPatchedParams{}, errors.Wrapf(err, "failed to map runestone to params batch at index %d", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
batchParams.TxHashArr = append(batchParams.TxHashArr, param.TxHash)
|
||||||
|
batchParams.BlockHeightArr = append(batchParams.BlockHeightArr, param.BlockHeight)
|
||||||
|
batchParams.EtchingArr = append(batchParams.EtchingArr, param.Etching)
|
||||||
|
batchParams.EtchingDivisibilityArr = append(batchParams.EtchingDivisibilityArr, param.EtchingDivisibility)
|
||||||
|
batchParams.EtchingPremineArr = append(batchParams.EtchingPremineArr, param.EtchingPremine)
|
||||||
|
batchParams.EtchingRuneArr = append(batchParams.EtchingRuneArr, param.EtchingRune)
|
||||||
|
batchParams.EtchingSpacersArr = append(batchParams.EtchingSpacersArr, param.EtchingSpacers)
|
||||||
|
batchParams.EtchingSymbolArr = append(batchParams.EtchingSymbolArr, param.EtchingSymbol)
|
||||||
|
batchParams.EtchingTermsArr = append(batchParams.EtchingTermsArr, param.EtchingTerms)
|
||||||
|
batchParams.EtchingTermsAmountArr = append(batchParams.EtchingTermsAmountArr, param.EtchingTermsAmount)
|
||||||
|
batchParams.EtchingTermsCapArr = append(batchParams.EtchingTermsCapArr, param.EtchingTermsCap)
|
||||||
|
batchParams.EtchingTermsHeightStartArr = append(batchParams.EtchingTermsHeightStartArr, param.EtchingTermsHeightStart)
|
||||||
|
batchParams.EtchingTermsHeightEndArr = append(batchParams.EtchingTermsHeightEndArr, param.EtchingTermsHeightEnd)
|
||||||
|
batchParams.EtchingTermsOffsetStartArr = append(batchParams.EtchingTermsOffsetStartArr, param.EtchingTermsOffsetStart)
|
||||||
|
batchParams.EtchingTermsOffsetEndArr = append(batchParams.EtchingTermsOffsetEndArr, param.EtchingTermsOffsetEnd)
|
||||||
|
batchParams.EtchingTurboArr = append(batchParams.EtchingTurboArr, param.EtchingTurbo)
|
||||||
|
batchParams.EdictsArr = append(batchParams.EdictsArr, param.Edicts)
|
||||||
|
batchParams.MintArr = append(batchParams.MintArr, param.Mint)
|
||||||
|
batchParams.PointerArr = append(batchParams.PointerArr, param.Pointer)
|
||||||
|
batchParams.CenotaphArr = append(batchParams.CenotaphArr, param.Cenotaph)
|
||||||
|
batchParams.FlawsArr = append(batchParams.FlawsArr, param.Flaws)
|
||||||
|
}
|
||||||
|
|
||||||
|
return batchParams, nil
|
||||||
|
}
|
||||||
|
|
||||||
func mapRunestoneModelToType(src gen.RunesRunestone) (runes.Runestone, error) {
|
func mapRunestoneModelToType(src gen.RunesRunestone) (runes.Runestone, error) {
|
||||||
runestone := runes.Runestone{
|
runestone := runes.Runestone{
|
||||||
Cenotaph: src.Cenotaph,
|
Cenotaph: src.Cenotaph,
|
||||||
@@ -602,6 +773,42 @@ func mapBalanceModelToType(src gen.RunesBalance) (*entity.Balance, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mapBalanceTypeToParams(src entity.Balance) (gen.CreateRuneBalanceParams, error) {
|
||||||
|
amount, err := numericFromUint128(&src.Amount)
|
||||||
|
if err != nil {
|
||||||
|
return gen.CreateRuneBalanceParams{}, errors.Wrap(err, "failed to parse amount")
|
||||||
|
}
|
||||||
|
return gen.CreateRuneBalanceParams{
|
||||||
|
RuneID: src.RuneId.String(),
|
||||||
|
Amount: amount,
|
||||||
|
Pkscript: hex.EncodeToString(src.PkScript),
|
||||||
|
BlockHeight: int32(src.BlockHeight),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func mapBalanceTypeToParamsBatch(srcs []*entity.Balance) (gen.BatchCreateRunesBalancesParams, error) {
|
||||||
|
batchParams := gen.BatchCreateRunesBalancesParams{
|
||||||
|
RuneIDArr: make([]string, 0, len(srcs)),
|
||||||
|
AmountArr: make([]pgtype.Numeric, 0, len(srcs)),
|
||||||
|
PkscriptArr: make([]string, 0, len(srcs)),
|
||||||
|
BlockHeightArr: make([]int32, 0, len(srcs)),
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, src := range srcs {
|
||||||
|
param, err := mapBalanceTypeToParams(*src)
|
||||||
|
if err != nil {
|
||||||
|
return gen.BatchCreateRunesBalancesParams{}, errors.Wrapf(err, "failed to map balance to params batch at index %d", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
batchParams.RuneIDArr = append(batchParams.RuneIDArr, param.RuneID)
|
||||||
|
batchParams.AmountArr = append(batchParams.AmountArr, param.Amount)
|
||||||
|
batchParams.PkscriptArr = append(batchParams.PkscriptArr, param.Pkscript)
|
||||||
|
batchParams.BlockHeightArr = append(batchParams.BlockHeightArr, param.BlockHeight)
|
||||||
|
}
|
||||||
|
|
||||||
|
return batchParams, nil
|
||||||
|
}
|
||||||
|
|
||||||
func mapIndexedBlockModelToType(src gen.RunesIndexedBlock) (*entity.IndexedBlock, error) {
|
func mapIndexedBlockModelToType(src gen.RunesIndexedBlock) (*entity.IndexedBlock, error) {
|
||||||
hash, err := chainhash.NewHashFromStr(src.Hash)
|
hash, err := chainhash.NewHashFromStr(src.Hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -738,16 +945,16 @@ func mapOutPointBalanceModelToType(src gen.RunesOutpointBalance) (entity.OutPoin
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapOutPointBalanceTypeToParams(src entity.OutPointBalance) (gen.CreateOutPointBalancesParams, error) {
|
func mapOutPointBalanceTypeToParams(src entity.OutPointBalance) (gen.CreateOutPointBalanceParams, error) {
|
||||||
amount, err := numericFromUint128(&src.Amount)
|
amount, err := numericFromUint128(&src.Amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gen.CreateOutPointBalancesParams{}, errors.Wrap(err, "failed to parse amount")
|
return gen.CreateOutPointBalanceParams{}, errors.Wrap(err, "failed to parse amount")
|
||||||
}
|
}
|
||||||
var spentHeight pgtype.Int4
|
var spentHeight pgtype.Int4
|
||||||
if src.SpentHeight != nil {
|
if src.SpentHeight != nil {
|
||||||
spentHeight = pgtype.Int4{Int32: int32(*src.SpentHeight), Valid: true}
|
spentHeight = pgtype.Int4{Int32: int32(*src.SpentHeight), Valid: true}
|
||||||
}
|
}
|
||||||
return gen.CreateOutPointBalancesParams{
|
return gen.CreateOutPointBalanceParams{
|
||||||
TxHash: src.OutPoint.Hash.String(),
|
TxHash: src.OutPoint.Hash.String(),
|
||||||
TxIdx: int32(src.OutPoint.Index),
|
TxIdx: int32(src.OutPoint.Index),
|
||||||
Pkscript: hex.EncodeToString(src.PkScript),
|
Pkscript: hex.EncodeToString(src.PkScript),
|
||||||
@@ -757,3 +964,31 @@ func mapOutPointBalanceTypeToParams(src entity.OutPointBalance) (gen.CreateOutPo
|
|||||||
SpentHeight: spentHeight,
|
SpentHeight: spentHeight,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mapOutPointBalanceTypeToParamsBatch(srcs []*entity.OutPointBalance) (gen.BatchCreateRunesOutpointBalancesPatchedParams, error) {
|
||||||
|
var batchParams gen.BatchCreateRunesOutpointBalancesPatchedParams
|
||||||
|
batchParams.TxHashArr = make([]string, 0, len(srcs))
|
||||||
|
batchParams.TxIdxArr = make([]int32, 0, len(srcs))
|
||||||
|
batchParams.PkscriptArr = make([]string, 0, len(srcs))
|
||||||
|
batchParams.RuneIDArr = make([]string, 0, len(srcs))
|
||||||
|
batchParams.AmountArr = make([]pgtype.Numeric, 0, len(srcs))
|
||||||
|
batchParams.BlockHeightArr = make([]int32, 0, len(srcs))
|
||||||
|
batchParams.SpentHeightArr = make([]pgtype.Int4, 0, len(srcs))
|
||||||
|
|
||||||
|
for i, src := range srcs {
|
||||||
|
param, err := mapOutPointBalanceTypeToParams(*src)
|
||||||
|
if err != nil {
|
||||||
|
return gen.BatchCreateRunesOutpointBalancesPatchedParams{}, errors.Wrapf(err, "failed to map outpoint balance to params batch at index %d", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
batchParams.TxHashArr = append(batchParams.TxHashArr, param.TxHash)
|
||||||
|
batchParams.TxIdxArr = append(batchParams.TxIdxArr, param.TxIdx)
|
||||||
|
batchParams.PkscriptArr = append(batchParams.PkscriptArr, param.Pkscript)
|
||||||
|
batchParams.RuneIDArr = append(batchParams.RuneIDArr, param.RuneID)
|
||||||
|
batchParams.AmountArr = append(batchParams.AmountArr, param.Amount)
|
||||||
|
batchParams.BlockHeightArr = append(batchParams.BlockHeightArr, param.BlockHeight)
|
||||||
|
batchParams.SpentHeightArr = append(batchParams.SpentHeightArr, param.SpentHeight)
|
||||||
|
}
|
||||||
|
|
||||||
|
return batchParams, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -482,65 +482,40 @@ func (r *Repository) CreateRuneTransactions(ctx context.Context, txs []*entity.R
|
|||||||
if len(txs) == 0 {
|
if len(txs) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
txParams := make([]gen.CreateRuneTransactionsParams, 0, len(txs))
|
|
||||||
runestoneParams := make([]gen.CreateRunestonesParams, 0, len(txs))
|
txParams, err := mapRuneTransactionTypeToParamsBatch(txs)
|
||||||
for _, tx := range txs {
|
if err != nil {
|
||||||
txParam, runestoneParam, err := mapRuneTransactionTypeToParams(*tx)
|
return errors.Wrap(err, "failed to map rune transactions to params")
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "failed to map rune transaction to params")
|
|
||||||
}
|
|
||||||
txParams = append(txParams, txParam)
|
|
||||||
if runestoneParam != nil {
|
|
||||||
runestoneParams = append(runestoneParams, *runestoneParam)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
createTxResults := r.queries.CreateRuneTransactions(ctx, txParams)
|
if err := r.queries.BatchCreateRuneTransactions(ctx, txParams); err != nil {
|
||||||
var execErrors []error
|
return errors.Wrap(err, "error during exec BatchCreateRuneTransactions")
|
||||||
createTxResults.Exec(func(i int, err error) {
|
|
||||||
if err != nil {
|
|
||||||
execErrors = append(execErrors, err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if len(execErrors) > 0 {
|
|
||||||
return errors.Wrap(errors.Join(execErrors...), "error during exec CreateRuneTransactions")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createRunestoneResults := r.queries.CreateRunestones(ctx, runestoneParams)
|
runestoneParams, err := mapRunestoneTypeToParamsBatch(txs)
|
||||||
execErrors = make([]error, 0)
|
if err != nil {
|
||||||
createRunestoneResults.Exec(func(i int, err error) {
|
return errors.Wrap(err, "failed to map runestones to params")
|
||||||
if err != nil {
|
|
||||||
execErrors = append(execErrors, err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if len(execErrors) > 0 {
|
|
||||||
return errors.Wrap(errors.Join(execErrors...), "error during exec CreateRunestones")
|
|
||||||
}
|
}
|
||||||
|
if err := r.queries.BatchCreateRunestonesPatched(ctx, runestoneParams); err != nil {
|
||||||
|
return errors.Wrap(err, "error during exec BatchCreateRunestones")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) CreateRuneEntries(ctx context.Context, entries []*runes.RuneEntry, blockHeight uint64) error {
|
func (r *Repository) CreateRuneEntries(ctx context.Context, entries []*runes.RuneEntry) error {
|
||||||
if len(entries) == 0 {
|
if len(entries) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
createParams := make([]gen.CreateRuneEntriesParams, 0, len(entries))
|
|
||||||
for _, entry := range entries {
|
params, err := mapRuneEntryTypeToParamsBatch(entries)
|
||||||
param, _, err := mapRuneEntryTypeToParams(*entry, blockHeight)
|
if err != nil {
|
||||||
if err != nil {
|
return errors.Wrap(err, "failed to map rune entries to params")
|
||||||
return errors.Wrap(err, "failed to map rune entry to params")
|
|
||||||
}
|
|
||||||
createParams = append(createParams, param)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
results := r.queries.CreateRuneEntries(ctx, createParams)
|
if err := r.queries.BatchCreateRuneEntriesPatched(ctx, params); err != nil {
|
||||||
var execErrors []error
|
return errors.Wrap(err, "error during exec")
|
||||||
results.Exec(func(i int, err error) {
|
|
||||||
if err != nil {
|
|
||||||
execErrors = append(execErrors, err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if len(execErrors) > 0 {
|
|
||||||
return errors.Wrap(errors.Join(execErrors...), "error during exec CreateRuneEntries")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -548,98 +523,71 @@ func (r *Repository) CreateRuneEntryStates(ctx context.Context, entries []*runes
|
|||||||
if len(entries) == 0 {
|
if len(entries) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
createParams := make([]gen.CreateRuneEntryStatesParams, 0, len(entries))
|
|
||||||
for _, entry := range entries {
|
params, err := mapRuneEntryStatesTypeToParamsBatch(entries, blockHeight)
|
||||||
_, param, err := mapRuneEntryTypeToParams(*entry, blockHeight)
|
if err != nil {
|
||||||
if err != nil {
|
return errors.Wrap(err, "failed to map rune entry states to params")
|
||||||
return errors.Wrap(err, "failed to map rune entry to params")
|
|
||||||
}
|
|
||||||
createParams = append(createParams, param)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
results := r.queries.CreateRuneEntryStates(ctx, createParams)
|
if err := r.queries.BatchCreateRuneEntryStatesPatched(ctx, params); err != nil {
|
||||||
var execErrors []error
|
return errors.Wrap(err, "error during exec")
|
||||||
results.Exec(func(i int, err error) {
|
|
||||||
if err != nil {
|
|
||||||
execErrors = append(execErrors, err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if len(execErrors) > 0 {
|
|
||||||
return errors.Wrap(errors.Join(execErrors...), "error during exec CreateRuneEntryStates")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) CreateOutPointBalances(ctx context.Context, outPointBalances []*entity.OutPointBalance) error {
|
func (r *Repository) CreateOutPointBalances(ctx context.Context, outPointBalances []*entity.OutPointBalance) error {
|
||||||
params := make([]gen.CreateOutPointBalancesParams, 0, len(outPointBalances))
|
if len(outPointBalances) == 0 {
|
||||||
for _, balance := range outPointBalances {
|
return nil
|
||||||
param, err := mapOutPointBalanceTypeToParams(*balance)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "failed to map outpoint balance to params")
|
|
||||||
}
|
|
||||||
params = append(params, param)
|
|
||||||
}
|
}
|
||||||
result := r.queries.CreateOutPointBalances(ctx, params)
|
|
||||||
var execErrors []error
|
params, err := mapOutPointBalanceTypeToParamsBatch(outPointBalances)
|
||||||
result.Exec(func(i int, err error) {
|
if err != nil {
|
||||||
if err != nil {
|
return errors.Wrap(err, "failed to map outpoint balances to params")
|
||||||
execErrors = append(execErrors, err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if len(execErrors) > 0 {
|
|
||||||
return errors.Wrap(errors.Join(execErrors...), "error during exec")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := r.queries.BatchCreateRunesOutpointBalancesPatched(ctx, params); err != nil {
|
||||||
|
return errors.Wrap(err, "error during exec")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) SpendOutPointBalancesBatch(ctx context.Context, outPoints []wire.OutPoint, blockHeight uint64) error {
|
func (r *Repository) SpendOutPointBalancesBatch(ctx context.Context, outPoints []wire.OutPoint, blockHeight uint64) error {
|
||||||
params := make([]gen.SpendOutPointBalancesBatchParams, 0, len(outPoints))
|
if len(outPoints) == 0 {
|
||||||
for _, outPoint := range outPoints {
|
return nil
|
||||||
params = append(params, gen.SpendOutPointBalancesBatchParams{
|
|
||||||
TxHash: outPoint.Hash.String(),
|
|
||||||
TxIdx: int32(outPoint.Index),
|
|
||||||
SpentHeight: pgtype.Int4{Int32: int32(blockHeight), Valid: true},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
results := r.queries.SpendOutPointBalancesBatch(ctx, params)
|
params := gen.BatchSpendOutpointBalancesParams{
|
||||||
var execErrors []error
|
TxHashArr: make([]string, 0, len(outPoints)),
|
||||||
results.Exec(func(i int, err error) {
|
TxIdxArr: make([]int32, 0, len(outPoints)),
|
||||||
if err != nil {
|
SpentHeight: int32(blockHeight),
|
||||||
execErrors = append(execErrors, err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if len(execErrors) > 0 {
|
|
||||||
return errors.Wrap(errors.Join(execErrors...), "error during exec")
|
|
||||||
}
|
}
|
||||||
|
for _, outPoint := range outPoints {
|
||||||
|
params.TxHashArr = append(params.TxHashArr, outPoint.Hash.String())
|
||||||
|
params.TxIdxArr = append(params.TxIdxArr, int32(outPoint.Index))
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := r.queries.BatchSpendOutpointBalances(ctx, params); err != nil {
|
||||||
|
return errors.Wrap(err, "error during exec")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) CreateRuneBalances(ctx context.Context, params []datagateway.CreateRuneBalancesParams) error {
|
func (r *Repository) CreateRuneBalances(ctx context.Context, balances []*entity.Balance) error {
|
||||||
insertParams := make([]gen.CreateRuneBalanceAtBlockParams, 0, len(params))
|
if len(balances) == 0 {
|
||||||
for _, param := range params {
|
return nil
|
||||||
param := param
|
|
||||||
amount, err := numericFromUint128(¶m.Balance)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "failed to convert balance to numeric")
|
|
||||||
}
|
|
||||||
insertParams = append(insertParams, gen.CreateRuneBalanceAtBlockParams{
|
|
||||||
Pkscript: hex.EncodeToString(param.PkScript),
|
|
||||||
BlockHeight: int32(param.BlockHeight),
|
|
||||||
RuneID: param.RuneId.String(),
|
|
||||||
Amount: amount,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
result := r.queries.CreateRuneBalanceAtBlock(ctx, insertParams)
|
|
||||||
var execErrors []error
|
params, err := mapBalanceTypeToParamsBatch(balances)
|
||||||
result.Exec(func(i int, err error) {
|
if err != nil {
|
||||||
if err != nil {
|
return errors.Wrap(err, "failed to map rune balances to params")
|
||||||
execErrors = append(execErrors, err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if len(execErrors) > 0 {
|
|
||||||
return errors.Wrap(errors.Join(execErrors...), "error during exec")
|
|
||||||
}
|
}
|
||||||
|
if err := r.queries.BatchCreateRunesBalances(ctx, params); err != nil {
|
||||||
|
return errors.Wrap(err, "error during exec")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user