Skip to content

Commit 6e3023c

Browse files
authored
Merge pull request #2403 from nervosnetwork/testnet
Deploy to mainnet
2 parents 7c4459b + 004298c commit 6e3023c

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

app/controllers/api/v2/rgbpp_assets_statistics_controller.rb renamed to app/controllers/api/v2/rgb_assets_statistics_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Api
22
module V2
3-
class RgbppAssetsStatisticsController < BaseController
3+
class RgbAssetsStatisticsController < BaseController
44
def index
55
expires_in 15.minutes, public: true, stale_while_revalidate: 5.minutes, stale_if_error: 5.minutes
66

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module Api
2+
module V2
3+
class RgbTopHoldersController < BaseController
4+
def show
5+
expires_in 15.minutes, public: true, stale_while_revalidate: 5.minutes, stale_if_error: 5.minutes
6+
7+
udt = Udt.find_by(udt_type: %i[xudt xudt_compatible], type_hash: params[:id])
8+
return head :not_found unless udt
9+
10+
merged_array = btc_top_holders(udt) + ckb_top_holders(udt)
11+
top10 = merged_array.sort_by { |item| -item[:amount].to_f }.take(10)
12+
13+
render json: { data: top10 }
14+
end
15+
16+
private
17+
18+
def btc_top_holders(udt)
19+
result = BitcoinAddressMapping.
20+
joins("LEFT OUTER JOIN udt_accounts ON udt_accounts.address_id = bitcoin_address_mappings.ckb_address_id").
21+
where(udt_accounts: { udt_id: udt.id }).where("udt_accounts.amount > 0").
22+
group("bitcoin_address_mappings.bitcoin_address_id").
23+
select("bitcoin_address_mappings.bitcoin_address_id, SUM(udt_accounts.amount) AS total_amount").
24+
order("total_amount DESC").limit(10)
25+
26+
result.map do |record|
27+
address_hash = BitcoinAddress.find_by(id: record.bitcoin_address_id).address_hash
28+
position_ratio = udt.total_amount.zero? ? 0 : format("%.5f", record.total_amount.to_f / udt.total_amount)
29+
{ address_hash:, amount: record.total_amount.to_s, position_ratio: position_ratio.to_s, network: "btc" }
30+
end
31+
end
32+
33+
def ckb_top_holders(udt)
34+
UdtAccount.joins("LEFT OUTER JOIN bitcoin_address_mappings ON udt_accounts.address_id = bitcoin_address_mappings.ckb_address_id").
35+
where(udt_accounts: { udt_id: udt.id}, bitcoin_address_mappings: { bitcoin_address_id: nil }).
36+
where("udt_accounts.amount > 0").
37+
order("udt_accounts.amount desc").limit(10).map do |udt_account|
38+
address_hash = udt_account.address.address_hash
39+
position_ratio = udt.total_amount.zero? ? 0 : format("%.5f", udt_account.amount.to_f / udt.total_amount)
40+
{ address_hash:, amount: udt_account.amount.to_s, position_ratio: position_ratio.to_s, network: "ckb" }
41+
end
42+
end
43+
end
44+
end
45+
end

app/services/charts/daily_statistic_generator.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ def call
1616
daily_statistic.from_scratch = from_scratch
1717
daily_statistic.reset!(updated_attrs)
1818
daily_statistic
19-
rescue StandardError => e
20-
Rails.logger.error "Error occurred during DailyStatisticGenerator error: #{e.message}"
2119
end
2220

2321
private

app/workers/charts/daily_statistic.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Charts
22
class DailyStatistic
33
include Sidekiq::Worker
4-
sidekiq_options queue: "critical", backtrace: 20
4+
sidekiq_options queue: "critical"
55

66
# iterate from the creation timestamp of last daily statistic record to now day by day
77
# and generate daily statistic record for each day

config/routes/v2.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
resources :graph_channels, only: :index
108108
end
109109
resources :udt_hourly_statistics, only: :show
110-
resources :rgbpp_assets_statistics, only: :index
110+
resources :rgb_assets_statistics, only: :index
111+
resources :rgb_top_holders, only: :show
111112
end
112113
end

0 commit comments

Comments
 (0)