mirror of
https://github.com/alexgo-io/gaze-indexer.git
synced 2026-04-30 04:35:13 +08:00
feat: add etching tx hash to rune entries
This commit is contained in:
@@ -42,7 +42,8 @@ CREATE TABLE IF NOT EXISTS "runes_entries" (
|
||||
"terms_offset_start" INT,
|
||||
"terms_offset_end" INT,
|
||||
"turbo" BOOLEAN NOT NULL,
|
||||
"etching_block" INT NOT NULL
|
||||
"etching_block" INT NOT NULL,
|
||||
"etching_tx_hash" TEXT NOT NULL
|
||||
);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS runes_entries_rune_idx ON "runes_entries" USING BTREE ("rune");
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ SELECT * FROM runes_transactions
|
||||
WHERE runes_transactions.block_height = $1;
|
||||
|
||||
-- name: CreateRuneEntry :exec
|
||||
INSERT INTO runes_entries (rune_id, rune, spacers, premine, symbol, divisibility, terms, terms_amount, terms_cap, terms_height_start, terms_height_end, terms_offset_start, terms_offset_end, turbo, etching_block)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15);
|
||||
INSERT INTO runes_entries (rune_id, rune, 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)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16);
|
||||
|
||||
-- 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);
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/gaze-network/uint128"
|
||||
)
|
||||
@@ -25,6 +26,8 @@ type RuneEntry struct {
|
||||
CompletedAt time.Time
|
||||
// CompletedAtHeight is the block height when the rune was fully minted.
|
||||
CompletedAtHeight *uint64
|
||||
EtchingBlock uint64
|
||||
EtchingTxHash chainhash.Hash
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
@@ -203,7 +203,7 @@ func (p *Processor) processTx(ctx context.Context, tx *types.Transaction, blockH
|
||||
}
|
||||
|
||||
if etching != nil {
|
||||
if err := p.createRuneEntry(ctx, runestone, etchedRuneId, etchedRune, uint64(tx.BlockHeight)); err != nil {
|
||||
if err := p.createRuneEntry(ctx, runestone, etchedRuneId, etchedRune, tx); err != nil {
|
||||
return errors.Wrap(err, "failed to create rune entry")
|
||||
}
|
||||
}
|
||||
@@ -543,7 +543,7 @@ func removeAnnexFromWitness(witness [][]byte) [][]byte {
|
||||
return witness
|
||||
}
|
||||
|
||||
func (p *Processor) createRuneEntry(ctx context.Context, runestone *runes.Runestone, runeId runes.RuneId, rune runes.Rune, blockHeight uint64) error {
|
||||
func (p *Processor) createRuneEntry(ctx context.Context, runestone *runes.Runestone, runeId runes.RuneId, rune runes.Rune, tx *types.Transaction) error {
|
||||
var runeEntry *runes.RuneEntry
|
||||
if runestone.Cenotaph {
|
||||
runeEntry = &runes.RuneEntry{
|
||||
@@ -558,6 +558,8 @@ func (p *Processor) createRuneEntry(ctx context.Context, runestone *runes.Runest
|
||||
Turbo: false,
|
||||
CompletedAt: time.Time{},
|
||||
CompletedAtHeight: nil,
|
||||
EtchingBlock: uint64(tx.BlockHeight),
|
||||
EtchingTxHash: tx.TxHash,
|
||||
}
|
||||
} else {
|
||||
etching := runestone.Etching
|
||||
@@ -573,9 +575,11 @@ func (p *Processor) createRuneEntry(ctx context.Context, runestone *runes.Runest
|
||||
Turbo: etching.Turbo,
|
||||
CompletedAt: time.Time{},
|
||||
CompletedAtHeight: nil,
|
||||
EtchingBlock: uint64(tx.BlockHeight),
|
||||
EtchingTxHash: tx.TxHash,
|
||||
}
|
||||
}
|
||||
if err := p.runesDg.CreateRuneEntry(ctx, runeEntry, blockHeight); err != nil {
|
||||
if err := p.runesDg.CreateRuneEntry(ctx, runeEntry, uint64(tx.BlockHeight)); err != nil {
|
||||
return errors.Wrap(err, "failed to create rune entry")
|
||||
}
|
||||
logger.DebugContext(ctx, "[RunesProcessor] created RuneEntry", slogx.Any("runeEntry", runeEntry))
|
||||
|
||||
@@ -35,8 +35,8 @@ func (q *Queries) CreateIndexedBlock(ctx context.Context, arg CreateIndexedBlock
|
||||
}
|
||||
|
||||
const createRuneEntry = `-- name: CreateRuneEntry :exec
|
||||
INSERT INTO runes_entries (rune_id, rune, spacers, premine, symbol, divisibility, terms, terms_amount, terms_cap, terms_height_start, terms_height_end, terms_offset_start, terms_offset_end, turbo, etching_block)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)
|
||||
INSERT INTO runes_entries (rune_id, rune, 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)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)
|
||||
`
|
||||
|
||||
type CreateRuneEntryParams struct {
|
||||
@@ -55,6 +55,7 @@ type CreateRuneEntryParams struct {
|
||||
TermsOffsetEnd pgtype.Int4
|
||||
Turbo bool
|
||||
EtchingBlock int32
|
||||
EtchingTxHash string
|
||||
}
|
||||
|
||||
func (q *Queries) CreateRuneEntry(ctx context.Context, arg CreateRuneEntryParams) error {
|
||||
@@ -74,6 +75,7 @@ func (q *Queries) CreateRuneEntry(ctx context.Context, arg CreateRuneEntryParams
|
||||
arg.TermsOffsetEnd,
|
||||
arg.Turbo,
|
||||
arg.EtchingBlock,
|
||||
arg.EtchingTxHash,
|
||||
)
|
||||
return err
|
||||
}
|
||||
@@ -416,7 +418,7 @@ WITH states AS (
|
||||
-- select latest state
|
||||
SELECT DISTINCT ON (rune_id) rune_id, block_height, mints, burned_amount, completed_at, completed_at_height FROM runes_entry_states WHERE rune_id = ANY($1::text[]) ORDER BY rune_id, block_height DESC
|
||||
)
|
||||
SELECT runes_entries.rune_id, rune, spacers, premine, symbol, divisibility, terms, terms_amount, terms_cap, terms_height_start, terms_height_end, terms_offset_start, terms_offset_end, turbo, etching_block, states.rune_id, block_height, mints, burned_amount, completed_at, completed_at_height FROM runes_entries
|
||||
SELECT runes_entries.rune_id, rune, 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, states.rune_id, block_height, mints, burned_amount, completed_at, completed_at_height FROM runes_entries
|
||||
LEFT JOIN states ON runes_entries.rune_id = states.rune_id
|
||||
WHERE rune_id = ANY($1::text[])
|
||||
`
|
||||
@@ -437,6 +439,7 @@ type GetRuneEntriesByRuneIdsRow struct {
|
||||
TermsOffsetEnd pgtype.Int4
|
||||
Turbo bool
|
||||
EtchingBlock int32
|
||||
EtchingTxHash string
|
||||
RuneID_2 pgtype.Text
|
||||
BlockHeight pgtype.Int4
|
||||
Mints pgtype.Numeric
|
||||
@@ -470,6 +473,7 @@ func (q *Queries) GetRuneEntriesByRuneIds(ctx context.Context, runeIds []string)
|
||||
&i.TermsOffsetEnd,
|
||||
&i.Turbo,
|
||||
&i.EtchingBlock,
|
||||
&i.EtchingTxHash,
|
||||
&i.RuneID_2,
|
||||
&i.BlockHeight,
|
||||
&i.Mints,
|
||||
|
||||
@@ -31,6 +31,7 @@ type RunesEntry struct {
|
||||
TermsOffsetEnd pgtype.Int4
|
||||
Turbo bool
|
||||
EtchingBlock int32
|
||||
EtchingTxHash string
|
||||
}
|
||||
|
||||
type RunesEntryState struct {
|
||||
|
||||
@@ -125,6 +125,10 @@ func mapRuneEntryModelToType(src gen.GetRuneEntriesByRuneIdsRow) (runes.RuneEntr
|
||||
terms.OffsetEnd = &offsetEnd
|
||||
}
|
||||
}
|
||||
etchingTxHash, err := chainhash.NewHashFromStr(src.EtchingTxHash)
|
||||
if err != nil {
|
||||
return runes.RuneEntry{}, errors.Wrap(err, "failed to parse etching tx hash")
|
||||
}
|
||||
return runes.RuneEntry{
|
||||
RuneId: runeId,
|
||||
Divisibility: uint8(src.Divisibility),
|
||||
@@ -137,6 +141,8 @@ func mapRuneEntryModelToType(src gen.GetRuneEntriesByRuneIdsRow) (runes.RuneEntr
|
||||
BurnedAmount: lo.FromPtr(burnedAmount),
|
||||
CompletedAt: completedAt,
|
||||
CompletedAtHeight: completedAtHeight,
|
||||
EtchingBlock: uint64(src.EtchingBlock),
|
||||
EtchingTxHash: *etchingTxHash,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -224,7 +230,8 @@ func mapRuneEntryTypeToParams(src runes.RuneEntry, blockHeight uint64) (gen.Crea
|
||||
TermsOffsetStart: termsOffsetStart,
|
||||
TermsOffsetEnd: termsOffsetEnd,
|
||||
Turbo: src.Turbo,
|
||||
EtchingBlock: int32(blockHeight),
|
||||
EtchingBlock: int32(src.EtchingBlock),
|
||||
EtchingTxHash: src.EtchingTxHash.String(),
|
||||
}, gen.CreateRuneEntryStateParams{
|
||||
BlockHeight: int32(blockHeight),
|
||||
RuneID: runeId,
|
||||
|
||||
Reference in New Issue
Block a user