From ba0e1057059a461325951e25bd7ba82e2241731c Mon Sep 17 00:00:00 2001 From: shaojunda Date: Tue, 21 Jan 2020 17:49:33 +0800 Subject: [PATCH] feat: add unlaimed compenstaion generator worker --- ...ntract_unclaimed_compensation_generator.rb | 29 +++++++++++++++++++ config/schedule.yml | 6 +++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 app/workers/dao_contract_unclaimed_compensation_generator.rb diff --git a/app/workers/dao_contract_unclaimed_compensation_generator.rb b/app/workers/dao_contract_unclaimed_compensation_generator.rb new file mode 100644 index 000000000..791137d4b --- /dev/null +++ b/app/workers/dao_contract_unclaimed_compensation_generator.rb @@ -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 diff --git a/config/schedule.yml b/config/schedule.yml index 074dee849..a08a6cc9a 100644 --- a/config/schedule.yml +++ b/config/schedule.yml @@ -16,4 +16,8 @@ epoch_statistic: chart_forked_event_processor: cron: "30 0 * * *" class: "Charts::ForkedEventProcessor" - queue: critical \ No newline at end of file + queue: critical + +cal_unclaimed_compensation: + cron: "0 */1 * * *" + class: "DaoContractUnclaimedCompensationGenerator"