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

feat: xudt_compatible needs to tag #1940

Merged
merged 5 commits into from
Jun 7, 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
2 changes: 1 addition & 1 deletion app/controllers/api/v1/xudts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def parse_tags
end

def xudt_type_params
params[:type].blank? ? "xudt" : "xudt_compatible"
params[:type].blank? ? ["xudt", "xudt_compatible"] : "xudt_compatible"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/cell_data_comparator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def diff_udt_cells(inputs, outputs)
h[k][:amount] += c.udt_amount.to_f
}

cell_types = %w(udt omiga_inscription xudt)
cell_types = %w(udt omiga_inscription xudt xudt_compatible)
inputs = inputs.where(cell_type: cell_types).each_with_object({}) { |c, h| process_udt.call(c, h) }
outputs = outputs.where(cell_type: cell_types).each_with_object({}) { |c, h| process_udt.call(c, h) }

Expand Down
2 changes: 1 addition & 1 deletion app/models/udt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Udt < ApplicationRecord
scope :query_by_name_or_symbl, ->(search) {
where("lower(full_name) LIKE ? or lower(symbol) LIKE ?", "%#{search}%", "%#{search}%")
}
scope :published_xudt, -> { where(udt_type: :xudt, published: true) }
scope :published_xudt, -> { where(udt_type: %i[xudt xudt_compatible], published: true) }

attribute :code_hash, :ckb_hash

Expand Down
2 changes: 1 addition & 1 deletion app/models/xudt_tag.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class XudtTag < ApplicationRecord
belongs_to :udt

VALID_TAGS = ["invalid", "suspicious", "out-of-length-range", "rgbpp-compatible", "layer-1-asset", "supply-limited", "duplicate", "layer-2-asset", "supply-unlimited"]
VALID_TAGS = ["unnamed", "invalid", "suspicious", "out-of-length-range", "rgbpp-compatible", "layer-1-asset", "supply-limited", "duplicate", "layer-2-asset", "supply-unlimited"]
end

# == Schema Information
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/udt_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class UdtSerializer
end

attribute :xudt_tags, if: Proc.new { |record, _params|
record.udt_type == "xudt" && record.published
record.udt_type.in?(["xudt", "xudt_compatible"]) && record.published
} do |object|
object.xudt_tag&.tags
end
Expand Down
2 changes: 1 addition & 1 deletion app/utils/ckb_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def self.cell_type(type_script, output_data)
CkbSync::Api.instance.issuer_script_code_hash, CkbSync::Api.instance.token_class_script_code_hash,
CkbSync::Api.instance.token_script_code_hash, CkbSync::Api.instance.cota_registry_code_hash,
CkbSync::Api.instance.cota_regular_code_hash, CkbSync::Api.instance.omiga_inscription_info_code_hash,
CkbSync::Api.instance.xudt_code_hash, CkbSync::Api.instance.unique_cell_code_hash
CkbSync::Api.instance.xudt_code_hash, CkbSync::Api.instance.unique_cell_code_hash, CkbSync::Api.instance.xudt_compatible_code_hash
].include?(type_script&.code_hash) && type_script&.hash_type == "type") ||
is_nrc_721_token_cell?(output_data) ||
is_nrc_721_factory_cell?(output_data) ||
Expand Down
2 changes: 1 addition & 1 deletion app/workers/xudt_tag_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def out_of_length?(symbol)
end

def first_xudt?(symbol, block_timestamp)
!Udt.xudt.where("LOWER(symbol) = ?", symbol.downcase).where("block_timestamp < ?", block_timestamp).exists?
!Udt.published_xudt.where("LOWER(symbol) = ?", symbol.downcase).where("block_timestamp < ?", block_timestamp).exists?
end

def rgbpp_lock?(issuer_address)
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/api/v1/xudts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class XudtsControllerTest < ActionDispatch::IntegrationTest

test "should get success code when call xudt_compatible index " do
create(:udt, :xudt_compatible, published: true)
create(:udt, :xudt, published: true)

valid_get api_v1_xudts_url, params: {type: "xudt_compatible"}
valid_get api_v1_xudts_url, params: { type: "xudt_compatible" }

assert_response :success
assert_equal 1, json["data"].length
end


test "filter xudt by symbol and tags" do
udt = create(:udt, :xudt, symbol: "CKBB")
create(:xudt_tag, udt:, tags: ["duplicate", "layer-1-asset", "supply-limited"])
Expand Down
8 changes: 8 additions & 0 deletions test/workers/xudt_tag_worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ class XudtTagWorkerTest < ActiveJob::TestCase
@address = create(:address, address_hash: "ckb1qz7xc452rgxs5z0ks3xun46dmdp58sepg0ljtae8ck0d7nah945nvqgqqqqqqx3l3v4")
end

test "add tag to xudt compatible" do
create(:udt, :xudt_compatible, symbol: nil)
assert_changes -> { XudtTag.count }, from: 0, to: 1 do
XudtTagWorker.new.perform
end
assert_equal ["unnamed"], XudtTag.last.tags
end

test "when xudt with no symbol" do
create(:udt, :xudt, symbol: nil)
assert_changes -> { XudtTag.count }, from: 0, to: 1 do
Expand Down
Loading