Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Issue 548 4 #1647

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
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
19 changes: 11 additions & 8 deletions app/models/ckb_sync/new_node_data_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class NewNodeDataProcessor
value :reorg_started_at, global: true
attr_accessor :local_tip_block, :pending_raw_block, :ckb_txs, :target_block, :addrs_changes,
:outputs, :inputs, :outputs_data, :udt_address_ids, :contained_address_ids,
:dao_address_ids, :contained_udt_ids, :cell_datas, :enable_cota
:dao_address_ids, :contained_udt_ids, :cell_datas, :enable_cota, :token_transfer_ckb_tx_ids

def initialize(enable_cota = ENV["COTA_AGGREGATOR_URL"].present?)
@enable_cota = enable_cota
Expand Down Expand Up @@ -68,13 +68,14 @@ def process_block(node_block, refresh_balance: true)
@dao_address_ids = dao_address_ids = []
@contained_udt_ids = contained_udt_ids = []
@contained_address_ids = contained_address_ids = []
@token_transfer_ckb_tx_ids = token_transfer_ckb_tx_ids = Set.new

benchmark :process_ckb_txs, node_block, ckb_txs, contained_address_ids,
contained_udt_ids, dao_address_ids, tags, udt_address_ids
addrs_changes = Hash.new { |hash, key| hash[key] = {} }

input_capacities, output_capacities = benchmark :build_cells_and_locks!, local_block, node_block, ckb_txs, inputs, outputs,
tags, udt_address_ids, dao_address_ids, contained_udt_ids, contained_address_ids, addrs_changes
tags, udt_address_ids, dao_address_ids, contained_udt_ids, contained_address_ids, addrs_changes, token_transfer_ckb_tx_ids

# update explorer data
benchmark :update_ckb_txs_rel_and_fee, ckb_txs, tags, input_capacities, output_capacities, udt_address_ids,
Expand All @@ -94,6 +95,7 @@ def process_block(node_block, refresh_balance: true)
generate_statistics_data(local_block)
generate_deployed_cells_and_referring_cells(local_block)
detect_cota_infos(local_block)
invoke_token_transfer_detect_worker(token_transfer_ckb_tx_ids)

local_block.update_counter_for_ckb_node_version
local_block
Expand Down Expand Up @@ -131,6 +133,12 @@ def detect_cota_infos(local_block)
FetchCotaWorker.perform_async(local_block.number) if enable_cota
end

def invoke_token_transfer_detect_worker(token_transfer_ckb_tx_ids)
token_transfer_ckb_tx_ids.each do |tx_id|
TokenTransferDetectWorker.perform_async(tx_id)
end
end

def process_ckb_txs(
node_block, ckb_txs, contained_address_ids, contained_udt_ids, dao_address_ids, tags,
udt_address_ids
Expand Down Expand Up @@ -808,7 +816,7 @@ def update_ckb_txs_rel_and_fee(

def build_cells_and_locks!(
local_block, node_block, ckb_txs, inputs, outputs, tags, udt_address_ids,
dao_address_ids, contained_udt_ids, contained_addr_ids, addrs_changes
dao_address_ids, contained_udt_ids, contained_addr_ids, addrs_changes, token_transfer_ckb_tx_ids
)
cell_outputs_attributes = []
cell_inputs_attributes = []
Expand All @@ -818,7 +826,6 @@ def build_cells_and_locks!(
lock_scripts_attributes, type_scripts_attributes = build_scripts(outputs)
lock_script_ids = []
type_script_ids = []
token_transfer_ckb_tx_ids = Set.new

if lock_scripts_attributes.present?
lock_scripts_attributes.map! do |attr|
Expand Down Expand Up @@ -902,10 +909,6 @@ def build_cells_and_locks!(
unique_by: %i[tx_hash cell_index])
end

token_transfer_ckb_tx_ids.each do |tx_id|
TokenTransferDetectWorker.perform_async(tx_id)
end

ScriptTransaction.create_from_scripts TypeScript.where(id: type_script_ids)
ScriptTransaction.create_from_scripts LockScript.where(id: lock_script_ids)

Expand Down
4 changes: 0 additions & 4 deletions app/workers/token_transfer_detect_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ class TokenTransferDetectWorker

def perform(tx_id)
tx = CkbTransaction.includes(:cell_outputs, cell_inputs: :previous_cell_output).find tx_id
puts "==================#{tx.inspect}"
return unless tx

@lock = Redis::Lock.new("token_transfer_#{tx_id}", expiration: 180, timeout: 30)
Expand All @@ -12,7 +11,6 @@ def perform(tx_id)
source_collections = []

tx.cell_inputs.each do |input|
puts input.cell_type
if input.cell_type.in?(%w(m_nft_token nrc_721_token spore_cell))
cell = input.previous_cell_output
type_script = input.type_script
Expand All @@ -22,9 +20,7 @@ def perform(tx_id)
end

tx.cell_outputs.each do |output|
puts output.cell_type
if output.cell_type.in?(%w(m_nft_token nrc_721_token spore_cell))
puts "========================#{output.id}"
type_script = output.type_script
item = find_or_create_item(output, type_script)
attrs = {
Expand Down
Loading