From 7fd6b5fab251109071ba40a574991990fe953ec6 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Mon, 15 Jan 2024 10:46:01 +0800 Subject: [PATCH 1/3] feat: omiga inscription sort by mint_status Signed-off-by: Miles Zhang --- .../api/v1/omiga_inscriptions_controller.rb | 9 ++++++--- .../v1/omiga_inscriptions_controller_test.rb | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/omiga_inscriptions_controller.rb b/app/controllers/api/v1/omiga_inscriptions_controller.rb index 4658be821..ee81800d9 100644 --- a/app/controllers/api/v1/omiga_inscriptions_controller.rb +++ b/app/controllers/api/v1/omiga_inscriptions_controller.rb @@ -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 diff --git a/test/controllers/api/v1/omiga_inscriptions_controller_test.rb b/test/controllers/api/v1/omiga_inscriptions_controller_test.rb index cc6d87b0b..ba4d752ce 100644 --- a/test/controllers/api/v1/omiga_inscriptions_controller_test.rb +++ b/test/controllers/api/v1/omiga_inscriptions_controller_test.rb @@ -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 From 646e6c6a605e427a9e0cdfcc657ec8c9ad6d8c1a Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Mon, 15 Jan 2024 11:26:10 +0800 Subject: [PATCH 2/3] feat: update addresses_count for omiga_inscription task Signed-off-by: Miles Zhang --- lib/tasks/migration/update_omiga_inscription_udt.rake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/tasks/migration/update_omiga_inscription_udt.rake b/lib/tasks/migration/update_omiga_inscription_udt.rake index 2aa452a0f..80b4284e4 100644 --- a/lib/tasks/migration/update_omiga_inscription_udt.rake +++ b/lib/tasks/migration/update_omiga_inscription_udt.rake @@ -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 From 18466760847c9552db0695293ca6d9725fc85e70 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Mon, 15 Jan 2024 11:32:15 +0800 Subject: [PATCH 3/3] fix: update inscription total_amount in node processor Signed-off-by: Miles Zhang --- app/models/ckb_sync/new_node_data_processor.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/models/ckb_sync/new_node_data_processor.rb b/app/models/ckb_sync/new_node_data_processor.rb index 60edaea99..041c11153 100644 --- a/app/models/ckb_sync/new_node_data_processor.rb +++ b/app/models/ckb_sync/new_node_data_processor.rb @@ -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|