Skip to content

Commit

Permalink
feat: add unlaimed compenstaion generator worker
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Jan 21, 2020
1 parent e00ca49 commit ba0e105
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
29 changes: 29 additions & 0 deletions app/workers/dao_contract_unclaimed_compensation_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class DaoContractUnclaimedCompensationGenerator
include Sidekiq::Worker

def perform
DaoContract.default_contract.update(unclaimed_compensation: cal_unclaimed_compensation)
end

private

def cal_unclaimed_compensation
phase1_dao_interests + unmade_dao_interests
end

def phase1_dao_interests
CellOutput.nervos_dao_withdrawing.generated_before(ended_at).unconsumed_at(ended_at).reduce(0) do |memo, nervos_dao_withdrawing_cell|
memo + CkbUtils.dao_interest(nervos_dao_withdrawing_cell)
end
end

def unmade_dao_interests
CellOutput.nervos_dao_deposit.generated_before(ended_at).unconsumed_at(ended_at).reduce(0) do |memo, cell_output|
dao = cell_output.block.dao
tip_dao = current_tip_block.dao
parse_dao = CkbUtils.parse_dao(dao)
tip_parse_dao = CkbUtils.parse_dao(tip_dao)
memo + (cell_output.capacity * tip_parse_dao.ar_i / parse_dao.ar_i) - cell_output.capacity
end
end
end
6 changes: 5 additions & 1 deletion config/schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ epoch_statistic:
chart_forked_event_processor:
cron: "30 0 * * *"
class: "Charts::ForkedEventProcessor"
queue: critical
queue: critical

cal_unclaimed_compensation:
cron: "0 */1 * * *"
class: "DaoContractUnclaimedCompensationGenerator"

0 comments on commit ba0e105

Please sign in to comment.