From c6f91a813fdcf79d6eac4d7e0d8ee6ee9ad806f0 Mon Sep 17 00:00:00 2001 From: Rabbit Date: Tue, 26 Mar 2024 14:24:08 +0800 Subject: [PATCH] chore: fix typo --- app/jobs/import_bitcoin_utxo_job.rb | 14 +++++++++---- .../concerns/ckb_transactions/bitcoin.rb | 8 ++++---- .../bitcoin_transaction_detect_worker.rb | 20 +++++++++---------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/app/jobs/import_bitcoin_utxo_job.rb b/app/jobs/import_bitcoin_utxo_job.rb index 595daedf2..301983273 100644 --- a/app/jobs/import_bitcoin_utxo_job.rb +++ b/app/jobs/import_bitcoin_utxo_job.rb @@ -1,18 +1,24 @@ class ImportBitcoinUtxoJob < ApplicationJob queue_as :bitcoin - def perform(txid, out_index, cell_id) + def perform(cell_id) ApplicationRecord.transaction do cell_output = CellOutput.find_by(id: cell_id) unless cell_output - raise ArgumentError, "Missing cell_output(#{cell_id}), txid(#{txid}), out_index(#{out_index})" + raise ArgumentError, "Missing cell_output(#{cell_id})" end + lock_script = cell_output.lock_script + return unless CkbUtils.is_rgbpp_lock_cell?(lock_script) + + txid, out_index = CkbUtils.parse_rgbpp_args(lock_script.args) + Rails.logger.info("Importing bitcoin utxo #{txid} out_index #{out_index}") + vout_attributes = [] # build bitcoin transaction raw_tx = fetch_raw_transaction(txid) - tx = build_tranaction!(raw_tx) + tx = build_transaction!(raw_tx) # build op_returns op_returns = build_op_returns!(raw_tx, tx, cell_output.ckb_transaction, vout_attributes) @@ -25,7 +31,7 @@ def perform(txid, out_index, cell_id) end end - def build_tranaction!(raw_tx) + def build_transaction!(raw_tx) tx = BitcoinTransaction.find_by(txid: raw_tx["txid"]) return tx if tx diff --git a/app/models/concerns/ckb_transactions/bitcoin.rb b/app/models/concerns/ckb_transactions/bitcoin.rb index 380f59a2a..7895dafda 100644 --- a/app/models/concerns/ckb_transactions/bitcoin.rb +++ b/app/models/concerns/ckb_transactions/bitcoin.rb @@ -15,15 +15,15 @@ def rgb_commitment return unless rgb_transaction? # In the outputs, there is exactly one OP_RETURN containing a commitment. - op_return_vout = bitcoin_vouts.find_by(op_return: true) - op_return_vout&.commitment + op_return = bitcoin_vouts.find_by(op_return: true) + op_return&.commitment end def rgb_txid return unless rgb_transaction? - op_return_vout = bitcoin_vouts.find_by(op_return: true) - op_return_vout&.bitcoin_transaction&.txid + bitcoin_transaction = BitcoinTransaction.includes(:bitcoin_vouts).find_by(bitcoin_vouts: { ckb_transaction_id: id }) + bitcoin_transaction&.txid end end end diff --git a/app/workers/bitcoin_transaction_detect_worker.rb b/app/workers/bitcoin_transaction_detect_worker.rb index cd58abd29..8d848dabf 100644 --- a/app/workers/bitcoin_transaction_detect_worker.rb +++ b/app/workers/bitcoin_transaction_detect_worker.rb @@ -3,11 +3,11 @@ class BitcoinUtxoDetectWorker sidekiq_options queue: "bitcoin" def perform(block_id) - @block = Block.find_by(id: block_id) - return unless @block + block = Block.find_by(id: block_id) + return unless block ApplicationRecord.transaction do - @block.ckb_transactions.each do |transaction| + block.ckb_transactions.each do |transaction| vin_attributes = [] # import cell_inputs utxo @@ -16,10 +16,10 @@ def perform(block_id) next unless previous_cell_output lock_script = previous_cell_output.lock_script - next unless CkbUtils2.is_rgbpp_lock_cell?(lock_script) + next unless CkbUtils.is_rgbpp_lock_cell?(lock_script) # import previous bitcoin transaction if prev vout is missing - import_utxo!(lock_script.args, previous_cell_output.id, transaction.id) + import_utxo!(lock_script.args, previous_cell_output.id) previous_vout = BitcoinVout.find_by(cell_output_id: previous_cell_output.id) vin_attributes << { @@ -36,22 +36,22 @@ def perform(block_id) # import cell_outputs utxo transaction.cell_outputs.each do |cell| lock_script = cell.lock_script - next unless CkbUtils2.is_rgbpp_lock_cell?(lock_script) + next unless CkbUtils.is_rgbpp_lock_cell?(lock_script) - import_utxo!(lock_script.args, cell.id, transaction.id) + import_utxo!(lock_script.args, cell.id) end end end end - def import_utxo!(args, cell_id, _tx_id) - txid, out_index = CkbUtils2.parse_rgbpp_args(args) + def import_utxo!(args, cell_id) + txid, out_index = CkbUtils.parse_rgbpp_args(args) unless BitcoinTransaction.includes(:bitcoin_vouts).where( bitcoin_transactions: { txid: }, bitcoin_vouts: { index: out_index, cell_output_id: cell_id }, ).exists? - ImportBitcoinUtxoJob.perform_now(txid, out_index, cell_id) + ImportBitcoinUtxoJob.perform_now(cell_id) end end end