diff --git a/app/controllers/api/v2/statistics_controller.rb b/app/controllers/api/v2/statistics_controller.rb index 60e2bfefe..087fa6f3c 100644 --- a/app/controllers/api/v2/statistics_controller.rb +++ b/app/controllers/api/v2/statistics_controller.rb @@ -15,6 +15,10 @@ def transaction_fees def contract_resource_distributed contracts = Contract.filter_nil_hash_type + if params[:code_hashes].present? + hashes = params[:code_hashes].split(",") + contracts = contracts.where(code_hash: hashes) + end if stale?(contracts) expires_in 30.minutes, public: true json = contracts.map do |contract| diff --git a/app/workers/contract_statistic_worker.rb b/app/workers/contract_statistic_worker.rb index e7993ee39..33b40ea9e 100644 --- a/app/workers/contract_statistic_worker.rb +++ b/app/workers/contract_statistic_worker.rb @@ -16,7 +16,7 @@ def perform referring_cells_count: contract.referring_cell_outputs.live.size, total_deployed_cells_capacity: contract.deployed_cell_outputs&.live&.sum(:capacity), total_referring_cells_capacity: contract.referring_cell_outputs.live.sum(:capacity), - # addresses_count: ckb_address_ids.count, + addresses_count: ckb_address_ids.count, ) end diff --git a/test/controllers/api/v2/statistics_controller_test.rb b/test/controllers/api/v2/statistics_controller_test.rb index 67fb636a4..146ed6dfd 100644 --- a/test/controllers/api/v2/statistics_controller_test.rb +++ b/test/controllers/api/v2/statistics_controller_test.rb @@ -97,6 +97,15 @@ class StatisticsControllerTest < ActionDispatch::IntegrationTest assert_equal 3, data.size end + + test "return contracts resource distributed with code_hashes params" do + contracts = create_list(:contract, 3) + + get contract_resource_distributed_api_v2_statistics_url, params: { code_hashes: "#{contracts[0].code_hash},#{contracts[1].code_hash}" } + data = JSON.parse(response.body) + + assert_equal 2, data.size + end end end end