Skip to content

Commit

Permalink
fix: block rollback test
Browse files Browse the repository at this point in the history
Signed-off-by: Miles Zhang <[email protected]>
  • Loading branch information
zmcNotafraid committed Nov 28, 2024
1 parent 9396246 commit 7d367dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
11 changes: 9 additions & 2 deletions app/models/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,15 @@ def cache_keys
def invalid!
uncle_blocks.delete_all
# delete_address_txs_cache
ckb_transactions.delete_all
CellOutput.where(block_id: id).delete_all
ckb_transaction_ids = ckb_transactions.pluck(:id)
CellOutput.where(ckb_transaction_id: ckb_transaction_ids).delete_all
CellInput.where(ckb_transaction_id: ckb_transaction_ids).delete_all
AccountBook.where(ckb_transaction_id: ckb_transaction_ids).delete_all
CellDependency.where(ckb_transaction_id: ckb_transaction_ids).delete_all
HeaderDependency.where(ckb_transaction_id: ckb_transaction_ids).delete_all
TokenTransfer.where(transaction_id: ckb_transaction_ids).delete_all
Witness.where(ckb_transaction_id: ckb_transaction_ids).delete_all
ckb_transactions.destroy_all
ForkedBlock.create(attributes)
destroy
end
Expand Down
16 changes: 8 additions & 8 deletions app/models/ckb_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ class CkbTransaction < ApplicationRecord
has_many :included_blocks, class_name: "Block",
through: :block_transactions,
inverse_of: :contained_transactions
has_many :account_books, dependent: :delete_all
has_many :account_books
has_many :addresses, through: :account_books
has_many :cell_inputs, dependent: :delete_all
has_many :cell_inputs
has_many :input_cells, through: :cell_inputs, source: :previous_cell_output
has_many :cell_outputs, dependent: :delete_all
has_many :cell_outputs
accepts_nested_attributes_for :cell_outputs
has_many :inputs, class_name: "CellOutput", inverse_of: "consumed_by", foreign_key: "consumed_by_id"
has_many :outputs, class_name: "CellOutput"
has_many :dao_events # , dependent: :delete_all
# has_many :script_transactions, dependent: :delete_all
# has_many :scripts, through: :script_transactions

has_many :referring_cells, dependent: :delete_all
has_many :token_transfers, foreign_key: :transaction_id, dependent: :delete_all, inverse_of: :ckb_transaction
has_many :cell_dependencies, dependent: :delete_all
has_many :header_dependencies, dependent: :delete_all
has_many :witnesses, dependent: :delete_all
has_many :referring_cells
has_many :token_transfers, foreign_key: :transaction_id, inverse_of: :ckb_transaction
has_many :cell_dependencies
has_many :header_dependencies
has_many :witnesses

has_one :reject_reason

Expand Down

0 comments on commit 7d367dc

Please sign in to comment.