From 08e8f07e40c5d691e8a071d13270aef0f81e035e Mon Sep 17 00:00:00 2001 From: Rabbit Date: Fri, 15 Nov 2024 14:16:11 +0800 Subject: [PATCH] chore: add holder field to udt serialization --- app/models/udt.rb | 4 ++++ app/serializers/udt_serializer.rb | 5 ++++- .../controllers/api/v1/omiga_inscriptions_controller_test.rb | 4 ++-- test/controllers/api/v1/udts_controller_test.rb | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/models/udt.rb b/app/models/udt.rb index 5f10557e0..136a932e6 100644 --- a/app/models/udt.rb +++ b/app/models/udt.rb @@ -42,6 +42,10 @@ def type_script hash_type:, } end + + def holders_count + udt_holder_allocations.sum("ckb_holder_count + btc_holder_count") + end end # == Schema Information diff --git a/app/serializers/udt_serializer.rb b/app/serializers/udt_serializer.rb index 49ee340d0..a7002489d 100644 --- a/app/serializers/udt_serializer.rb +++ b/app/serializers/udt_serializer.rb @@ -22,9 +22,12 @@ class UdtSerializer attribute :h24_ckb_transactions_count do |object| object.h24_ckb_transactions_count.to_s end - attributes :created_at do |object| + attribute :created_at do |object| object.block_timestamp.to_s end + attribute :holders_count do |object| + object.holders_count.to_s + end attribute :mint_status, if: Proc.new { |record, _params| record.udt_type == "omiga_inscription" diff --git a/test/controllers/api/v1/omiga_inscriptions_controller_test.rb b/test/controllers/api/v1/omiga_inscriptions_controller_test.rb index dde4b207e..e491e50ec 100644 --- a/test/controllers/api/v1/omiga_inscriptions_controller_test.rb +++ b/test/controllers/api/v1/omiga_inscriptions_controller_test.rb @@ -72,7 +72,7 @@ class OmigaInscriptionsControllerTest < ActionDispatch::IntegrationTest assert_equal %w( symbol full_name 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 + published type_hash type_script issuer_address mint_status mint_limit expected_supply holders_count inscription_info_id udt_type pre_udt_hash info_type_hash operator_website email is_repeated_symbol ).sort, response_udt["attributes"].keys.sort @@ -86,7 +86,7 @@ class OmigaInscriptionsControllerTest < ActionDispatch::IntegrationTest response_udt = json["data"] assert_equal %w( symbol full_name total_amount addresses_count - decimal icon_file h24_ckb_transactions_count created_at description + decimal icon_file h24_ckb_transactions_count created_at description holders_count 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, diff --git a/test/controllers/api/v1/udts_controller_test.rb b/test/controllers/api/v1/udts_controller_test.rb index bd742fa68..6ef993925 100644 --- a/test/controllers/api/v1/udts_controller_test.rb +++ b/test/controllers/api/v1/udts_controller_test.rb @@ -120,7 +120,7 @@ class UdtsControllerTest < ActionDispatch::IntegrationTest response_tx_transaction = json["data"] assert_equal %w( - symbol full_name total_amount addresses_count + symbol full_name total_amount addresses_count holders_count decimal icon_file h24_ckb_transactions_count created_at description published type_hash type_script issuer_address udt_type operator_website email ).sort,