diff --git a/app/jobs/import_btc_time_cell_job.rb b/app/jobs/import_btc_time_cell_job.rb index 5025b8875..ffbc49533 100644 --- a/app/jobs/import_btc_time_cell_job.rb +++ b/app/jobs/import_btc_time_cell_job.rb @@ -17,7 +17,7 @@ def perform(cell_id) raw_tx = fetch_raw_transaction(txid) return unless raw_tx - tx = build_transaction!(raw_tx) + tx = build_transaction!(raw_tx, cell_output.ckb_transaction) # build transfer BitcoinTransfer.create_with( bitcoin_transaction_id: tx.id, @@ -29,16 +29,18 @@ def perform(cell_id) end end - def build_transaction!(raw_tx) + def build_transaction!(raw_tx, ckb_tx) tx = BitcoinTransaction.find_by(txid: raw_tx["txid"]) return tx if tx + created_at = Time.at((ckb_tx.block_timestamp / 1000).to_i).in_time_zone BitcoinTransaction.create!( txid: raw_tx["txid"], tx_hash: raw_tx["hash"], time: raw_tx["time"], block_hash: raw_tx["blockhash"], block_height: 0, + created_at:, ) end diff --git a/app/jobs/import_rgbpp_cell_job.rb b/app/jobs/import_rgbpp_cell_job.rb index 386ce29d6..9cfcb99c5 100644 --- a/app/jobs/import_rgbpp_cell_job.rb +++ b/app/jobs/import_rgbpp_cell_job.rb @@ -19,7 +19,7 @@ def perform(cell_id) raw_tx = fetch_raw_transaction(txid) return unless raw_tx - tx = build_transaction!(raw_tx) + tx = build_transaction!(raw_tx, cell_output.ckb_transaction) # build op_returns vout_attributes = [] op_returns = build_op_returns!(raw_tx, tx, cell_output.ckb_transaction) @@ -47,7 +47,7 @@ def perform(cell_id) Rails.logger.error(e.message) end - def build_transaction!(raw_tx) + def build_transaction!(raw_tx, ckb_tx) tx = BitcoinTransaction.find_by(txid: raw_tx["txid"]) return tx if tx @@ -55,12 +55,15 @@ def build_transaction!(raw_tx) if raw_tx["blockhash"].present? block_header = rpc.getblockheader(raw_tx["blockhash"]) end + + created_at = Time.at((ckb_tx.block_timestamp / 1000).to_i).in_time_zone BitcoinTransaction.create!( txid: raw_tx["txid"], tx_hash: raw_tx["hash"], time: raw_tx["time"], block_hash: raw_tx["blockhash"], block_height: block_header&.dig("result", "height") || 0, + created_at:, ) end @@ -136,7 +139,8 @@ def build_vin!(cell_id, tx) end def build_address!(address_hash, cell_output) - bitcoin_address = BitcoinAddress.find_or_create_by!(address_hash:) + created_at = Time.at((cell_output.block_timestamp / 1000).to_i).in_time_zone + bitcoin_address = BitcoinAddress.create_with(created_at:).find_or_create_by!(address_hash:) BitcoinAddressMapping. create_with(bitcoin_address_id: bitcoin_address.id). find_or_create_by!(ckb_address_id: cell_output.address_id) diff --git a/app/workers/bitcoin_transaction_detect_worker.rb b/app/workers/bitcoin_transaction_detect_worker.rb index 768f7a952..b4f861a9c 100644 --- a/app/workers/bitcoin_transaction_detect_worker.rb +++ b/app/workers/bitcoin_transaction_detect_worker.rb @@ -92,11 +92,12 @@ def build_bitcoin_annotations! annotations = [] @block.ckb_transactions.each do |transaction| - next unless BitcoinTransfer.exists?(ckb_transaction_id: transaction.id) - leap_direction, transfer_step = annotation_workflow_attributes(transaction) tags = annotation_tags(transaction) - annotations << { ckb_transaction_id: transaction.id, leap_direction:, transfer_step:, tags: } + + if tags.present? + annotations << { ckb_transaction_id: transaction.id, leap_direction:, transfer_step:, tags: } + end end BitcoinAnnotation.upsert_all(annotations, unique_by: [:ckb_transaction_id]) if annotations.present?