feat(btc): upgrade data type for idx

Co-authored-by: Gaze <dev@gaze.network>
This commit is contained in:
Gaze
2024-04-17 22:01:03 +07:00
parent ba3333ff9d
commit 5bee86e996
4 changed files with 16 additions and 16 deletions

View File

@@ -37,7 +37,7 @@ CREATE TABLE IF NOT EXISTS "bitcoin_transactions" (
"locktime" BIGINT NOT NULL,
"block_height" INT NOT NULL,
"block_hash" TEXT NOT NULL,
"idx" SMALLINT NOT NULL
"idx" INT NOT NULL
);
CREATE INDEX IF NOT EXISTS bitcoin_transactions_block_height_idx ON "bitcoin_transactions" USING BTREE ("block_height");
@@ -45,7 +45,7 @@ CREATE INDEX IF NOT EXISTS bitcoin_transactions_block_hash_idx ON "bitcoin_trans
CREATE TABLE IF NOT EXISTS "bitcoin_transaction_txouts" (
"tx_hash" TEXT NOT NULL,
"tx_idx" SMALLINT NOT NULL,
"tx_idx" INT NOT NULL,
"pkscript" TEXT NOT NULL, -- Hex String
"value" BIGINT NOT NULL,
"is_spent" BOOLEAN NOT NULL DEFAULT false,
@@ -56,9 +56,9 @@ CREATE INDEX IF NOT EXISTS bitcoin_transaction_txouts_pkscript_idx ON "bitcoin_t
CREATE TABLE IF NOT EXISTS "bitcoin_transaction_txins" (
"tx_hash" TEXT NOT NULL,
"tx_idx" SMALLINT NOT NULL,
"tx_idx" INT NOT NULL,
"prevout_tx_hash" TEXT NOT NULL,
"prevout_tx_idx" SMALLINT NOT NULL,
"prevout_tx_idx" INT NOT NULL,
"prevout_pkscript" TEXT NULL, -- Hex String, Can be NULL if the prevout is a coinbase transaction
"scriptsig" TEXT NOT NULL, -- Hex String
"witness" TEXT, -- Hex String

View File

@@ -245,7 +245,7 @@ type InsertTransactionParams struct {
Locktime int64
BlockHeight int32
BlockHash string
Idx int16
Idx int32
}
func (q *Queries) InsertTransaction(ctx context.Context, arg InsertTransactionParams) error {
@@ -273,9 +273,9 @@ VALUES ($1, $2, $3, $4, (SELECT "pkscript" FROM update_txout), $5, $6, $7)
type InsertTransactionTxInParams struct {
TxHash string
TxIdx int16
TxIdx int32
PrevoutTxHash string
PrevoutTxIdx int16
PrevoutTxIdx int32
Scriptsig string
Witness pgtype.Text
Sequence int64
@@ -300,7 +300,7 @@ INSERT INTO bitcoin_transaction_txouts ("tx_hash","tx_idx","pkscript","value") V
type InsertTransactionTxOutParams struct {
TxHash string
TxIdx int16
TxIdx int32
Pkscript string
Value int64
}

View File

@@ -38,14 +38,14 @@ type BitcoinTransaction struct {
Locktime int64
BlockHeight int32
BlockHash string
Idx int16
Idx int32
}
type BitcoinTransactionTxin struct {
TxHash string
TxIdx int16
TxIdx int32
PrevoutTxHash string
PrevoutTxIdx int16
PrevoutTxIdx int32
PrevoutPkscript pgtype.Text
Scriptsig string
Witness pgtype.Text
@@ -54,7 +54,7 @@ type BitcoinTransactionTxin struct {
type BitcoinTransactionTxout struct {
TxHash string
TxIdx int16
TxIdx int32
Pkscript string
Value int64
IsSpent bool

View File

@@ -79,7 +79,7 @@ func mapBlockTypeToParams(src *types.Block) (gen.InsertBlockParams, []gen.Insert
Locktime: int64(srcTx.LockTime),
BlockHeight: int32(src.Header.Height),
BlockHash: src.Header.Hash.String(),
Idx: int16(txIdx),
Idx: int32(txIdx),
}
txs = append(txs, tx)
@@ -93,9 +93,9 @@ func mapBlockTypeToParams(src *types.Block) (gen.InsertBlockParams, []gen.Insert
}
txins = append(txins, gen.InsertTransactionTxInParams{
TxHash: tx.TxHash,
TxIdx: int16(idx),
TxIdx: int32(idx),
PrevoutTxHash: txin.PreviousOutTxHash.String(),
PrevoutTxIdx: int16(txin.PreviousOutIndex),
PrevoutTxIdx: int32(txin.PreviousOutIndex),
Scriptsig: hex.EncodeToString(txin.SignatureScript),
Witness: witness,
Sequence: int64(txin.Sequence),
@@ -105,7 +105,7 @@ func mapBlockTypeToParams(src *types.Block) (gen.InsertBlockParams, []gen.Insert
for idx, txout := range srcTx.TxOut {
txouts = append(txouts, gen.InsertTransactionTxOutParams{
TxHash: tx.TxHash,
TxIdx: int16(idx),
TxIdx: int32(idx),
Pkscript: hex.EncodeToString(txout.PkScript),
Value: txout.Value,
})