From f7b98fa28b9f734ee91e63a94083230d0e878c65 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Mon, 26 Feb 2024 18:41:14 +0800 Subject: [PATCH] feat: only set first unique symbol published true (#1649) Signed-off-by: Miles Zhang --- .../ckb_sync/new_node_data_processor.rb | 6 +++-- .../ckb_sync/node_data_processor_test.rb | 22 ++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/models/ckb_sync/new_node_data_processor.rb b/app/models/ckb_sync/new_node_data_processor.rb index b26f9ea22..f2a7ebc81 100644 --- a/app/models/ckb_sync/new_node_data_processor.rb +++ b/app/models/ckb_sync/new_node_data_processor.rb @@ -683,7 +683,7 @@ def build_udts!(local_block, outputs, outputs_data) if parsed_spore_cell[:cluster_id].present? binary_hashes = CkbUtils.hexes_to_bins_sql(CkbSync::Api.instance.spore_cluster_code_hashes) spore_cluster_type_ids = TypeScript.where("code_hash IN (#{binary_hashes})").where(hash_type: "data1", - args: parsed_spore_cell[:cluster_id]).pluck(:id) + args: parsed_spore_cell[:cluster_id]).pluck(:id) spore_cluster_cell = CellOutput.live.where(type_script_id: spore_cluster_type_ids).last parsed_cluster_data = CkbUtils.parse_spore_cluster_data(spore_cluster_cell.data) @@ -712,7 +712,9 @@ def build_udts!(local_block, outputs, outputs_data) nft_token_attr[:full_name] = info[:name] nft_token_attr[:symbol] = info[:symbol] nft_token_attr[:decimal] = info[:decimal] - nft_token_attr[:published] = true + unless Udt.where(symbol: info[:symbol].strip, udt_type: :omiga_inscription).exists? + nft_token_attr[:published] = true + end end # fill issuer_address after publish the token udts_attributes << { diff --git a/test/models/ckb_sync/node_data_processor_test.rb b/test/models/ckb_sync/node_data_processor_test.rb index 68d49aefc..31b778ae5 100644 --- a/test/models/ckb_sync/node_data_processor_test.rb +++ b/test/models/ckb_sync/node_data_processor_test.rb @@ -1034,15 +1034,15 @@ class NodeDataProcessorTest < ActiveSupport::TestCase Address.find_or_create_address(lock1, node_block.header.timestamp) Address.find_or_create_address(lock2, node_block.header.timestamp) 300.times do |i| - if i % 2 == 0 - node_block.transactions.first.outputs << CKB::Types::Output.new( - capacity: 30000 * 10**8, lock: lock1, - ) - else - node_block.transactions.first.outputs << CKB::Types::Output.new( - capacity: 40000 * 10**8, lock: lock2, - ) - end + node_block.transactions.first.outputs << if i % 2 == 0 + CKB::Types::Output.new( + capacity: 30000 * 10**8, lock: lock1, + ) + else + CKB::Types::Output.new( + capacity: 40000 * 10**8, lock: lock2, + ) + end node_block.transactions.first.outputs_data << "0x" end new_local_block = node_data_processor.process_block(node_block) @@ -4043,8 +4043,10 @@ class NodeDataProcessorTest < ActiveSupport::TestCase assert_equal info.mint_limit, 0.1e12 assert_equal info.mint_status, "minting" assert_equal info.udt_id, Udt.first.id + udt = Udt.first assert_equal "0x5fa66c8d5f43914f85d3083e0529931883a5b0a14282f891201069f1b5067908", - Udt.first.type_hash + udt.type_hash + assert_equal true, udt.published end end