Skip to content

Commit

Permalink
feat: handle is_repeated_symbol logic in node processor
Browse files Browse the repository at this point in the history
Signed-off-by: Miles Zhang <[email protected]>
  • Loading branch information
zmcNotafraid committed Mar 13, 2024
1 parent 4d89c65 commit 86b4440
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
4 changes: 2 additions & 2 deletions app/controllers/api/v1/address_udt_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def show
raise Api::V1::Exceptions::AddressNotFoundError if address.is_a?(NullAddress)
raise Api::V1::Exceptions::TypeHashInvalidError if params[:type_hash].blank?

udt = Udt.find_by(type_hash: params[:type_hash])
raise Api::V1::Exceptions::UdtNotFoundError if udt.blank? || (udt.udt_type != "omiga_inscription" && !udt.published)
udt = Udt.find_by(type_hash: params[:type_hash], published: true)
raise Api::V1::Exceptions::UdtNotFoundError if udt.blank?

ckb_dao_transactions = address.ckb_udt_transactions(udt.id).
select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at, :created_at).
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v1/udt_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class UdtTransactionsController < ApplicationController
before_action :validate_query_params, :validate_pagination_params, :pagination_params

def show
udt = Udt.find_by(type_hash: params[:id])
raise Api::V1::Exceptions::UdtNotFoundError if udt.blank? || (udt.udt_type != "omiga_inscription" && !udt.published)
udt = Udt.find_by(type_hash: params[:id], published: true)
raise Api::V1::Exceptions::UdtNotFoundError if udt.blank?

ckb_transactions = udt.ckb_transactions.tx_committed.
select(:id, :tx_hash, :block_id, :block_number,
Expand Down
24 changes: 11 additions & 13 deletions app/models/ckb_sync/new_node_data_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -633,24 +633,24 @@ def build_udts!(local_block, outputs, outputs_data)
next unless cell_type.in?(%w(udt m_nft_token nrc_721_token spore_cell
omiga_inscription_info omiga_inscription))

type_hash, parsed_udt_type, published =
type_hash, parsed_udt_type =
if cell_type == "omiga_inscription_info"
info = CkbUtils.parse_omiga_inscription_info(outputs_data[tx_index][index])
info_type_hash = output.type.compute_hash
attrs = info.merge(output.type.to_h, type_hash: info_type_hash)
pre_closed_info = OmigaInscriptionInfo.includes(:udt).find_by(
type_hash: info_type_hash, mint_status: :closed,
)
attrs, published =
if pre_closed_info
[attrs.merge(pre_udt_hash: pre_closed_info.udt_hash), pre_closed_info.udt&.published == true]
else
[attrs, false]
end
attrs = info.merge(output.type.to_h, type_hash: info_type_hash)
if pre_closed_info
attrs[:pre_udt_hash] = pre_closed_info.udt_hash
attrs[:is_repeated_symbol] = pre_closed_info.is_repeated_symbol
else
attrs[:is_repeated_symbol] = OmigaInscriptionInfo.where(symbol: info[:symbol].strip).exists?
end
OmigaInscriptionInfo.upsert(attrs, unique_by: :udt_hash)
[info[:udt_hash], "omiga_inscription", published]
[info[:udt_hash], "omiga_inscription"]
else
[output.type.compute_hash, udt_type(cell_type), false]
[output.type.compute_hash, udt_type(cell_type)]
end

if cell_type == "omiga_inscription"
Expand Down Expand Up @@ -714,9 +714,7 @@ 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]
if published || !Udt.where(symbol: info[:symbol].strip, udt_type: :omiga_inscription).exists?
nft_token_attr[:published] = true
end
nft_token_attr[:published] = true
end
# fill issuer_address after publish the token
udts_attributes << {
Expand Down
6 changes: 6 additions & 0 deletions app/serializers/udt_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@ class UdtSerializer
} do |object|
object.omiga_inscription_info.pre_udt_hash
end

attribute :is_repeated_symbol, if: Proc.new { |record, _params|
record.udt_type == "omiga_inscription"
} do |object|
object.is_repeated_symbol
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class AddressUdtTransactionsControllerTest < ActionDispatch::IntegrationTest
end

test "should return meta if udt is omiga_inscription" do
udt = create(:udt, udt_type: :omiga_inscription, published: false)
udt = create(:udt, udt_type: :omiga_inscription, published: true)
address = create(:address, :with_udt_transactions, transactions_count: 3, udt:)

valid_get api_v1_address_udt_transaction_url(address.address_hash, type_hash: udt.type_hash)
Expand Down
4 changes: 2 additions & 2 deletions test/models/ckb_sync/node_data_processor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4047,7 +4047,7 @@ class NodeDataProcessorTest < ActiveSupport::TestCase
udt = Udt.first
assert_equal "0x5fa66c8d5f43914f85d3083e0529931883a5b0a14282f891201069f1b5067908",
udt.type_hash
assert_equal true, udt.published
assert_equal false, info.is_repeated_symbol
end
end

Expand Down Expand Up @@ -4148,7 +4148,7 @@ class NodeDataProcessorTest < ActiveSupport::TestCase
node_data_processor.process_block(node_block)
assert_equal 2, Udt.count
assert_equal info.udt_hash, OmigaInscriptionInfo.last.pre_udt_hash
assert_equal true, Udt.last.published
assert_equal false, OmigaInscriptionInfo.last.is_repeated_symbol
end
end

Expand Down

0 comments on commit 86b4440

Please sign in to comment.