Skip to content

Commit 8e69f5d

Browse files
authored
Merge pull request #2613 from nervosnetwork/develop
Deploy to testnet
2 parents c6da8f7 + f0f16ef commit 8e69f5d

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

app/models/daily_statistic.rb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,16 @@ def liquidity
6969
define_logic :claimed_compensation do
7070
claimed_compensation = 0
7171
if from_scratch
72-
CellOutput.nervos_dao_withdrawing.consumed_before(ended_at).find_each do |nervos_dao_withdrawing_cell|
72+
DaoEvent.processed.withdraw_from_dao.consumed_before(ended_at).find_each do |dao_event|
73+
nervos_dao_withdrawing_cell = CellOutput.find_by(ckb_transaction_id: dao_event.ckb_transaction_id, cell_index: dao_event.cell_index)
7374
claimed_compensation += CkbUtils.dao_interest(nervos_dao_withdrawing_cell)
7475
end
7576
else
7677
claimed_compensation_today = 0
7778

78-
CellOutput.nervos_dao_withdrawing.consumed_between(started_at,
79-
ended_at).find_each do |nervos_dao_withdrawing_cell|
79+
DaoEvent.processed.withdraw_from_dao.consumed_between(started_at,
80+
ended_at).find_each do |dao_event|
81+
nervos_dao_withdrawing_cell = CellOutput.find_by(ckb_transaction_id: dao_event.ckb_transaction_id, cell_index: dao_event.cell_index)
8082
claimed_compensation_today += CkbUtils.dao_interest(nervos_dao_withdrawing_cell)
8183
end
8284

@@ -90,14 +92,14 @@ def liquidity
9092
sum_interest_bearing = 0
9193
sum_uninterest_bearing = 0
9294

93-
CellOutput.nervos_dao_withdrawing.generated_before(ended_at).unconsumed_at(ended_at).find_each do |nervos_dao_withdrawing_cell|
94-
nervos_dao_withdrawing_cell_generated_tx = nervos_dao_withdrawing_cell.ckb_transaction
95-
nervos_dao_deposit_cell = nervos_dao_withdrawing_cell_generated_tx.cell_inputs.order(:id)[nervos_dao_withdrawing_cell.cell_index].previous_cell_output
95+
DaoEvent.processed.withdraw_from_dao.created_before(ended_at).unconsumed_at(ended_at).find_each do |nervos_dao_withdrawing_cell|
96+
nervos_dao_deposit_cell = CellInput.find_by(ckb_transaction_id: nervos_dao_withdrawing_cell.ckb_transaction_id, index: nervos_dao_withdrawing_cell.cell_index).previous_cell_output
9697
interest_bearing_deposits += nervos_dao_deposit_cell.capacity
9798
sum_interest_bearing += nervos_dao_deposit_cell.capacity * (nervos_dao_withdrawing_cell.block_timestamp - nervos_dao_deposit_cell.block_timestamp) / MILLISECONDS_IN_DAY
9899
end
99100

100-
CellOutput.nervos_dao_deposit.generated_before(ended_at).unconsumed_at(ended_at).find_each do |nervos_dao_deposit_cell|
101+
DaoEvent.includes(:cell_output).processed.deposit_to_dao.created_before(ended_at).unconsumed_at(ended_at).find_each do |dao_event|
102+
nervos_dao_deposit_cell = dao_event.cell_output
101103
uninterest_bearing_deposits += nervos_dao_deposit_cell.capacity
102104

103105
sum_uninterest_bearing += nervos_dao_deposit_cell.capacity * (ended_at - nervos_dao_deposit_cell.block_timestamp) / MILLISECONDS_IN_DAY
@@ -478,8 +480,9 @@ def phase1_dao_interests
478480
@phase1_dao_interests ||=
479481
begin
480482
total = 0
481-
CellOutput.nervos_dao_withdrawing.
482-
generated_before(ended_at).unconsumed_at(ended_at).find_each do |nervos_dao_withdrawing_cell|
483+
DaoEvent.processed.withdraw_from_dao.
484+
created_before(ended_at).unconsumed_at(ended_at).find_each do |dao_event|
485+
nervos_dao_withdrawing_cell = CellOutput.find_by(ckb_transaction_id: dao_event.ckb_transaction_id, cell_index: dao_event.cell_index)
483486
total += CkbUtils.dao_interest(nervos_dao_withdrawing_cell)
484487
end
485488
total
@@ -491,9 +494,9 @@ def unmade_dao_interests
491494
begin
492495
tip_dao = current_tip_block.dao
493496
total = 0
494-
CellOutput.nervos_dao_deposit.
495-
generated_before(ended_at).unconsumed_at(ended_at).find_each do |cell_output|
496-
total += DaoCompensationCalculator.new(cell_output, tip_dao).call
497+
DaoEvent.includes(:cell_output).processed.deposit_to_dao.
498+
created_before(ended_at).unconsumed_at(ended_at).find_each do |dao_event|
499+
total += DaoCompensationCalculator.new(dao_event.cell_output, tip_dao).call
497500
end
498501
total
499502
end

app/models/dao_event.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ class DaoEvent < ApplicationRecord
2323
scope :created_between, ->(start_block_timestamp, end_block_timestamp) {
2424
created_after(start_block_timestamp).created_before(end_block_timestamp)
2525
}
26+
scope :consumed_before, ->(block_timestamp) {
27+
where("consumed_block_timestamp <= ?", block_timestamp)
28+
}
29+
scope :consumed_after, ->(block_timestamp) {
30+
where("consumed_block_timestamp >= ?", block_timestamp)
31+
}
32+
scope :consumed_between, ->(start_timestamp, end_timestamp) {
33+
consumed_after(start_timestamp).consumed_before(end_timestamp)
34+
}
35+
36+
scope :unconsumed_at, ->(block_timestamp) {
37+
where("consumed_block_timestamp > ? or consumed_block_timestamp is null", block_timestamp)
38+
}
2639
end
2740

2841
# == Schema Information

app/utils/ckb_utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def self.dao_withdraw_tx_fee(ckb_transaction)
287287

288288
def self.dao_interest(nervos_dao_withdrawing_cell)
289289
nervos_dao_withdrawing_cell_generated_tx = nervos_dao_withdrawing_cell.ckb_transaction
290-
nervos_dao_deposit_cell = nervos_dao_withdrawing_cell_generated_tx.cell_inputs.order(:id)[nervos_dao_withdrawing_cell.cell_index].previous_cell_output
290+
nervos_dao_deposit_cell = nervos_dao_withdrawing_cell_generated_tx.cell_inputs.order(:index)[nervos_dao_withdrawing_cell.cell_index].previous_cell_output
291291
withdrawing_dao_cell_block_dao = nervos_dao_withdrawing_cell.dao
292292
DaoCompensationCalculator.new(nervos_dao_deposit_cell, withdrawing_dao_cell_block_dao,
293293
nervos_dao_withdrawing_cell).call

0 commit comments

Comments
 (0)