feat: add tx index to entity

This commit is contained in:
Gaze
2024-04-14 21:41:44 +07:00
parent 4cfd111437
commit fdb23ccbad
7 changed files with 14 additions and 3 deletions

View File

@@ -60,6 +60,7 @@ CREATE TABLE IF NOT EXISTS "runes_entry_states" (
CREATE TABLE IF NOT EXISTS "runes_transactions" (
"hash" TEXT NOT NULL PRIMARY KEY,
"block_height" INT NOT NULL,
"index" INT NOT NULL,
"timestamp" TIMESTAMP NOT NULL,
"inputs" JSONB NOT NULL,
"outputs" JSONB NOT NULL,

View File

@@ -35,7 +35,7 @@ INSERT INTO runes_entries (rune_id, rune, spacers, premine, symbol, divisibility
INSERT INTO runes_entry_states (rune_id, block_height, mints, burned_amount, completed_at, completed_at_height) VALUES ($1, $2, $3, $4, $5, $6);
-- name: CreateRuneTransaction :exec
INSERT INTO runes_transactions (hash, block_height, timestamp, inputs, outputs, mints, burns) VALUES ($1, $2, $3, $4, $5, $6, $7);
INSERT INTO runes_transactions (hash, block_height, index, timestamp, inputs, outputs, mints, burns) VALUES ($1, $2, $3, $4, $5, $6, $7, $8);
-- name: CreateRunestone :exec
INSERT INTO runes_runestones (tx_hash, block_height, etching, etching_divisibility, etching_premine, etching_rune, etching_spacers, etching_symbol, etching_terms, etching_terms_amount, etching_terms_cap, etching_terms_height_start, etching_terms_height_end, etching_terms_offset_start, etching_terms_offset_end, etching_turbo, edicts, mint, pointer, cenotaph, flaws)

View File

@@ -65,6 +65,7 @@ func (o *OutPointBalance) UnmarshalJSON(data []byte) error {
type RuneTransaction struct {
Hash chainhash.Hash
BlockHeight uint64
Index uint32
Timestamp time.Time
Inputs []*OutPointBalance
Outputs []*OutPointBalance

View File

@@ -104,12 +104,13 @@ func (q *Queries) CreateRuneEntryState(ctx context.Context, arg CreateRuneEntryS
}
const createRuneTransaction = `-- name: CreateRuneTransaction :exec
INSERT INTO runes_transactions (hash, block_height, timestamp, inputs, outputs, mints, burns) VALUES ($1, $2, $3, $4, $5, $6, $7)
INSERT INTO runes_transactions (hash, block_height, index, timestamp, inputs, outputs, mints, burns) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
`
type CreateRuneTransactionParams struct {
Hash string
BlockHeight int32
Index int32
Timestamp pgtype.Timestamp
Inputs []byte
Outputs []byte
@@ -121,6 +122,7 @@ func (q *Queries) CreateRuneTransaction(ctx context.Context, arg CreateRuneTrans
_, err := q.db.Exec(ctx, createRuneTransaction,
arg.Hash,
arg.BlockHeight,
arg.Index,
arg.Timestamp,
arg.Inputs,
arg.Outputs,
@@ -497,7 +499,7 @@ func (q *Queries) GetRuneIdFromRune(ctx context.Context, rune string) (string, e
}
const getRuneTransactionsByHeight = `-- name: GetRuneTransactionsByHeight :many
SELECT hash, runes_transactions.block_height, timestamp, inputs, outputs, mints, burns, tx_hash, runes_runestones.block_height, etching, etching_divisibility, etching_premine, etching_rune, etching_spacers, etching_symbol, etching_terms, etching_terms_amount, etching_terms_cap, etching_terms_height_start, etching_terms_height_end, etching_terms_offset_start, etching_terms_offset_end, etching_turbo, edicts, mint, pointer, cenotaph, flaws FROM runes_transactions
SELECT hash, runes_transactions.block_height, index, timestamp, inputs, outputs, mints, burns, tx_hash, runes_runestones.block_height, etching, etching_divisibility, etching_premine, etching_rune, etching_spacers, etching_symbol, etching_terms, etching_terms_amount, etching_terms_cap, etching_terms_height_start, etching_terms_height_end, etching_terms_offset_start, etching_terms_offset_end, etching_turbo, edicts, mint, pointer, cenotaph, flaws FROM runes_transactions
LEFT JOIN runes_runestones ON runes_transactions.hash = runes_runestones.tx_hash
WHERE runes_transactions.block_height = $1
`
@@ -505,6 +507,7 @@ SELECT hash, runes_transactions.block_height, timestamp, inputs, outputs, mints,
type GetRuneTransactionsByHeightRow struct {
Hash string
BlockHeight int32
Index int32
Timestamp pgtype.Timestamp
Inputs []byte
Outputs []byte
@@ -545,6 +548,7 @@ func (q *Queries) GetRuneTransactionsByHeight(ctx context.Context, blockHeight i
if err := rows.Scan(
&i.Hash,
&i.BlockHeight,
&i.Index,
&i.Timestamp,
&i.Inputs,
&i.Outputs,

View File

@@ -100,6 +100,7 @@ type RunesRunestone struct {
type RunesTransaction struct {
Hash string
BlockHeight int32
Index int32
Timestamp pgtype.Timestamp
Inputs []byte
Outputs []byte

View File

@@ -279,6 +279,7 @@ func mapRuneTransactionTypeToParams(src entity.RuneTransaction) (gen.CreateRuneT
return gen.CreateRuneTransactionParams{
Hash: src.Hash.String(),
BlockHeight: int32(src.BlockHeight),
Index: int32(src.Index),
Timestamp: timestamp,
Inputs: inputsBytes,
Outputs: outputsBytes,
@@ -329,6 +330,7 @@ func extractModelRuneTxAndRunestone(src gen.GetRuneTransactionsByHeightRow) (gen
return gen.RunesTransaction{
Hash: src.Hash,
BlockHeight: src.BlockHeight,
Index: src.Index,
Timestamp: src.Timestamp,
Inputs: src.Inputs,
Outputs: src.Outputs,
@@ -384,6 +386,7 @@ func mapRuneTransactionModelToType(src gen.RunesTransaction) (entity.RuneTransac
return entity.RuneTransaction{
Hash: *hash,
BlockHeight: uint64(src.BlockHeight),
Index: uint32(src.Index),
Timestamp: timestamp,
Inputs: inputs,
Outputs: outputs,

View File

@@ -255,6 +255,7 @@ func (p *Processor) processTx(ctx context.Context, tx *types.Transaction, blockH
runeTx := entity.RuneTransaction{
Hash: tx.TxHash,
BlockHeight: uint64(blockHeader.Height),
Index: tx.Index,
Timestamp: blockHeader.Timestamp,
Inputs: make([]*entity.OutPointBalance, 0),
Outputs: make([]*entity.OutPointBalance, 0),