Skip to content

Commit

Permalink
chore: rename bitcoin transaciton column name (#1670)
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz authored Mar 11, 2024
1 parent e543c76 commit 5c56865
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/models/bitcoin_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def ckb_transaction_hash
#
# id :bigint not null, primary key
# txid :binary
# hash :binary
# tx_hash :binary
# time :bigint
# block_hash :binary
# block_height :bigint
Expand Down
4 changes: 2 additions & 2 deletions app/models/bitcoin_vout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class BitcoinVout < ApplicationRecord
def commitment
return unless op_return?

script_pubkey = Bitcoin::Script.parse_from_payload(hex.htb)
script_pubkey = Bitcoin::Script.parse_from_payload(data.htb)
script_pubkey.op_return_data.bth
end
end
Expand All @@ -20,7 +20,7 @@ def commitment
# id :bigint not null, primary key
# bitcoin_transaction_id :bigint
# bitcoin_address_id :bigint
# hex :binary
# data :binary
# index :integer
# asm :text
# op_return :boolean default(FALSE)
Expand Down
10 changes: 5 additions & 5 deletions app/workers/bitcoin_transaction_detect_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def perform(block_id)
return unless @block

ApplicationRecord.transaction do
build_vins!
# build_vins!
build_vouts!
end
end
Expand Down Expand Up @@ -87,7 +87,7 @@ def build_tx!(raw_tx)
block_header = rpc.getblockheader(raw_tx["blockhash"])
BitcoinTransaction.create!(
txid: raw_tx["txid"],
hash: raw_tx["hash"],
tx_hash: raw_tx["hash"],
time: raw_tx["time"],
block_hash: raw_tx["blockhash"],
block_height: block_header["height"],
Expand All @@ -99,15 +99,15 @@ def build_vout_attributes!(raw_tx, tx)
address_hash = v.dig("scriptPubKey", "address")
address = BitcoinAddress.find_or_create_by(address_hash:) if address_hash.present?

hex = v.dig("scriptPubKey", "hex")
script_pubkey = Bitcoin::Script.parse_from_payload(hex.htb)
data = v.dig("scriptPubKey", "hex")
script_pubkey = Bitcoin::Script.parse_from_payload(data.htb)
op_return = script_pubkey.op_return?

{
txid: tx.txid,
bitcoin_transaction_id: tx.id,
bitcoin_address_id: address&.id,
hex:,
data:,
index: v.dig("n"),
asm: v.dig("scriptPubKey", "asm"),
op_return:,
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20240311143030_rename_hash_to_tx_hash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class RenameHashToTxHash < ActiveRecord::Migration[7.0]
def change
rename_column :bitcoin_transactions, :hash, :tx_hash
rename_column :bitcoin_vouts, :hex, :data
end
end
7 changes: 4 additions & 3 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ ALTER SEQUENCE public.bitcoin_addresses_id_seq OWNED BY public.bitcoin_addresses
CREATE TABLE public.bitcoin_transactions (
id bigint NOT NULL,
txid bytea,
hash bytea,
tx_hash bytea,
"time" bigint,
block_hash bytea,
block_height bigint,
Expand Down Expand Up @@ -637,7 +637,7 @@ CREATE TABLE public.bitcoin_vouts (
id bigint NOT NULL,
bitcoin_transaction_id bigint,
bitcoin_address_id bigint,
hex bytea,
data bytea,
index integer,
asm text,
op_return boolean DEFAULT false,
Expand Down Expand Up @@ -5189,6 +5189,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20240228072407'),
('20240228102716'),
('20240301025505'),
('20240305100337');
('20240305100337'),
('20240311143030');


0 comments on commit 5c56865

Please sign in to comment.