mirror of
https://github.com/alexgo-io/gaze-indexer.git
synced 2026-01-12 08:34:28 +08:00
* feat: implement pagination on get balance, get holders * feat: paginate get transactions * fix: remove debug * feat: implement pagination in get utxos * feat: sort response in get holders * feat: cap batch query * feat: add default limits to all endpoints * chore: rename endpoint funcs * fix: parse rune name spacers * feat(runes): add get token list api * fix(runes): use distinct to get token list * feat: remove unused code * fix: count holders distinct pkscript * feat: implement additional scopes * chore: comments * feat: implement search * refactor: switch to use paginationRequest * refactor: rename get token list to get tokens * fix: count total holders by rune ids * fix: rename file * fix: rename minting to ongoing * fix: get ongoing check rune is mintable * chore: disable gosec g115 * fix: pr --------- Co-authored-by: Gaze <gazenw@users.noreply.github.com>
131 lines
2.8 KiB
Go
131 lines
2.8 KiB
Go
// 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()
|
|
}
|