diff --git a/app/jobs/revert_block_job.rb b/app/jobs/revert_block_job.rb index cfabb33e0..20ade0a4a 100644 --- a/app/jobs/revert_block_job.rb +++ b/app/jobs/revert_block_job.rb @@ -2,12 +2,12 @@ class RevertBlockJob < ApplicationJob def perform(local_tip_block = nil) local_tip_block = case local_tip_block - when nil - Block.recent.first - when Integer - Block.find(local_tip_block) - else - local_tip_block + when nil + Block.recent.first + when Integer + Block.find(local_tip_block) + else + local_tip_block end ApplicationRecord.transaction do @@ -79,7 +79,7 @@ def recalculate_udt_transactions_count(local_tip_block) id: udt_id, ckb_transactions_count: udt.ckb_transactions_count - count, created_at: udt.created_at, - updated_at: Time.current + updated_at: Time.current, } end @@ -101,17 +101,22 @@ def recalculate_udt_accounts(udt_type_hashes, local_tip_block) local_tip_block.contained_addresses.find_each do |address| udt_type_hashes.each do |type_hash| - udt_account = address.udt_accounts.find_by(type_hash: type_hash) + udt_account = address.udt_accounts.find_by(type_hash:) next if udt_account.blank? case udt_account.udt_type when "sudt" - amount = address.cell_outputs.live.udt.where(type_hash: type_hash).sum(:udt_amount) - udt_account.update!(amount: amount) + amount = address.cell_outputs.live.udt.where(type_hash:).sum(:udt_amount) + udt_account.update!(amount:) + when "xudt", "omiga_inscription" + amount = address.cell_outputs.live.where(cell_type: udt_account.udt_type).where(type_hash:).sum(:udt_amount) + udt_account.update!(amount:) when "m_nft_token" udt_account.destroy when "nrc_721_token" udt_account.destroy + when "spore_cell" + udt_account.destroy end end end diff --git a/app/models/concerns/ckb_transactions/bitcoin.rb b/app/models/concerns/ckb_transactions/bitcoin.rb index fd577fbf1..3d9d2708f 100644 --- a/app/models/concerns/ckb_transactions/bitcoin.rb +++ b/app/models/concerns/ckb_transactions/bitcoin.rb @@ -4,10 +4,10 @@ module CkbTransactions module Bitcoin extend ActiveSupport::Concern included do - has_many :bitcoin_vouts - has_many :bitcoin_vins - has_many :bitcoin_transfers - has_one :bitcoin_annotation + has_many :bitcoin_vouts, dependent: :delete_all + has_many :bitcoin_vins, dependent: :delete_all + has_many :bitcoin_transfers, dependent: :delete_all + has_one :bitcoin_annotation, dependent: :delete delegate :leap_direction, to: :bitcoin_annotation, allow_nil: true delegate :transfer_step, to: :bitcoin_annotation, allow_nil: true diff --git a/lib/tasks/migration/comprare_output_with_rpc.rake b/lib/tasks/migration/comprare_output_with_rpc.rake index b76506bf3..3a1a12bb4 100644 --- a/lib/tasks/migration/comprare_output_with_rpc.rake +++ b/lib/tasks/migration/comprare_output_with_rpc.rake @@ -47,7 +47,12 @@ namespace :migration do unless input[:previous_output][:tx_hash] == "0x0000000000000000000000000000000000000000000000000000000000000000" result = CellOutput.where(tx_hash: input[:previous_output][:tx_hash], cell_index: input[:previous_output][:index].to_i(16), status: :dead).exists? unless result - $error_ids << r[:header][:number].to_i(16) + output = CellOutput.find_by(tx_hash: input[:previous_output][:tx_hash], cell_index: input[:previous_output][:index].to_i(16), status: :live) + if output.present? + output.update(status: :dead) + else + $error_ids << r[:header][:number].to_i(16) + end end end end