Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: spore and xudt needs recalculate udt_account when rollback #1917

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions app/jobs/revert_block_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
Loading