Skip to content

Commit

Permalink
chore: fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz committed Mar 26, 2024
1 parent 838296f commit c6f91a8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
14 changes: 10 additions & 4 deletions app/jobs/import_bitcoin_utxo_job.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions app/models/concerns/ckb_transactions/bitcoin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions app/workers/bitcoin_transaction_detect_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 << {
Expand All @@ -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

0 comments on commit c6f91a8

Please sign in to comment.