diff --git a/app/models/bitcoin_transaction.rb b/app/models/bitcoin_transaction.rb index 59b8e6696..6abbd246c 100644 --- a/app/models/bitcoin_transaction.rb +++ b/app/models/bitcoin_transaction.rb @@ -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 diff --git a/app/models/bitcoin_vout.rb b/app/models/bitcoin_vout.rb index f7cea59a6..3671284fe 100644 --- a/app/models/bitcoin_vout.rb +++ b/app/models/bitcoin_vout.rb @@ -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 @@ -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) diff --git a/app/workers/bitcoin_transaction_detect_worker.rb b/app/workers/bitcoin_transaction_detect_worker.rb index 1a5be1689..573ce8ed7 100644 --- a/app/workers/bitcoin_transaction_detect_worker.rb +++ b/app/workers/bitcoin_transaction_detect_worker.rb @@ -9,7 +9,7 @@ def perform(block_id) return unless @block ApplicationRecord.transaction do - build_vins! + # build_vins! build_vouts! end end @@ -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"], @@ -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:, diff --git a/db/migrate/20240311143030_rename_hash_to_tx_hash.rb b/db/migrate/20240311143030_rename_hash_to_tx_hash.rb new file mode 100644 index 000000000..b82edcfd7 --- /dev/null +++ b/db/migrate/20240311143030_rename_hash_to_tx_hash.rb @@ -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 diff --git a/db/structure.sql b/db/structure.sql index 5771e1a6d..2f4218c28 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -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, @@ -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, @@ -5189,6 +5189,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20240228072407'), ('20240228102716'), ('20240301025505'), -('20240305100337'); +('20240305100337'), +('20240311143030');