Skip to content

Commit

Permalink
fix: update rgbpp assets statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz committed Dec 23, 2024
1 parent cf2f62a commit 156401d
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions app/workers/generate_rgbpp_assets_statistic_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,25 @@ def dob_count_attributes
end

def btc_transactions_count_attributes
transactions_count = BitcoinTransaction.where(time: started_at.to_i..ended_at.to_i).count
transactions_count = BitcoinTransaction.where(time: ..ended_at.to_i).count

Check warning on line 39 in app/workers/generate_rgbpp_assets_statistic_worker.rb

View check run for this annotation

Codecov / codecov/patch

app/workers/generate_rgbpp_assets_statistic_worker.rb#L39

Added line #L39 was not covered by tests
{ indicator: "transactions_count", value: transactions_count, network: "btc" }
end

def ckb_transactions_count_attributes
started_timestamp = CkbUtils.time_in_milliseconds(started_at)
ended_timestamp = CkbUtils.time_in_milliseconds(ended_at) - 1
transactions_count = BitcoinAnnotation.includes(:ckb_transaction).
where(ckb_transactions: { block_timestamp: started_timestamp..ended_timestamp }).count
timestamp = CkbUtils.time_in_milliseconds(ended_at) - 1

Check warning on line 44 in app/workers/generate_rgbpp_assets_statistic_worker.rb

View check run for this annotation

Codecov / codecov/patch

app/workers/generate_rgbpp_assets_statistic_worker.rb#L44

Added line #L44 was not covered by tests

ft_transaction_ids = Set.new
Udt.where(udt_type: %i[xudt xudt_compatible]).find_each do |xudt|
ft_transaction_ids.merge(xudt.ckb_transactions.where(block_timestamp: ..timestamp).ids)
end

Check warning on line 49 in app/workers/generate_rgbpp_assets_statistic_worker.rb

View check run for this annotation

Codecov / codecov/patch

app/workers/generate_rgbpp_assets_statistic_worker.rb#L46-L49

Added lines #L46 - L49 were not covered by tests

dob_transaction_ids = Set.new
TokenCollection.where("tags && ARRAY[?]::varchar[]", ["rgb++"]).find_each do |token_collection|
transfers = token_collection.transfers.joins(:ckb_transaction).where("ckb_transactions.block_timestamp <= ?", timestamp)
dob_transaction_ids.merge(transfers.map(&:transaction_id))
end

Check warning on line 55 in app/workers/generate_rgbpp_assets_statistic_worker.rb

View check run for this annotation

Codecov / codecov/patch

app/workers/generate_rgbpp_assets_statistic_worker.rb#L51-L55

Added lines #L51 - L55 were not covered by tests

transactions_count = ft_transaction_ids.length + dob_transaction_ids.length

Check warning on line 57 in app/workers/generate_rgbpp_assets_statistic_worker.rb

View check run for this annotation

Codecov / codecov/patch

app/workers/generate_rgbpp_assets_statistic_worker.rb#L57

Added line #L57 was not covered by tests
{ indicator: "transactions_count", value: transactions_count, network: "ckb" }
end

Expand All @@ -67,14 +77,14 @@ def ckb_holders_count_attributes

def to_be_counted_date
if @datetime.present?
return Time.zone.parse(@datetime)
return Time.parse(@datetime)

Check warning on line 80 in app/workers/generate_rgbpp_assets_statistic_worker.rb

View check run for this annotation

Codecov / codecov/patch

app/workers/generate_rgbpp_assets_statistic_worker.rb#L80

Added line #L80 was not covered by tests
end

last_record = UdtHourlyStatistic.order(created_at_unixtimestamp: :desc).first
if last_record
Time.zone.at(last_record.created_at_unixtimestamp) + 1.day
Time.at(last_record.created_at_unixtimestamp) + 1.day

Check warning on line 85 in app/workers/generate_rgbpp_assets_statistic_worker.rb

View check run for this annotation

Codecov / codecov/patch

app/workers/generate_rgbpp_assets_statistic_worker.rb#L85

Added line #L85 was not covered by tests
else
Time.current.yesterday
Time.now.yesterday

Check warning on line 87 in app/workers/generate_rgbpp_assets_statistic_worker.rb

View check run for this annotation

Codecov / codecov/patch

app/workers/generate_rgbpp_assets_statistic_worker.rb#L87

Added line #L87 was not covered by tests
end
end

Expand Down

0 comments on commit 156401d

Please sign in to comment.