mirror of
https://github.com/alexgo-io/gaze-brc20-indexer.git
synced 2026-01-12 14:34:54 +08:00
1139 lines
34 KiB
Go
1139 lines
34 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.26.0
|
|
// source: data.sql
|
|
|
|
package gen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createIndexedBlock = `-- name: CreateIndexedBlock :exec
|
|
INSERT INTO "brc20_indexed_blocks" ("height", "hash", "event_hash", "cumulative_event_hash") VALUES ($1, $2, $3, $4)
|
|
`
|
|
|
|
type CreateIndexedBlockParams struct {
|
|
Height int32
|
|
Hash string
|
|
EventHash string
|
|
CumulativeEventHash string
|
|
}
|
|
|
|
func (q *Queries) CreateIndexedBlock(ctx context.Context, arg CreateIndexedBlockParams) error {
|
|
_, err := q.db.Exec(ctx, createIndexedBlock,
|
|
arg.Height,
|
|
arg.Hash,
|
|
arg.EventHash,
|
|
arg.CumulativeEventHash,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const createProcessorStats = `-- name: CreateProcessorStats :exec
|
|
INSERT INTO "brc20_processor_stats" ("block_height", "cursed_inscription_count", "blessed_inscription_count", "lost_sats") VALUES ($1, $2, $3, $4)
|
|
`
|
|
|
|
type CreateProcessorStatsParams struct {
|
|
BlockHeight int32
|
|
CursedInscriptionCount int32
|
|
BlessedInscriptionCount int32
|
|
LostSats int64
|
|
}
|
|
|
|
func (q *Queries) CreateProcessorStats(ctx context.Context, arg CreateProcessorStatsParams) error {
|
|
_, err := q.db.Exec(ctx, createProcessorStats,
|
|
arg.BlockHeight,
|
|
arg.CursedInscriptionCount,
|
|
arg.BlessedInscriptionCount,
|
|
arg.LostSats,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const deleteBalancesSinceHeight = `-- name: DeleteBalancesSinceHeight :exec
|
|
DELETE FROM "brc20_balances" WHERE "block_height" >= $1
|
|
`
|
|
|
|
func (q *Queries) DeleteBalancesSinceHeight(ctx context.Context, blockHeight int32) error {
|
|
_, err := q.db.Exec(ctx, deleteBalancesSinceHeight, blockHeight)
|
|
return err
|
|
}
|
|
|
|
const deleteEventDeploysSinceHeight = `-- name: DeleteEventDeploysSinceHeight :exec
|
|
DELETE FROM "brc20_event_deploys" WHERE "block_height" >= $1
|
|
`
|
|
|
|
func (q *Queries) DeleteEventDeploysSinceHeight(ctx context.Context, blockHeight int32) error {
|
|
_, err := q.db.Exec(ctx, deleteEventDeploysSinceHeight, blockHeight)
|
|
return err
|
|
}
|
|
|
|
const deleteEventInscribeTransfersSinceHeight = `-- name: DeleteEventInscribeTransfersSinceHeight :exec
|
|
DELETE FROM "brc20_event_inscribe_transfers" WHERE "block_height" >= $1
|
|
`
|
|
|
|
func (q *Queries) DeleteEventInscribeTransfersSinceHeight(ctx context.Context, blockHeight int32) error {
|
|
_, err := q.db.Exec(ctx, deleteEventInscribeTransfersSinceHeight, blockHeight)
|
|
return err
|
|
}
|
|
|
|
const deleteEventMintsSinceHeight = `-- name: DeleteEventMintsSinceHeight :exec
|
|
DELETE FROM "brc20_event_mints" WHERE "block_height" >= $1
|
|
`
|
|
|
|
func (q *Queries) DeleteEventMintsSinceHeight(ctx context.Context, blockHeight int32) error {
|
|
_, err := q.db.Exec(ctx, deleteEventMintsSinceHeight, blockHeight)
|
|
return err
|
|
}
|
|
|
|
const deleteEventTransferTransfersSinceHeight = `-- name: DeleteEventTransferTransfersSinceHeight :exec
|
|
DELETE FROM "brc20_event_transfer_transfers" WHERE "block_height" >= $1
|
|
`
|
|
|
|
func (q *Queries) DeleteEventTransferTransfersSinceHeight(ctx context.Context, blockHeight int32) error {
|
|
_, err := q.db.Exec(ctx, deleteEventTransferTransfersSinceHeight, blockHeight)
|
|
return err
|
|
}
|
|
|
|
const deleteIndexedBlocksSinceHeight = `-- name: DeleteIndexedBlocksSinceHeight :exec
|
|
DELETE FROM "brc20_indexed_blocks" WHERE "height" >= $1
|
|
`
|
|
|
|
func (q *Queries) DeleteIndexedBlocksSinceHeight(ctx context.Context, height int32) error {
|
|
_, err := q.db.Exec(ctx, deleteIndexedBlocksSinceHeight, height)
|
|
return err
|
|
}
|
|
|
|
const deleteInscriptionEntriesSinceHeight = `-- name: DeleteInscriptionEntriesSinceHeight :exec
|
|
DELETE FROM "brc20_inscription_entries" WHERE "created_at_height" >= $1
|
|
`
|
|
|
|
func (q *Queries) DeleteInscriptionEntriesSinceHeight(ctx context.Context, createdAtHeight int32) error {
|
|
_, err := q.db.Exec(ctx, deleteInscriptionEntriesSinceHeight, createdAtHeight)
|
|
return err
|
|
}
|
|
|
|
const deleteInscriptionEntryStatesSinceHeight = `-- name: DeleteInscriptionEntryStatesSinceHeight :exec
|
|
DELETE FROM "brc20_inscription_entry_states" WHERE "block_height" >= $1
|
|
`
|
|
|
|
func (q *Queries) DeleteInscriptionEntryStatesSinceHeight(ctx context.Context, blockHeight int32) error {
|
|
_, err := q.db.Exec(ctx, deleteInscriptionEntryStatesSinceHeight, blockHeight)
|
|
return err
|
|
}
|
|
|
|
const deleteInscriptionTransfersSinceHeight = `-- name: DeleteInscriptionTransfersSinceHeight :exec
|
|
DELETE FROM "brc20_inscription_transfers" WHERE "block_height" >= $1
|
|
`
|
|
|
|
func (q *Queries) DeleteInscriptionTransfersSinceHeight(ctx context.Context, blockHeight int32) error {
|
|
_, err := q.db.Exec(ctx, deleteInscriptionTransfersSinceHeight, blockHeight)
|
|
return err
|
|
}
|
|
|
|
const deleteProcessorStatsSinceHeight = `-- name: DeleteProcessorStatsSinceHeight :exec
|
|
DELETE FROM "brc20_processor_stats" WHERE "block_height" >= $1
|
|
`
|
|
|
|
func (q *Queries) DeleteProcessorStatsSinceHeight(ctx context.Context, blockHeight int32) error {
|
|
_, err := q.db.Exec(ctx, deleteProcessorStatsSinceHeight, blockHeight)
|
|
return err
|
|
}
|
|
|
|
const deleteTickEntriesSinceHeight = `-- name: DeleteTickEntriesSinceHeight :exec
|
|
DELETE FROM "brc20_tick_entries" WHERE "deployed_at_height" >= $1
|
|
`
|
|
|
|
func (q *Queries) DeleteTickEntriesSinceHeight(ctx context.Context, deployedAtHeight int32) error {
|
|
_, err := q.db.Exec(ctx, deleteTickEntriesSinceHeight, deployedAtHeight)
|
|
return err
|
|
}
|
|
|
|
const deleteTickEntryStatesSinceHeight = `-- name: DeleteTickEntryStatesSinceHeight :exec
|
|
DELETE FROM "brc20_tick_entry_states" WHERE "block_height" >= $1
|
|
`
|
|
|
|
func (q *Queries) DeleteTickEntryStatesSinceHeight(ctx context.Context, blockHeight int32) error {
|
|
_, err := q.db.Exec(ctx, deleteTickEntryStatesSinceHeight, blockHeight)
|
|
return err
|
|
}
|
|
|
|
const getBalancesBatchAtHeight = `-- name: GetBalancesBatchAtHeight :many
|
|
SELECT DISTINCT ON ("brc20_balances"."pkscript", "brc20_balances"."tick") brc20_balances.pkscript, brc20_balances.block_height, brc20_balances.tick, brc20_balances.overall_balance, brc20_balances.available_balance FROM "brc20_balances"
|
|
INNER JOIN (
|
|
SELECT
|
|
unnest($1::text[]) AS "pkscript",
|
|
unnest($2::text[]) AS "tick"
|
|
) "queries" ON "brc20_balances"."pkscript" = "queries"."pkscript" AND "brc20_balances"."tick" = "queries"."tick" AND "brc20_balances"."block_height" <= $3
|
|
ORDER BY "brc20_balances"."pkscript", "brc20_balances"."tick", "block_height" DESC
|
|
`
|
|
|
|
type GetBalancesBatchAtHeightParams struct {
|
|
PkscriptArr []string
|
|
TickArr []string
|
|
BlockHeight int32
|
|
}
|
|
|
|
func (q *Queries) GetBalancesBatchAtHeight(ctx context.Context, arg GetBalancesBatchAtHeightParams) ([]Brc20Balance, error) {
|
|
rows, err := q.db.Query(ctx, getBalancesBatchAtHeight, arg.PkscriptArr, arg.TickArr, arg.BlockHeight)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Brc20Balance
|
|
for rows.Next() {
|
|
var i Brc20Balance
|
|
if err := rows.Scan(
|
|
&i.Pkscript,
|
|
&i.BlockHeight,
|
|
&i.Tick,
|
|
&i.OverallBalance,
|
|
&i.AvailableBalance,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getBalancesByPkScript = `-- name: GetBalancesByPkScript :many
|
|
WITH balances AS (
|
|
SELECT DISTINCT ON (tick) pkscript, block_height, tick, overall_balance, available_balance FROM brc20_balances WHERE pkscript = $1 AND block_height <= $2 ORDER BY tick, overall_balance DESC
|
|
)
|
|
SELECT pkscript, block_height, tick, overall_balance, available_balance FROM balances WHERE overall_balance > 0
|
|
`
|
|
|
|
type GetBalancesByPkScriptParams struct {
|
|
Pkscript string
|
|
BlockHeight int32
|
|
}
|
|
|
|
type GetBalancesByPkScriptRow struct {
|
|
Pkscript string
|
|
BlockHeight int32
|
|
Tick string
|
|
OverallBalance pgtype.Numeric
|
|
AvailableBalance pgtype.Numeric
|
|
}
|
|
|
|
func (q *Queries) GetBalancesByPkScript(ctx context.Context, arg GetBalancesByPkScriptParams) ([]GetBalancesByPkScriptRow, error) {
|
|
rows, err := q.db.Query(ctx, getBalancesByPkScript, arg.Pkscript, arg.BlockHeight)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetBalancesByPkScriptRow
|
|
for rows.Next() {
|
|
var i GetBalancesByPkScriptRow
|
|
if err := rows.Scan(
|
|
&i.Pkscript,
|
|
&i.BlockHeight,
|
|
&i.Tick,
|
|
&i.OverallBalance,
|
|
&i.AvailableBalance,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getBalancesByTick = `-- name: GetBalancesByTick :many
|
|
WITH balances AS (
|
|
SELECT DISTINCT ON (pkscript) pkscript, block_height, tick, overall_balance, available_balance FROM brc20_balances WHERE tick = $1 AND block_height <= $2 ORDER BY pkscript, block_height DESC
|
|
)
|
|
SELECT pkscript, block_height, tick, overall_balance, available_balance FROM balances WHERE overall_balance > 0
|
|
`
|
|
|
|
type GetBalancesByTickParams struct {
|
|
Tick string
|
|
BlockHeight int32
|
|
}
|
|
|
|
type GetBalancesByTickRow struct {
|
|
Pkscript string
|
|
BlockHeight int32
|
|
Tick string
|
|
OverallBalance pgtype.Numeric
|
|
AvailableBalance pgtype.Numeric
|
|
}
|
|
|
|
func (q *Queries) GetBalancesByTick(ctx context.Context, arg GetBalancesByTickParams) ([]GetBalancesByTickRow, error) {
|
|
rows, err := q.db.Query(ctx, getBalancesByTick, arg.Tick, arg.BlockHeight)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetBalancesByTickRow
|
|
for rows.Next() {
|
|
var i GetBalancesByTickRow
|
|
if err := rows.Scan(
|
|
&i.Pkscript,
|
|
&i.BlockHeight,
|
|
&i.Tick,
|
|
&i.OverallBalance,
|
|
&i.AvailableBalance,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getDeployEventByTick = `-- name: GetDeployEventByTick :one
|
|
SELECT id, inscription_id, inscription_number, tick, original_tick, tx_hash, block_height, tx_index, timestamp, pkscript, satpoint, total_supply, decimals, limit_per_mint, is_self_mint FROM brc20_event_deploys WHERE tick = $1
|
|
`
|
|
|
|
func (q *Queries) GetDeployEventByTick(ctx context.Context, tick string) (Brc20EventDeploy, error) {
|
|
row := q.db.QueryRow(ctx, getDeployEventByTick, tick)
|
|
var i Brc20EventDeploy
|
|
err := row.Scan(
|
|
&i.Id,
|
|
&i.InscriptionID,
|
|
&i.InscriptionNumber,
|
|
&i.Tick,
|
|
&i.OriginalTick,
|
|
&i.TxHash,
|
|
&i.BlockHeight,
|
|
&i.TxIndex,
|
|
&i.Timestamp,
|
|
&i.Pkscript,
|
|
&i.Satpoint,
|
|
&i.TotalSupply,
|
|
&i.Decimals,
|
|
&i.LimitPerMint,
|
|
&i.IsSelfMint,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getDeployEvents = `-- name: GetDeployEvents :many
|
|
SELECT id, inscription_id, inscription_number, tick, original_tick, tx_hash, block_height, tx_index, timestamp, pkscript, satpoint, total_supply, decimals, limit_per_mint, is_self_mint FROM "brc20_event_deploys"
|
|
WHERE (
|
|
$1::BOOLEAN = FALSE -- if @filter_pk_script is TRUE, apply pk_script filter
|
|
OR pkscript = $2
|
|
) AND (
|
|
$3::BOOLEAN = FALSE -- if @filter_ticker is TRUE, apply ticker filter
|
|
OR tick = $4
|
|
) AND (
|
|
$5::INT = 0 OR block_height = $5::INT -- if @block_height > 0, apply block_height filter
|
|
)
|
|
`
|
|
|
|
type GetDeployEventsParams struct {
|
|
FilterPkScript bool
|
|
PkScript string
|
|
FilterTicker bool
|
|
Ticker string
|
|
BlockHeight int32
|
|
}
|
|
|
|
func (q *Queries) GetDeployEvents(ctx context.Context, arg GetDeployEventsParams) ([]Brc20EventDeploy, error) {
|
|
rows, err := q.db.Query(ctx, getDeployEvents,
|
|
arg.FilterPkScript,
|
|
arg.PkScript,
|
|
arg.FilterTicker,
|
|
arg.Ticker,
|
|
arg.BlockHeight,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Brc20EventDeploy
|
|
for rows.Next() {
|
|
var i Brc20EventDeploy
|
|
if err := rows.Scan(
|
|
&i.Id,
|
|
&i.InscriptionID,
|
|
&i.InscriptionNumber,
|
|
&i.Tick,
|
|
&i.OriginalTick,
|
|
&i.TxHash,
|
|
&i.BlockHeight,
|
|
&i.TxIndex,
|
|
&i.Timestamp,
|
|
&i.Pkscript,
|
|
&i.Satpoint,
|
|
&i.TotalSupply,
|
|
&i.Decimals,
|
|
&i.LimitPerMint,
|
|
&i.IsSelfMint,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getEventInscribeTransfersByInscriptionIds = `-- name: GetEventInscribeTransfersByInscriptionIds :many
|
|
SELECT id, inscription_id, inscription_number, tick, original_tick, tx_hash, block_height, tx_index, timestamp, pkscript, satpoint, output_index, sats_amount, amount FROM "brc20_event_inscribe_transfers" WHERE "inscription_id" = ANY($1::text[])
|
|
`
|
|
|
|
func (q *Queries) GetEventInscribeTransfersByInscriptionIds(ctx context.Context, inscriptionIds []string) ([]Brc20EventInscribeTransfer, error) {
|
|
rows, err := q.db.Query(ctx, getEventInscribeTransfersByInscriptionIds, inscriptionIds)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Brc20EventInscribeTransfer
|
|
for rows.Next() {
|
|
var i Brc20EventInscribeTransfer
|
|
if err := rows.Scan(
|
|
&i.Id,
|
|
&i.InscriptionID,
|
|
&i.InscriptionNumber,
|
|
&i.Tick,
|
|
&i.OriginalTick,
|
|
&i.TxHash,
|
|
&i.BlockHeight,
|
|
&i.TxIndex,
|
|
&i.Timestamp,
|
|
&i.Pkscript,
|
|
&i.Satpoint,
|
|
&i.OutputIndex,
|
|
&i.SatsAmount,
|
|
&i.Amount,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getFirstLastInscriptionNumberByTick = `-- name: GetFirstLastInscriptionNumberByTick :one
|
|
SELECT
|
|
COALESCE(MIN("inscription_number"), -1)::BIGINT AS "first_inscription_number",
|
|
COALESCE(MAX("inscription_number"), -1)::BIGINT AS "last_inscription_number"
|
|
FROM (
|
|
SELECT inscription_number FROM "brc20_event_mints" WHERE "brc20_event_mints"."tick" = $1
|
|
UNION ALL
|
|
SELECT inscription_number FROM "brc20_event_inscribe_transfers" WHERE "brc20_event_inscribe_transfers"."tick" = $1
|
|
UNION ALL
|
|
SELECT inscription_number FROM "brc20_event_transfer_transfers" WHERE "brc20_event_transfer_transfers"."tick" = $1
|
|
) as events
|
|
`
|
|
|
|
type GetFirstLastInscriptionNumberByTickRow struct {
|
|
FirstInscriptionNumber int64
|
|
LastInscriptionNumber int64
|
|
}
|
|
|
|
func (q *Queries) GetFirstLastInscriptionNumberByTick(ctx context.Context, tick string) (GetFirstLastInscriptionNumberByTickRow, error) {
|
|
row := q.db.QueryRow(ctx, getFirstLastInscriptionNumberByTick, tick)
|
|
var i GetFirstLastInscriptionNumberByTickRow
|
|
err := row.Scan(&i.FirstInscriptionNumber, &i.LastInscriptionNumber)
|
|
return i, err
|
|
}
|
|
|
|
const getIndexedBlockByHeight = `-- name: GetIndexedBlockByHeight :one
|
|
SELECT height, hash, event_hash, cumulative_event_hash FROM "brc20_indexed_blocks" WHERE "height" = $1
|
|
`
|
|
|
|
func (q *Queries) GetIndexedBlockByHeight(ctx context.Context, height int32) (Brc20IndexedBlock, error) {
|
|
row := q.db.QueryRow(ctx, getIndexedBlockByHeight, height)
|
|
var i Brc20IndexedBlock
|
|
err := row.Scan(
|
|
&i.Height,
|
|
&i.Hash,
|
|
&i.EventHash,
|
|
&i.CumulativeEventHash,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getInscribeTransferEvents = `-- name: GetInscribeTransferEvents :many
|
|
SELECT id, inscription_id, inscription_number, tick, original_tick, tx_hash, block_height, tx_index, timestamp, pkscript, satpoint, output_index, sats_amount, amount FROM "brc20_event_inscribe_transfers"
|
|
WHERE (
|
|
$1::BOOLEAN = FALSE -- if @filter_pk_script is TRUE, apply pk_script filter
|
|
OR pkscript = $2
|
|
) AND (
|
|
$3::BOOLEAN = FALSE -- if @filter_ticker is TRUE, apply ticker filter
|
|
OR tick = $4
|
|
) AND (
|
|
$5::INT = 0 OR block_height = $5::INT -- if @block_height > 0, apply block_height filter
|
|
)
|
|
`
|
|
|
|
type GetInscribeTransferEventsParams struct {
|
|
FilterPkScript bool
|
|
PkScript string
|
|
FilterTicker bool
|
|
Ticker string
|
|
BlockHeight int32
|
|
}
|
|
|
|
func (q *Queries) GetInscribeTransferEvents(ctx context.Context, arg GetInscribeTransferEventsParams) ([]Brc20EventInscribeTransfer, error) {
|
|
rows, err := q.db.Query(ctx, getInscribeTransferEvents,
|
|
arg.FilterPkScript,
|
|
arg.PkScript,
|
|
arg.FilterTicker,
|
|
arg.Ticker,
|
|
arg.BlockHeight,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Brc20EventInscribeTransfer
|
|
for rows.Next() {
|
|
var i Brc20EventInscribeTransfer
|
|
if err := rows.Scan(
|
|
&i.Id,
|
|
&i.InscriptionID,
|
|
&i.InscriptionNumber,
|
|
&i.Tick,
|
|
&i.OriginalTick,
|
|
&i.TxHash,
|
|
&i.BlockHeight,
|
|
&i.TxIndex,
|
|
&i.Timestamp,
|
|
&i.Pkscript,
|
|
&i.Satpoint,
|
|
&i.OutputIndex,
|
|
&i.SatsAmount,
|
|
&i.Amount,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getInscriptionEntriesByIds = `-- name: GetInscriptionEntriesByIds :many
|
|
WITH "states" AS (
|
|
-- select latest state
|
|
SELECT DISTINCT ON ("id") id, block_height, transfer_count FROM "brc20_inscription_entry_states" WHERE "id" = ANY($1::text[]) ORDER BY "id", "block_height" DESC
|
|
)
|
|
SELECT brc20_inscription_entries.id, number, sequence_number, delegate, metadata, metaprotocol, parents, pointer, content, content_encoding, content_type, cursed, cursed_for_brc20, created_at, created_at_height, states.id, block_height, transfer_count FROM "brc20_inscription_entries"
|
|
LEFT JOIN "states" ON "brc20_inscription_entries"."id" = "states"."id"
|
|
WHERE "brc20_inscription_entries"."id" = ANY($1::text[])
|
|
`
|
|
|
|
type GetInscriptionEntriesByIdsRow struct {
|
|
Id string
|
|
Number int64
|
|
SequenceNumber int64
|
|
Delegate pgtype.Text
|
|
Metadata []byte
|
|
Metaprotocol pgtype.Text
|
|
Parents []string
|
|
Pointer pgtype.Int8
|
|
Content []byte
|
|
ContentEncoding pgtype.Text
|
|
ContentType pgtype.Text
|
|
Cursed bool
|
|
CursedForBrc20 bool
|
|
CreatedAt pgtype.Timestamp
|
|
CreatedAtHeight int32
|
|
Id_2 pgtype.Text
|
|
BlockHeight pgtype.Int4
|
|
TransferCount pgtype.Int4
|
|
}
|
|
|
|
func (q *Queries) GetInscriptionEntriesByIds(ctx context.Context, inscriptionIds []string) ([]GetInscriptionEntriesByIdsRow, error) {
|
|
rows, err := q.db.Query(ctx, getInscriptionEntriesByIds, inscriptionIds)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetInscriptionEntriesByIdsRow
|
|
for rows.Next() {
|
|
var i GetInscriptionEntriesByIdsRow
|
|
if err := rows.Scan(
|
|
&i.Id,
|
|
&i.Number,
|
|
&i.SequenceNumber,
|
|
&i.Delegate,
|
|
&i.Metadata,
|
|
&i.Metaprotocol,
|
|
&i.Parents,
|
|
&i.Pointer,
|
|
&i.Content,
|
|
&i.ContentEncoding,
|
|
&i.ContentType,
|
|
&i.Cursed,
|
|
&i.CursedForBrc20,
|
|
&i.CreatedAt,
|
|
&i.CreatedAtHeight,
|
|
&i.Id_2,
|
|
&i.BlockHeight,
|
|
&i.TransferCount,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getInscriptionNumbersByIds = `-- name: GetInscriptionNumbersByIds :many
|
|
SELECT id, number FROM "brc20_inscription_entries" WHERE "id" = ANY($1::text[])
|
|
`
|
|
|
|
type GetInscriptionNumbersByIdsRow struct {
|
|
Id string
|
|
Number int64
|
|
}
|
|
|
|
func (q *Queries) GetInscriptionNumbersByIds(ctx context.Context, inscriptionIds []string) ([]GetInscriptionNumbersByIdsRow, error) {
|
|
rows, err := q.db.Query(ctx, getInscriptionNumbersByIds, inscriptionIds)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetInscriptionNumbersByIdsRow
|
|
for rows.Next() {
|
|
var i GetInscriptionNumbersByIdsRow
|
|
if err := rows.Scan(&i.Id, &i.Number); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getInscriptionParentsByIds = `-- name: GetInscriptionParentsByIds :many
|
|
SELECT id, parents FROM "brc20_inscription_entries" WHERE "id" = ANY($1::text[])
|
|
`
|
|
|
|
type GetInscriptionParentsByIdsRow struct {
|
|
Id string
|
|
Parents []string
|
|
}
|
|
|
|
func (q *Queries) GetInscriptionParentsByIds(ctx context.Context, inscriptionIds []string) ([]GetInscriptionParentsByIdsRow, error) {
|
|
rows, err := q.db.Query(ctx, getInscriptionParentsByIds, inscriptionIds)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetInscriptionParentsByIdsRow
|
|
for rows.Next() {
|
|
var i GetInscriptionParentsByIdsRow
|
|
if err := rows.Scan(&i.Id, &i.Parents); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getInscriptionTransfersInOutPoints = `-- name: GetInscriptionTransfersInOutPoints :many
|
|
SELECT it.inscription_id, it.inscription_number, it.inscription_sequence_number, it.block_height, it.tx_index, it.tx_hash, it.from_input_index, it.old_satpoint_tx_hash, it.old_satpoint_out_idx, it.old_satpoint_offset, it.new_satpoint_tx_hash, it.new_satpoint_out_idx, it.new_satpoint_offset, it.new_pkscript, it.new_output_value, it.sent_as_fee, it.transfer_count, "ie"."content" FROM (
|
|
SELECT
|
|
unnest($1::text[]) AS "tx_hash",
|
|
unnest($2::int[]) AS "tx_out_idx"
|
|
) "inputs"
|
|
INNER JOIN "brc20_inscription_transfers" it ON "inputs"."tx_hash" = "it"."new_satpoint_tx_hash" AND "inputs"."tx_out_idx" = "it"."new_satpoint_out_idx"
|
|
LEFT JOIN "brc20_inscription_entries" ie ON "it"."inscription_id" = "ie"."id"
|
|
`
|
|
|
|
type GetInscriptionTransfersInOutPointsParams struct {
|
|
TxHashArr []string
|
|
TxOutIdxArr []int32
|
|
}
|
|
|
|
type GetInscriptionTransfersInOutPointsRow struct {
|
|
InscriptionID string
|
|
InscriptionNumber int64
|
|
InscriptionSequenceNumber int64
|
|
BlockHeight int32
|
|
TxIndex int32
|
|
TxHash string
|
|
FromInputIndex int32
|
|
OldSatpointTxHash pgtype.Text
|
|
OldSatpointOutIdx pgtype.Int4
|
|
OldSatpointOffset pgtype.Int8
|
|
NewSatpointTxHash pgtype.Text
|
|
NewSatpointOutIdx pgtype.Int4
|
|
NewSatpointOffset pgtype.Int8
|
|
NewPkscript string
|
|
NewOutputValue int64
|
|
SentAsFee bool
|
|
TransferCount int32
|
|
Content []byte
|
|
}
|
|
|
|
func (q *Queries) GetInscriptionTransfersInOutPoints(ctx context.Context, arg GetInscriptionTransfersInOutPointsParams) ([]GetInscriptionTransfersInOutPointsRow, error) {
|
|
rows, err := q.db.Query(ctx, getInscriptionTransfersInOutPoints, arg.TxHashArr, arg.TxOutIdxArr)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetInscriptionTransfersInOutPointsRow
|
|
for rows.Next() {
|
|
var i GetInscriptionTransfersInOutPointsRow
|
|
if err := rows.Scan(
|
|
&i.InscriptionID,
|
|
&i.InscriptionNumber,
|
|
&i.InscriptionSequenceNumber,
|
|
&i.BlockHeight,
|
|
&i.TxIndex,
|
|
&i.TxHash,
|
|
&i.FromInputIndex,
|
|
&i.OldSatpointTxHash,
|
|
&i.OldSatpointOutIdx,
|
|
&i.OldSatpointOffset,
|
|
&i.NewSatpointTxHash,
|
|
&i.NewSatpointOutIdx,
|
|
&i.NewSatpointOffset,
|
|
&i.NewPkscript,
|
|
&i.NewOutputValue,
|
|
&i.SentAsFee,
|
|
&i.TransferCount,
|
|
&i.Content,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getLatestEventIds = `-- name: GetLatestEventIds :one
|
|
WITH "latest_deploy_id" AS (
|
|
SELECT "id" FROM "brc20_event_deploys" ORDER BY "id" DESC LIMIT 1
|
|
),
|
|
"latest_mint_id" AS (
|
|
SELECT "id" FROM "brc20_event_mints" ORDER BY "id" DESC LIMIT 1
|
|
),
|
|
"latest_inscribe_transfer_id" AS (
|
|
SELECT "id" FROM "brc20_event_inscribe_transfers" ORDER BY "id" DESC LIMIT 1
|
|
),
|
|
"latest_transfer_transfer_id" AS (
|
|
SELECT "id" FROM "brc20_event_transfer_transfers" ORDER BY "id" DESC LIMIT 1
|
|
)
|
|
SELECT
|
|
COALESCE((SELECT "id" FROM "latest_deploy_id"), -1) AS "event_deploy_id",
|
|
COALESCE((SELECT "id" FROM "latest_mint_id"), -1) AS "event_mint_id",
|
|
COALESCE((SELECT "id" FROM "latest_inscribe_transfer_id"), -1) AS "event_inscribe_transfer_id",
|
|
COALESCE((SELECT "id" FROM "latest_transfer_transfer_id"), -1) AS "event_transfer_transfer_id"
|
|
`
|
|
|
|
type GetLatestEventIdsRow struct {
|
|
EventDeployID interface{}
|
|
EventMintID interface{}
|
|
EventInscribeTransferID interface{}
|
|
EventTransferTransferID interface{}
|
|
}
|
|
|
|
func (q *Queries) GetLatestEventIds(ctx context.Context) (GetLatestEventIdsRow, error) {
|
|
row := q.db.QueryRow(ctx, getLatestEventIds)
|
|
var i GetLatestEventIdsRow
|
|
err := row.Scan(
|
|
&i.EventDeployID,
|
|
&i.EventMintID,
|
|
&i.EventInscribeTransferID,
|
|
&i.EventTransferTransferID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getLatestIndexedBlock = `-- name: GetLatestIndexedBlock :one
|
|
SELECT height, hash, event_hash, cumulative_event_hash FROM "brc20_indexed_blocks" ORDER BY "height" DESC LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetLatestIndexedBlock(ctx context.Context) (Brc20IndexedBlock, error) {
|
|
row := q.db.QueryRow(ctx, getLatestIndexedBlock)
|
|
var i Brc20IndexedBlock
|
|
err := row.Scan(
|
|
&i.Height,
|
|
&i.Hash,
|
|
&i.EventHash,
|
|
&i.CumulativeEventHash,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getLatestProcessorStats = `-- name: GetLatestProcessorStats :one
|
|
SELECT block_height, cursed_inscription_count, blessed_inscription_count, lost_sats FROM "brc20_processor_stats" ORDER BY "block_height" DESC LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetLatestProcessorStats(ctx context.Context) (Brc20ProcessorStat, error) {
|
|
row := q.db.QueryRow(ctx, getLatestProcessorStats)
|
|
var i Brc20ProcessorStat
|
|
err := row.Scan(
|
|
&i.BlockHeight,
|
|
&i.CursedInscriptionCount,
|
|
&i.BlessedInscriptionCount,
|
|
&i.LostSats,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getMintEvents = `-- name: GetMintEvents :many
|
|
SELECT id, inscription_id, inscription_number, tick, original_tick, tx_hash, block_height, tx_index, timestamp, pkscript, satpoint, amount, parent_id FROM "brc20_event_mints"
|
|
WHERE (
|
|
$1::BOOLEAN = FALSE -- if @filter_pk_script is TRUE, apply pk_script filter
|
|
OR pkscript = $2
|
|
) AND (
|
|
$3::BOOLEAN = FALSE -- if @filter_ticker is TRUE, apply ticker filter
|
|
OR tick = $4
|
|
) AND (
|
|
$5::INT = 0 OR block_height = $5::INT -- if @block_height > 0, apply block_height filter
|
|
)
|
|
`
|
|
|
|
type GetMintEventsParams struct {
|
|
FilterPkScript bool
|
|
PkScript string
|
|
FilterTicker bool
|
|
Ticker string
|
|
BlockHeight int32
|
|
}
|
|
|
|
func (q *Queries) GetMintEvents(ctx context.Context, arg GetMintEventsParams) ([]Brc20EventMint, error) {
|
|
rows, err := q.db.Query(ctx, getMintEvents,
|
|
arg.FilterPkScript,
|
|
arg.PkScript,
|
|
arg.FilterTicker,
|
|
arg.Ticker,
|
|
arg.BlockHeight,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Brc20EventMint
|
|
for rows.Next() {
|
|
var i Brc20EventMint
|
|
if err := rows.Scan(
|
|
&i.Id,
|
|
&i.InscriptionID,
|
|
&i.InscriptionNumber,
|
|
&i.Tick,
|
|
&i.OriginalTick,
|
|
&i.TxHash,
|
|
&i.BlockHeight,
|
|
&i.TxIndex,
|
|
&i.Timestamp,
|
|
&i.Pkscript,
|
|
&i.Satpoint,
|
|
&i.Amount,
|
|
&i.ParentID,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getTickEntriesByTicks = `-- name: GetTickEntriesByTicks :many
|
|
WITH "states" AS (
|
|
-- select latest state
|
|
SELECT DISTINCT ON ("tick") tick, block_height, minted_amount, burned_amount, completed_at, completed_at_height FROM "brc20_tick_entry_states" WHERE "tick" = ANY($1::text[]) ORDER BY "tick", "block_height" DESC
|
|
)
|
|
SELECT brc20_tick_entries.tick, original_tick, total_supply, decimals, limit_per_mint, is_self_mint, deploy_inscription_id, deployed_at, deployed_at_height, states.tick, block_height, minted_amount, burned_amount, completed_at, completed_at_height FROM "brc20_tick_entries"
|
|
LEFT JOIN "states" ON "brc20_tick_entries"."tick" = "states"."tick"
|
|
WHERE "brc20_tick_entries"."tick" = ANY($1::text[])
|
|
`
|
|
|
|
type GetTickEntriesByTicksRow struct {
|
|
Tick string
|
|
OriginalTick string
|
|
TotalSupply pgtype.Numeric
|
|
Decimals int16
|
|
LimitPerMint pgtype.Numeric
|
|
IsSelfMint bool
|
|
DeployInscriptionID string
|
|
DeployedAt pgtype.Timestamp
|
|
DeployedAtHeight int32
|
|
Tick_2 pgtype.Text
|
|
BlockHeight pgtype.Int4
|
|
MintedAmount pgtype.Numeric
|
|
BurnedAmount pgtype.Numeric
|
|
CompletedAt pgtype.Timestamp
|
|
CompletedAtHeight pgtype.Int4
|
|
}
|
|
|
|
func (q *Queries) GetTickEntriesByTicks(ctx context.Context, ticks []string) ([]GetTickEntriesByTicksRow, error) {
|
|
rows, err := q.db.Query(ctx, getTickEntriesByTicks, ticks)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetTickEntriesByTicksRow
|
|
for rows.Next() {
|
|
var i GetTickEntriesByTicksRow
|
|
if err := rows.Scan(
|
|
&i.Tick,
|
|
&i.OriginalTick,
|
|
&i.TotalSupply,
|
|
&i.Decimals,
|
|
&i.LimitPerMint,
|
|
&i.IsSelfMint,
|
|
&i.DeployInscriptionID,
|
|
&i.DeployedAt,
|
|
&i.DeployedAtHeight,
|
|
&i.Tick_2,
|
|
&i.BlockHeight,
|
|
&i.MintedAmount,
|
|
&i.BurnedAmount,
|
|
&i.CompletedAt,
|
|
&i.CompletedAtHeight,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getTickEntriesByTicksAndHeight = `-- name: GetTickEntriesByTicksAndHeight :many
|
|
|
|
WITH "states" AS (
|
|
-- select latest state
|
|
SELECT DISTINCT ON ("tick") tick, block_height, minted_amount, burned_amount, completed_at, completed_at_height FROM "brc20_tick_entry_states" WHERE "tick" = ANY($1::text[]) AND block_height <= $2 ORDER BY "tick", "block_height" DESC
|
|
)
|
|
SELECT brc20_tick_entries.tick, original_tick, total_supply, decimals, limit_per_mint, is_self_mint, deploy_inscription_id, deployed_at, deployed_at_height, states.tick, block_height, minted_amount, burned_amount, completed_at, completed_at_height FROM "brc20_tick_entries"
|
|
LEFT JOIN "states" ON "brc20_tick_entries"."tick" = "states"."tick"
|
|
WHERE "brc20_tick_entries"."tick" = ANY($1::text[]) AND deployed_at_height <= $2
|
|
`
|
|
|
|
type GetTickEntriesByTicksAndHeightParams struct {
|
|
Ticks []string
|
|
Height int32
|
|
}
|
|
|
|
type GetTickEntriesByTicksAndHeightRow struct {
|
|
Tick string
|
|
OriginalTick string
|
|
TotalSupply pgtype.Numeric
|
|
Decimals int16
|
|
LimitPerMint pgtype.Numeric
|
|
IsSelfMint bool
|
|
DeployInscriptionID string
|
|
DeployedAt pgtype.Timestamp
|
|
DeployedAtHeight int32
|
|
Tick_2 pgtype.Text
|
|
BlockHeight pgtype.Int4
|
|
MintedAmount pgtype.Numeric
|
|
BurnedAmount pgtype.Numeric
|
|
CompletedAt pgtype.Timestamp
|
|
CompletedAtHeight pgtype.Int4
|
|
}
|
|
|
|
// WITH
|
|
// "first_mint" AS (SELECT "inscription_number" FROM "brc20_event_mints" WHERE "brc20_event_mints".tick = $1 ORDER BY "id" ASC LIMIT 1),
|
|
// "latest_mint" AS (SELECT "inscription_number" FROM "brc20_event_mints" WHERE "brc20_event_mints".tick = $1 ORDER BY "id" DESC LIMIT 1),
|
|
// "first_inscribe_transfer" AS (SELECT "inscription_number" FROM "brc20_event_inscribe_transfers" WHERE "brc20_event_inscribe_transfers".tick = $1 ORDER BY "id" ASC LIMIT 1),
|
|
// "latest_inscribe_transfer" AS (SELECT "inscription_number" FROM "brc20_event_inscribe_transfers" WHERE "brc20_event_inscribe_transfers".tick = $1 ORDER BY "id" DESC LIMIT 1)
|
|
// SELECT
|
|
//
|
|
// COALESCE(
|
|
// LEAST(
|
|
// (SELECT "inscription_number" FROM "first_mint"),
|
|
// (SELECT "inscription_number" FROM "first_inscribe_transfer")
|
|
// ),
|
|
// -1
|
|
// ) AS "first_inscription_number",
|
|
// COALESCE(
|
|
// GREATEST(
|
|
// (SELECT "inscription_number" FROM "latest_mint"),
|
|
// (SELECT "inscription_number" FROM "latest_inscribe_transfer")
|
|
// ),
|
|
// -1
|
|
// ) AS "last_inscription_number";
|
|
func (q *Queries) GetTickEntriesByTicksAndHeight(ctx context.Context, arg GetTickEntriesByTicksAndHeightParams) ([]GetTickEntriesByTicksAndHeightRow, error) {
|
|
rows, err := q.db.Query(ctx, getTickEntriesByTicksAndHeight, arg.Ticks, arg.Height)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetTickEntriesByTicksAndHeightRow
|
|
for rows.Next() {
|
|
var i GetTickEntriesByTicksAndHeightRow
|
|
if err := rows.Scan(
|
|
&i.Tick,
|
|
&i.OriginalTick,
|
|
&i.TotalSupply,
|
|
&i.Decimals,
|
|
&i.LimitPerMint,
|
|
&i.IsSelfMint,
|
|
&i.DeployInscriptionID,
|
|
&i.DeployedAt,
|
|
&i.DeployedAtHeight,
|
|
&i.Tick_2,
|
|
&i.BlockHeight,
|
|
&i.MintedAmount,
|
|
&i.BurnedAmount,
|
|
&i.CompletedAt,
|
|
&i.CompletedAtHeight,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getTransferTransferEvents = `-- name: GetTransferTransferEvents :many
|
|
SELECT id, inscription_id, inscription_number, tick, original_tick, tx_hash, block_height, tx_index, timestamp, from_pkscript, from_satpoint, from_input_index, to_pkscript, to_satpoint, to_output_index, spent_as_fee, amount FROM "brc20_event_transfer_transfers"
|
|
WHERE (
|
|
$1::BOOLEAN = FALSE -- if @filter_pk_script is TRUE, apply pk_script filter
|
|
OR from_pkscript = $2
|
|
OR to_pkscript = $2
|
|
) AND (
|
|
$3::BOOLEAN = FALSE -- if @filter_ticker is TRUE, apply ticker filter
|
|
OR tick = $4
|
|
) AND (
|
|
$5::INT = 0 OR block_height = $5::INT -- if @block_height > 0, apply block_height filter
|
|
)
|
|
`
|
|
|
|
type GetTransferTransferEventsParams struct {
|
|
FilterPkScript bool
|
|
PkScript string
|
|
FilterTicker bool
|
|
Ticker string
|
|
BlockHeight int32
|
|
}
|
|
|
|
func (q *Queries) GetTransferTransferEvents(ctx context.Context, arg GetTransferTransferEventsParams) ([]Brc20EventTransferTransfer, error) {
|
|
rows, err := q.db.Query(ctx, getTransferTransferEvents,
|
|
arg.FilterPkScript,
|
|
arg.PkScript,
|
|
arg.FilterTicker,
|
|
arg.Ticker,
|
|
arg.BlockHeight,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Brc20EventTransferTransfer
|
|
for rows.Next() {
|
|
var i Brc20EventTransferTransfer
|
|
if err := rows.Scan(
|
|
&i.Id,
|
|
&i.InscriptionID,
|
|
&i.InscriptionNumber,
|
|
&i.Tick,
|
|
&i.OriginalTick,
|
|
&i.TxHash,
|
|
&i.BlockHeight,
|
|
&i.TxIndex,
|
|
&i.Timestamp,
|
|
&i.FromPkscript,
|
|
&i.FromSatpoint,
|
|
&i.FromInputIndex,
|
|
&i.ToPkscript,
|
|
&i.ToSatpoint,
|
|
&i.ToOutputIndex,
|
|
&i.SpentAsFee,
|
|
&i.Amount,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getTransferableTransfersByPkScript = `-- name: GetTransferableTransfersByPkScript :many
|
|
SELECT id, inscription_id, inscription_number, tick, original_tick, tx_hash, block_height, tx_index, timestamp, pkscript, satpoint, output_index, sats_amount, amount
|
|
FROM "brc20_event_inscribe_transfers"
|
|
WHERE
|
|
pkscript = $1
|
|
AND "brc20_event_inscribe_transfers"."block_height" <= $2
|
|
AND NOT EXISTS (
|
|
SELECT NULL
|
|
FROM "brc20_event_transfer_transfers"
|
|
WHERE "brc20_event_transfer_transfers"."inscription_id" = "brc20_event_inscribe_transfers"."inscription_id"
|
|
)
|
|
ORDER BY "brc20_event_inscribe_transfers"."block_height" DESC
|
|
`
|
|
|
|
type GetTransferableTransfersByPkScriptParams struct {
|
|
Pkscript string
|
|
BlockHeight int32
|
|
}
|
|
|
|
func (q *Queries) GetTransferableTransfersByPkScript(ctx context.Context, arg GetTransferableTransfersByPkScriptParams) ([]Brc20EventInscribeTransfer, error) {
|
|
rows, err := q.db.Query(ctx, getTransferableTransfersByPkScript, arg.Pkscript, arg.BlockHeight)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Brc20EventInscribeTransfer
|
|
for rows.Next() {
|
|
var i Brc20EventInscribeTransfer
|
|
if err := rows.Scan(
|
|
&i.Id,
|
|
&i.InscriptionID,
|
|
&i.InscriptionNumber,
|
|
&i.Tick,
|
|
&i.OriginalTick,
|
|
&i.TxHash,
|
|
&i.BlockHeight,
|
|
&i.TxIndex,
|
|
&i.Timestamp,
|
|
&i.Pkscript,
|
|
&i.Satpoint,
|
|
&i.OutputIndex,
|
|
&i.SatsAmount,
|
|
&i.Amount,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|