Skip to content

Commit

Permalink
Issue 508 8 (#1566)
Browse files Browse the repository at this point in the history
* feat: omiga inscription sort by mint_status

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

* feat: update addresses_count for omiga_inscription task

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

* fix: update inscription total_amount in node processor

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

---------

Signed-off-by: Miles Zhang <[email protected]>
  • Loading branch information
zmcNotafraid authored Jan 15, 2024
1 parent 1d4d524 commit eecb50f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
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

0 comments on commit eecb50f

Please sign in to comment.