From 465a80a0f9933334f5c49c26de3be6d20801ddc0 Mon Sep 17 00:00:00 2001 From: Rabbit Date: Wed, 7 Feb 2024 14:16:34 +0800 Subject: [PATCH] fix: adjust the count of nft cells change --- app/controllers/concerns/cell_data_comparator.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/controllers/concerns/cell_data_comparator.rb b/app/controllers/concerns/cell_data_comparator.rb index 860840d32..b421f136c 100644 --- a/app/controllers/concerns/cell_data_comparator.rb +++ b/app/controllers/concerns/cell_data_comparator.rb @@ -90,14 +90,14 @@ def diff_normal_nft_cells(inputs, outputs) transfers = Hash.new { |h, k| h[k] = Array.new } cell_types = %w(m_nft_token nrc_721_token spore_cell) - process_nft = ->(c, h) { + process_nft = ->(c, h, o) { k = [c.address_id, c.cell_type, c.type_hash] h[k] ||= { capacity: 0.0, count: 0 } h[k][:capacity] += c.capacity - h[k][:count] -= 1 + h[k][:count] += o } - inputs = inputs.where(cell_type: cell_types).each_with_object({}) { |c, h| process_nft.call(c, h) } - outputs = outputs.where(cell_type: cell_types).each_with_object({}) { |c, h| process_nft.call(c, h) } + inputs = inputs.where(cell_type: cell_types).each_with_object({}) { |c, h| process_nft.call(c, h, -1) } + outputs = outputs.where(cell_type: cell_types).each_with_object({}) { |c, h| process_nft.call(c, h, 1) } (inputs.keys | outputs.keys).each do |k| address_id, cell_type, type_hash = k @@ -136,10 +136,10 @@ def cota_info(transaction, address_id) process_transfer = ->(item, count) { collection = item.collection info << CkbUtils.hash_value_to_s({ - collection_name: collection.name, - count:, - token_id: item.token_id, - }) + collection_name: collection.name, + count:, + token_id: item.token_id, + }) } transaction.token_transfers.each do |t|