mirror of
https://github.com/alexgo-io/gaze-indexer.git
synced 2026-04-29 20:25:24 +08:00
fix: change types in db
This commit is contained in:
@@ -2,6 +2,7 @@ BEGIN;
|
||||
|
||||
DROP TABLE IF EXISTS "runes_indexer_stats";
|
||||
DROP TABLE IF EXISTS "runes_indexer_db_version";
|
||||
DROP TABLE IF EXISTS "runes_processor_state";
|
||||
DROP TABLE IF EXISTS "runes_entries";
|
||||
DROP TABLE IF EXISTS "runes_outpoint_balances";
|
||||
DROP TABLE IF EXISTS "runes_balances";
|
||||
|
||||
@@ -13,15 +13,15 @@ CREATE TABLE IF NOT EXISTS "runes_indexer_stats" (
|
||||
CREATE TABLE IF NOT EXISTS "runes_indexer_db_version" (
|
||||
"id" BIGSERIAL PRIMARY KEY,
|
||||
"version" INT NOT NULL,
|
||||
"created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
"created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE
|
||||
);
|
||||
INSERT INTO "runes_indexer_db_version" ("version") VALUES (1);
|
||||
|
||||
-- Runes data
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "runes_processor_state" (
|
||||
"id" SERIAL PRIMARY KEY,
|
||||
"latest_block_height" INT NOT NULL
|
||||
"latest_block_height" INT NOT NULL,
|
||||
"updated_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "runes_entries" (
|
||||
@@ -36,10 +36,10 @@ CREATE TABLE IF NOT EXISTS "runes_entries" (
|
||||
"terms" BOOLEAN NOT NULL, -- if true, then minting term exists for this entry
|
||||
"terms_amount" DECIMAL,
|
||||
"terms_cap" DECIMAL,
|
||||
"terms_height_start" DECIMAL, -- using DECIMAL because it is uint64 but postgres only supports up to int64
|
||||
"terms_height_end" DECIMAL,
|
||||
"terms_offset_start" DECIMAL,
|
||||
"terms_offset_end" DECIMAL,
|
||||
"terms_height_start" INT,
|
||||
"terms_height_end" INT,
|
||||
"terms_offset_start" INT,
|
||||
"terms_offset_end" INT,
|
||||
"completion_time" TIMESTAMP NOT NULL
|
||||
);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS runes_entries_rune_idx ON "runes_entries" USING BTREE ("rune");
|
||||
@@ -49,6 +49,8 @@ CREATE TABLE IF NOT EXISTS "runes_outpoint_balances" (
|
||||
"tx_hash" TEXT NOT NULL,
|
||||
"tx_idx" INT NOT NULL, -- output index
|
||||
"amount" DECIMAL NOT NULL,
|
||||
"block_height" INT NOT NULL, -- block height when this output was created
|
||||
"spent_height" INT, -- block height when this output was spent
|
||||
PRIMARY KEY ("rune_id", "tx_hash", "tx_idx")
|
||||
);
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ func (q *Queries) GetBalancesByRuneId(ctx context.Context, arg GetBalancesByRune
|
||||
}
|
||||
|
||||
const getOutPointBalances = `-- name: GetOutPointBalances :many
|
||||
SELECT rune_id, tx_hash, tx_idx, amount FROM runes_outpoint_balances WHERE tx_hash = $1 AND tx_idx = $2
|
||||
SELECT rune_id, tx_hash, tx_idx, amount, block_height, spent_height FROM runes_outpoint_balances WHERE tx_hash = $1 AND tx_idx = $2
|
||||
`
|
||||
|
||||
type GetOutPointBalancesParams struct {
|
||||
@@ -102,6 +102,8 @@ func (q *Queries) GetOutPointBalances(ctx context.Context, arg GetOutPointBalanc
|
||||
&i.TxHash,
|
||||
&i.TxIdx,
|
||||
&i.Amount,
|
||||
&i.BlockHeight,
|
||||
&i.SpentHeight,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -226,10 +228,10 @@ type SetRuneEntryParams struct {
|
||||
Terms bool
|
||||
TermsAmount pgtype.Numeric
|
||||
TermsCap pgtype.Numeric
|
||||
TermsHeightStart pgtype.Numeric
|
||||
TermsHeightEnd pgtype.Numeric
|
||||
TermsOffsetStart pgtype.Numeric
|
||||
TermsOffsetEnd pgtype.Numeric
|
||||
TermsHeightStart pgtype.Int4
|
||||
TermsHeightEnd pgtype.Int4
|
||||
TermsOffsetStart pgtype.Int4
|
||||
TermsOffsetEnd pgtype.Int4
|
||||
CompletionTime pgtype.Timestamp
|
||||
}
|
||||
|
||||
|
||||
@@ -27,10 +27,10 @@ type RunesEntry struct {
|
||||
Terms bool
|
||||
TermsAmount pgtype.Numeric
|
||||
TermsCap pgtype.Numeric
|
||||
TermsHeightStart pgtype.Numeric
|
||||
TermsHeightEnd pgtype.Numeric
|
||||
TermsOffsetStart pgtype.Numeric
|
||||
TermsOffsetEnd pgtype.Numeric
|
||||
TermsHeightStart pgtype.Int4
|
||||
TermsHeightEnd pgtype.Int4
|
||||
TermsOffsetStart pgtype.Int4
|
||||
TermsOffsetEnd pgtype.Int4
|
||||
CompletionTime pgtype.Timestamp
|
||||
}
|
||||
|
||||
@@ -49,10 +49,12 @@ type RunesIndexerStat struct {
|
||||
}
|
||||
|
||||
type RunesOutpointBalance struct {
|
||||
RuneID string
|
||||
TxHash string
|
||||
TxIdx int32
|
||||
Amount pgtype.Numeric
|
||||
RuneID string
|
||||
TxHash string
|
||||
TxIdx int32
|
||||
Amount pgtype.Numeric
|
||||
BlockHeight int32
|
||||
SpentHeight pgtype.Int4
|
||||
}
|
||||
|
||||
type RunesProcessorState struct {
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/gaze-network/indexer-network/modules/runes/internal/runes"
|
||||
"github.com/gaze-network/uint128"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
func uint128FromNumeric(src pgtype.Numeric) (uint128.Uint128, error) {
|
||||
@@ -81,32 +80,20 @@ func mapRuneEntryModelToType(src gen.RunesEntry) (runes.RuneEntry, error) {
|
||||
terms.Cap = &cap
|
||||
}
|
||||
if src.TermsHeightStart.Valid {
|
||||
heightStart, err := uint128FromNumeric(src.TermsHeightStart)
|
||||
if err != nil {
|
||||
return runes.RuneEntry{}, errors.Wrap(err, "failed to parse terms height start")
|
||||
}
|
||||
terms.HeightStart = lo.ToPtr((heightStart.Uint64()))
|
||||
heightStart := uint64(src.TermsHeightStart.Int32)
|
||||
terms.HeightStart = &heightStart
|
||||
}
|
||||
if src.TermsHeightEnd.Valid {
|
||||
heightEnd, err := uint128FromNumeric(src.TermsHeightEnd)
|
||||
if err != nil {
|
||||
return runes.RuneEntry{}, errors.Wrap(err, "failed to parse terms height end")
|
||||
}
|
||||
terms.HeightEnd = lo.ToPtr((heightEnd.Uint64()))
|
||||
heightEnd := uint64(src.TermsHeightEnd.Int32)
|
||||
terms.HeightEnd = &heightEnd
|
||||
}
|
||||
if src.TermsOffsetStart.Valid {
|
||||
offsetStart, err := uint128FromNumeric(src.TermsOffsetStart)
|
||||
if err != nil {
|
||||
return runes.RuneEntry{}, errors.Wrap(err, "failed to parse terms offset start")
|
||||
}
|
||||
terms.OffsetStart = lo.ToPtr((offsetStart.Uint64()))
|
||||
offsetStart := uint64(src.TermsOffsetStart.Int32)
|
||||
terms.OffsetStart = &offsetStart
|
||||
}
|
||||
if src.TermsOffsetEnd.Valid {
|
||||
offsetEnd, err := uint128FromNumeric(src.TermsOffsetEnd)
|
||||
if err != nil {
|
||||
return runes.RuneEntry{}, errors.Wrap(err, "failed to parse terms offset end")
|
||||
}
|
||||
terms.OffsetEnd = lo.ToPtr((offsetEnd.Uint64()))
|
||||
offsetEnd := uint64(src.TermsOffsetEnd.Int32)
|
||||
terms.OffsetEnd = &offsetEnd
|
||||
}
|
||||
}
|
||||
return runes.RuneEntry{
|
||||
@@ -144,7 +131,8 @@ func mapRuneEntryTypeToParams(src runes.RuneEntry) (gen.SetRuneEntryParams, erro
|
||||
completionTime.Valid = true
|
||||
}
|
||||
var terms bool
|
||||
var termsAmount, termsCap, termsHeightStart, termsHeightEnd, termsOffsetStart, termsOffsetEnd pgtype.Numeric
|
||||
var termsAmount, termsCap pgtype.Numeric
|
||||
var termsHeightStart, termsHeightEnd, termsOffsetStart, termsOffsetEnd pgtype.Int4
|
||||
if src.Terms != nil {
|
||||
terms = true
|
||||
if src.Terms.Amount != nil {
|
||||
@@ -160,27 +148,27 @@ func mapRuneEntryTypeToParams(src runes.RuneEntry) (gen.SetRuneEntryParams, erro
|
||||
}
|
||||
}
|
||||
if src.Terms.HeightStart != nil {
|
||||
termsHeightStart, err = numericFromUint128(lo.ToPtr(uint128.From64(*src.Terms.HeightStart)))
|
||||
if err != nil {
|
||||
return gen.SetRuneEntryParams{}, errors.Wrap(err, "failed to parse terms height start")
|
||||
termsHeightStart = pgtype.Int4{
|
||||
Int32: int32(*src.Terms.HeightStart),
|
||||
Valid: true,
|
||||
}
|
||||
}
|
||||
if src.Terms.HeightEnd != nil {
|
||||
termsHeightEnd, err = numericFromUint128(lo.ToPtr(uint128.From64(*src.Terms.HeightEnd)))
|
||||
if err != nil {
|
||||
return gen.SetRuneEntryParams{}, errors.Wrap(err, "failed to parse terms height end")
|
||||
termsHeightEnd = pgtype.Int4{
|
||||
Int32: int32(*src.Terms.HeightEnd),
|
||||
Valid: true,
|
||||
}
|
||||
}
|
||||
if src.Terms.OffsetStart != nil {
|
||||
termsOffsetStart, err = numericFromUint128(lo.ToPtr(uint128.From64(*src.Terms.OffsetStart)))
|
||||
if err != nil {
|
||||
return gen.SetRuneEntryParams{}, errors.Wrap(err, "failed to parse terms offset start")
|
||||
termsOffsetStart = pgtype.Int4{
|
||||
Int32: int32(*src.Terms.OffsetStart),
|
||||
Valid: true,
|
||||
}
|
||||
}
|
||||
if src.Terms.OffsetEnd != nil {
|
||||
termsOffsetEnd, err = numericFromUint128(lo.ToPtr(uint128.From64(*src.Terms.OffsetEnd)))
|
||||
if err != nil {
|
||||
return gen.SetRuneEntryParams{}, errors.Wrap(err, "failed to parse terms offset end")
|
||||
termsOffsetEnd = pgtype.Int4{
|
||||
Int32: int32(*src.Terms.OffsetEnd),
|
||||
Valid: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user