fix: switch pk to block height

This commit is contained in:
Gaze
2024-04-15 16:19:08 +07:00
parent 5129e0c5f0
commit 7174bb6221
4 changed files with 8 additions and 9 deletions

View File

@@ -20,13 +20,12 @@ CREATE INDEX IF NOT EXISTS runes_indexer_state_created_at_idx ON "runes_indexer_
-- Runes data
CREATE TABLE IF NOT EXISTS "runes_indexed_blocks" (
"hash" TEXT NOT NULL PRIMARY KEY,
"height" INT NOT NULL,
"height" INT NOT NULL PRIMARY KEY,
"hash" TEXT NOT NULL,
"prev_hash" TEXT NOT NULL,
"event_hash" TEXT NOT NULL,
"cumulative_event_hash" TEXT NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS runes_indexed_blocks_height_idx ON "runes_indexed_blocks" USING BTREE ("height" DESC);
CREATE TABLE IF NOT EXISTS "runes_entries" (
"rune_id" TEXT NOT NULL PRIMARY KEY,

View File

@@ -342,15 +342,15 @@ func (q *Queries) GetBalancesByRuneId(ctx context.Context, arg GetBalancesByRune
}
const getIndexedBlockByHeight = `-- name: GetIndexedBlockByHeight :one
SELECT hash, height, prev_hash, event_hash, cumulative_event_hash FROM runes_indexed_blocks WHERE height = $1
SELECT height, hash, prev_hash, event_hash, cumulative_event_hash FROM runes_indexed_blocks WHERE height = $1
`
func (q *Queries) GetIndexedBlockByHeight(ctx context.Context, height int32) (RunesIndexedBlock, error) {
row := q.db.QueryRow(ctx, getIndexedBlockByHeight, height)
var i RunesIndexedBlock
err := row.Scan(
&i.Hash,
&i.Height,
&i.Hash,
&i.PrevHash,
&i.EventHash,
&i.CumulativeEventHash,
@@ -359,15 +359,15 @@ func (q *Queries) GetIndexedBlockByHeight(ctx context.Context, height int32) (Ru
}
const getLatestIndexedBlock = `-- name: GetLatestIndexedBlock :one
SELECT hash, height, prev_hash, event_hash, cumulative_event_hash FROM runes_indexed_blocks ORDER BY height DESC LIMIT 1
SELECT height, hash, prev_hash, event_hash, cumulative_event_hash FROM runes_indexed_blocks ORDER BY height DESC LIMIT 1
`
func (q *Queries) GetLatestIndexedBlock(ctx context.Context) (RunesIndexedBlock, error) {
row := q.db.QueryRow(ctx, getLatestIndexedBlock)
var i RunesIndexedBlock
err := row.Scan(
&i.Hash,
&i.Height,
&i.Hash,
&i.PrevHash,
&i.EventHash,
&i.CumulativeEventHash,

View File

@@ -43,8 +43,8 @@ type RunesEntryState struct {
}
type RunesIndexedBlock struct {
Hash string
Height int32
Hash string
PrevHash string
EventHash string
CumulativeEventHash string

View File

@@ -507,7 +507,7 @@ func mapRunestoneModelToType(src gen.RunesRunestone) (runes.Runestone, error) {
var symbol rune = src.EtchingSymbol.Int32
etching.Symbol = &symbol
}
if src.EtchingTerms.Valid && src.EtchingTerms.Valid {
if src.EtchingTerms.Valid && src.EtchingTerms.Bool {
terms := runes.Terms{}
if src.EtchingTermsAmount.Valid {
amount, err := uint128FromNumeric(src.EtchingTermsAmount)