Skip to content

Commit

Permalink
feat: calculate estimated apc
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Jan 2, 2020
1 parent 3b68742 commit 4a4f04f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/models/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def block_index_in_epoch
number - start_number
end

def fraction_epoch
OpenStruct.new(number: epoch, index: block_index_in_epoch, length: length)
end

def self.find_block!(query_key)
cached_find(query_key) || raise(Api::V1::Exceptions::BlockNotFoundError)
end
Expand Down
5 changes: 3 additions & 2 deletions app/workers/charts/daily_statistic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ def perform(datetime = nil)
current_tip_block = Block.where("timestamp <= ?", ended_at).recent.first
mining_reward = Block.where("timestamp <= ?", ended_at).sum(:secondary_reward)
deposit_compensation = unclaimed_compensation(cell_outputs, current_tip_block) + claimed_compensation(cell_outputs)

estimated_apc = DaoContract.default_contract.estimated_apc(current_tip_block.fraction_epoch)
block_timestamp = Block.created_after(started_at).created_before(ended_at).recent.pick(:timestamp)
daily_statistic = ::DailyStatistic.create_or_find_by!(block_timestamp: block_timestamp)
daily_statistic.update(created_at_unixtimestamp: to_be_counted_date.to_i, transactions_count: daily_ckb_transactions_count,
addresses_count: addresses_count, total_dao_deposit: total_dao_deposit,
dao_depositors_count: dao_depositors_count, unclaimed_compensation: unclaimed_compensation(cell_outputs, current_tip_block),
claimed_compensation: claimed_compensation(cell_outputs), average_deposit_time: average_deposit_time(cell_outputs),
mining_reward: mining_reward, deposit_compensation: deposit_compensation, treasury_amount: treasury_amount(cell_outputs, current_tip_block))
mining_reward: mining_reward, deposit_compensation: deposit_compensation, treasury_amount: treasury_amount(cell_outputs, current_tip_block),
estimated_apc: estimated_apc)
end

private
Expand Down

0 comments on commit 4a4f04f

Please sign in to comment.