Skip to content

Commit

Permalink
Issue 527 3 (#1675)
Browse files Browse the repository at this point in the history
* feat: add is_repeated_symbol to omiga_inscription_infos

Signed-off-by: Miles Zhang <[email protected]>

* feat: handle is_repeated_symbol logic in node processor

Signed-off-by: Miles Zhang <[email protected]>

---------

Signed-off-by: Miles Zhang <[email protected]>
  • Loading branch information
zmcNotafraid authored Mar 13, 2024
1 parent bc79d09 commit 675a342
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 40 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
33 changes: 17 additions & 16 deletions app/models/omiga_inscription_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ class OmigaInscriptionInfo < ApplicationRecord
#
# Table name: omiga_inscription_infos
#
# id :bigint not null, primary key
# code_hash :binary
# hash_type :string
# args :string
# decimal :decimal(, )
# name :string
# symbol :string
# udt_hash :string
# expected_supply :decimal(, )
# mint_limit :decimal(, )
# mint_status :integer
# udt_id :bigint
# created_at :datetime not null
# updated_at :datetime not null
# type_hash :binary
# pre_udt_hash :binary
# id :bigint not null, primary key
# code_hash :binary
# hash_type :string
# args :string
# decimal :decimal(, )
# name :string
# symbol :string
# udt_hash :string
# expected_supply :decimal(, )
# mint_limit :decimal(, )
# mint_status :integer
# udt_id :bigint
# created_at :datetime not null
# updated_at :datetime not null
# type_hash :binary
# pre_udt_hash :binary
# is_repeated_symbol :boolean default(FALSE)
#
# Indexes
#
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.omiga_inscription_info.is_repeated_symbol
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddIsRepeatedSymbolToOmigaInscriptionInfo < ActiveRecord::Migration[7.0]
def change
add_column :omiga_inscription_infos, :is_repeated_symbol, :boolean, default: false
end
end
6 changes: 4 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,8 @@ CREATE TABLE public.omiga_inscription_infos (
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
type_hash bytea,
pre_udt_hash bytea
pre_udt_hash bytea,
is_repeated_symbol boolean DEFAULT false
);


Expand Down Expand Up @@ -5185,6 +5186,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20240301025505'),
('20240305100337'),
('20240311143030'),
('20240312050057');
('20240312050057'),
('20240313075641');


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/controllers/api/v1/omiga_inscriptions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class OmigaInscriptionsControllerTest < ActionDispatch::IntegrationTest
assert_equal %w(
symbol full_name display_name uan total_amount addresses_count
decimal icon_file h24_ckb_transactions_count created_at description
published type_hash type_script issuer_address mint_status mint_limit expected_supply inscription_info_id udt_type pre_udt_hash info_type_hash operator_website email
published type_hash type_script issuer_address mint_status mint_limit expected_supply inscription_info_id udt_type pre_udt_hash info_type_hash operator_website email is_repeated_symbol
).sort,
response_udt["attributes"].keys.sort
end
Expand All @@ -86,7 +86,7 @@ class OmigaInscriptionsControllerTest < ActionDispatch::IntegrationTest
assert_equal %w(
symbol full_name display_name uan total_amount addresses_count
decimal icon_file h24_ckb_transactions_count created_at description
published type_hash type_script issuer_address mint_status mint_limit expected_supply inscription_info_id udt_type pre_udt_hash info_type_hash operator_website email
published type_hash type_script issuer_address mint_status mint_limit expected_supply inscription_info_id udt_type pre_udt_hash info_type_hash operator_website email is_repeated_symbol
).sort,
response_udt["attributes"].keys.sort
end
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 675a342

Please sign in to comment.