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 508 8 #1566

Merged
merged 3 commits into from
Jan 15, 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
9 changes: 6 additions & 3 deletions app/controllers/api/v1/omiga_inscriptions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,18 @@ def sort_udts(records)
case sort
when "created_time" then "block_timestamp"
when "transactions" then "h24_ckb_transactions_count"
when "addresses_count" then "addresses_count"
else "id"
else sort
end

if order.nil? || !order.match?(/^(asc|desc)$/i)
order = "asc"
end

records.order("#{sort} #{order}")
if sort == "mint_status"
records.joins(:omiga_inscription_info).order("omiga_inscription_infos.mint_status #{order}")
else
records.order("#{sort} #{order}")
end
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions app/models/ckb_sync/new_node_data_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ def update_udt_info(local_block)
local_block.cell_outputs.udt.select(:id, :type_hash).each do |udt_output|
type_hashes << udt_output.type_hash
end
local_block.cell_outputs.omiga_inscription.select(:id, :type_hash).each do |udt_output|
type_hashes << udt_output.type_hash
end
local_block.ckb_transactions.pluck(:id).each do |tx_id|
CellOutput.where(consumed_by_id: tx_id).udt.select(:id,
:type_hash).each do |udt_output|
Expand Down
4 changes: 3 additions & 1 deletion lib/tasks/migration/update_omiga_inscription_udt.rake
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ namespace :migration do

unless attrs.empty?
UdtAccount.insert_all(attrs)
udt.update(total_amount: results.sum { |_k, v| v })
udt.update(total_amount: results.sum do |_k, v|
v
end, addresses_count: results.length)
end
end

Expand Down
17 changes: 17 additions & 0 deletions test/controllers/api/v1/omiga_inscriptions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ class OmigaInscriptionsControllerTest < ActionDispatch::IntegrationTest

assert_equal 2, json["data"].length
end

test "should sorted by mint_status asc when sort param is mint_status" do
page = 1
page_size = 5
create_list(:udt, 10, :omiga_inscription)
Udt.last.omiga_inscription_info.update(mint_status: :closed)
udts = Udt.omiga_inscription.joins(:omiga_inscription_info).order("mint_status desc").page(page).per(page_size)

valid_get api_v1_omiga_inscriptions_url,
params: { page:, page_size:, sort: "mint_status.desc" }

options = FastJsonapi::PaginationMetaGenerator.new(request:, records: udts, page:,
page_size:).call
response_udts = UdtSerializer.new(udts, options).serialized_json

assert_equal response_udts, response.body
end
end
end
end