diff --git a/app/jobs/import_block_job.rb b/app/jobs/import_block_job.rb deleted file mode 100644 index 58bd09cda..000000000 --- a/app/jobs/import_block_job.rb +++ /dev/null @@ -1,17 +0,0 @@ -# No used -class ImportBlockJob < ApplicationJob - def perform(block_hash) - if block_hash.is_a?(Integer) - block = Block.fetch_raw_hash_by_number(block_hash) - block_number = block_hash - block_hash = block["header"]["hash"] - else - block = Block.fetch_raw_hash(block_hash) - block_number = block["header"]["number"] - end - - block["transactions"].each do |tx| - ImportTransactionJob.perform_later tx, { block_hash: block["hash"] } - end - end -end diff --git a/app/jobs/import_transaction_job.rb b/app/jobs/import_transaction_job.rb deleted file mode 100644 index 3eac63c4e..000000000 --- a/app/jobs/import_transaction_job.rb +++ /dev/null @@ -1,335 +0,0 @@ -# process a raw transaction and save related records to database -class ImportTransactionJob < ApplicationJob - queue_as :default - attr_accessor :tx, :txid, :sdk_tx, :cell_dependencies_attrs, - :by_type_hash, :by_data_hash, - :deployed_cells_attrs, - :addresses, - :address_changes - - # @param tx_hash [String] - def perform(tx_hash, extra_data = {}) - self.address_changes = {} - if tx_hash.is_a?(Hash) - CkbTransaction.write_raw_hash_cache tx_hash["hash"], tx_hash - tx_hash = tx_hash["hash"] - end - @tx = CkbTransaction.unscoped.create_with(tx_status: :pending).find_or_create_by!(tx_hash:) - return unless tx.tx_pending? - - Rails.logger.info "Importing #{tx.tx_hash}" - @sdk_tx = CkbTransaction.fetch_sdk_transaction(tx_hash) - unless @sdk_tx - Rails.logger.info "Cannot fetch transaction details for #{tx_hash}" - return - end - @tx.cycles = extra_data[:cycles] - if extra_data[:timestamp] - @tx.created_at = Time.at(extra_data[:timestamp].to_d / 1000).utc - end - @tx.transaction_fee = extra_data[:fee] - @tx.bytes = extra_data[:size] || @sdk_tx.serialized_size_in_block - @tx.version = @sdk_tx.version - @tx.live_cell_changes = sdk_tx.outputs.count - sdk_tx.inputs.count - if extra_data[:block_hash] - block = Block.find_by block_hash: extra_data["block_hash"] - @tx.included_block_ids << block.id - end - @tx.save - @txid = tx.id - @deployed_cells_attrs = [] - @cell_dependencies_attrs = [] - @by_type_hash = {} - @by_data_hash = {} - - capacity_involved = 0 - - # process inputs - sdk_tx.inputs.each_with_index do |input, index| - if input.previous_output.tx_hash == CellOutput::SYSTEM_TX_HASH - tx.cell_inputs.create_with( - index:, - ).create_or_find_by( - previous_cell_output_id: nil, - from_cell_base: true, - ) - else - cell = CellOutput.find_by( - tx_hash: input.previous_output.tx_hash, - cell_index: input.previous_output.index, - ) - - if cell - process_input tx.cell_inputs.create_with( - previous_cell_output_id: cell.id, - ).create_or_find_by!( - ckb_transaction_id: txid, - index:, - ) - process_deployed_cell(cell.lock_script) - process_deployed_cell(cell.type_script) if cell.type_script - capacity_involved += cell.capacity - else - tx.cell_inputs.create_or_find_by!( - previous_tx_hash: input.previous_output.tx_hash, - previous_index: input.previous_output.index, - since: input.since, - index:, - ) - puts "Missing input #{input.previous_output.to_h} in #{tx_hash}" - # cannot find corresponding cell output, - # maybe the transaction contains the cell output has not been processed, - # so add current transaction to pending list, and wait for future processing - - list = Kredis.unique_list "pending_transactions_for_input:#{input.previous_output.tx_hash}" - list << tx_hash - end - end - end - @tx.update_column :capacity_involved, capacity_involved - # process outputs - sdk_tx.outputs.each_with_index do |output, index| - output_data = sdk_tx.outputs_data[index] - lock = LockScript.process(output.lock) - t = TypeScript.process(output.type) if output.type - cell = tx.cell_outputs.find_or_create_by( - tx_hash:, - cell_index: index, - ) - - # after the cell is created, create a datum - if output_data.present? && output_data != "0x" - (cell.cell_datum || cell.build_cell_datum).update(data: [output_data[2..]].pack("H*")) - end - - cell.lock_script = lock - cell.type_script = t - cell.update!( - address_id: lock.address_id, - capacity: output.capacity, - occupied_capacity: cell.calculate_min_capacity, - status: "pending", - ) - puts "output cell created tx_hash: #{tx_hash}, index: #{index}, cell_id: #{cell.id}" - - process_output cell - process_deployed_cell(cell.lock_script) - process_deployed_cell(cell.type_script) if cell.type_script - end - - process_cell_deps - process_header_deps - process_witnesses - save_relationship - save_changes - - # notify pending transaction to reprocess again - pending_list = Kredis.unique_list "pending_transactions_for_input:#{tx_hash}" - pending_list.elements.each do |_tx| - ImportTransactionJob.perform_later _tx - end - pending_list.clear - end - - def parse_code_dep(cell_dep) - # this cell output is the contract cell, i.e. one of deployed cells of the contract - cell_output = CellOutput.find_by_pointer cell_dep["out_point"]["tx_hash"], cell_dep["out_point"]["index"] - - attr = { - contract_cell_id: cell_output.id, - dep_type: cell_dep["dep_type"], - ckb_transaction_id: ckb_transaction.id, - # check if we already known the relationship between the contract cell and contract - contract_id: DeployedCell.cell_output_id_to_contract_id(cell_output.id), - implicit: cell_dep["implicit"] || false, - } - - # we don't know how the cells in transaction may refer to the contract cell - # so we make index for both `data` and `type` of `hash_type` - cell_output.data_hash ||= CKB::Blake2b.hexdigest(cell_output.binary_data) - - ## data type refer by the hash value of data field of cell - by_data_hash[cell_output.data_hash] = attr - - ## `type` type refer by the hash value of type field of cell - if cell_output.type_script_id - cell_output.type_hash ||= cell_output.type_script.script_hash - by_type_hash[cell_output.type_hash] = attr - end - - cell_output.save if cell_output.changed? # save data_hash type_hash to cell_output - cell_dependencies_attrs << attr - cell_output - end - - def save_relationship - @deployed_cells_attrs = deployed_cells_attrs.uniq { |a| a[:cell_output_id] } - if cell_dependencies_attrs.present? - CellDependency.upsert_all cell_dependencies_attrs.uniq { |a| - a[:contract_cell_id] - }, unique_by: %i[ckb_transaction_id contract_cell_id] - end - DeployedCell.upsert_all deployed_cells_attrs, unique_by: [:cell_output_id] if deployed_cells_attrs.present? - deployed_cells_attrs.each do |deployed_cell_attr| - DeployedCell.write_cell_output_id_to_contract_id( - deployed_cell_attr[:cell_output_id], - deployed_cell_attr[:contract_id], - ) - end - end - - def process_deployed_cell(lock_script_or_type_script) - @processed_script_for_deployed_cell ||= Set.new - return if @processed_script_for_deployed_cell.include?(lock_script_or_type_script) - - @processed_script_for_deployed_cell << lock_script_or_type_script - - dep = - case lock_script_or_type_script.hash_type - when "data", "data1", "data2" - by_data_hash[lock_script_or_type_script.code_hash] - when "type" - by_type_hash[lock_script_or_type_script.code_hash] - end - return unless dep - - unless dep[:contract_id] # we don't know the corresponding contract - contract = Contract.find_or_initialize_by code_hash: lock_script_or_type_script.code_hash, - hash_type: lock_script_or_type_script.hash_type - - if contract.id.blank? # newly created contract record - contract.deployed_args = lock_script_or_type_script.args - contract.role = lock_script_or_type_script.class.name - contract.save! - end - dep[:contract_id] = contract.id - - deployed_cells_attrs << { - contract_id: contract.id, - cell_output_id: dep[:contract_cell_id], - } - end - end - - def process_cell_deps - sdk_tx.cell_deps.each_with_index do |cell_dep, _index| - process_cell_dep cell_dep - end - end - - def process_cell_dep(cell_dep) - cell_dep = cell_dep.to_h if cell_dep.is_a?(CKB::Types::CellDep) - case cell_dep["dep_type"] - when "code" - parse_code_dep(cell_dep) - when "dep_group" - # when the type of cell_dep is "dep_group", - # it means the cell specified by the `out_point` is a list of out points to the actual referred contract cells - mid_cell = CellOutput.find_by_pointer cell_dep["out_point"]["tx_hash"], cell_dep["out_point"]["index"] - cell_dependencies_attrs << { - contract_cell_id: mid_cell.id, - dep_type: cell_dep["dep_type"], - ckb_transaction_id: ckb_transaction.id, - contract_id: nil, - implicit: false, - } - binary_data = mid_cell.binary_data - # binary_data = [hex_data[2..-1]].pack("H*") - # parse the actual list of out points from the data field of the cell - out_points_count = binary_data[0, 4].unpack("L<") - - # iterate over the out point list and append actual referred contract cells to cell dependencies_attrs - 0.upto(out_points_count[0] - 1) do |i| - tx_hash, cell_index = binary_data[4 + i * 36, 36].unpack("H64L<") - # contract_cell = CellOutput.find_by_pointer "0x#{tx_hash}", cell_index - - parse_code_dep( - "out_point" => { - "tx_hash" => "0x#{tx_hash}", - "index" => cell_index, - }, - "dep_type" => "code", - "implicit" => true, # this is an implicit dependency - ) - end - end - end - - def process_header_deps - header_deps_attrs = [] - sdk_tx.header_deps.each_with_index do |header_dep, index| - header_deps_attrs << { - ckb_transaction_id: txid, - index:, - header_hash: header_dep, - } - end - if header_deps_attrs.present? - HeaderDependency.upsert_all(header_deps_attrs, - unique_by: %i[ckb_transaction_id index]) - end - end - - def process_witnesses - witnesses_attrs = [] - sdk_tx.witnesses.each_with_index do |w, i| - witnesses_attrs << { - ckb_transaction_id: txid, - index: i, - data: w, - } - end - if witnesses_attrs.present? - Witness.upsert_all(witnesses_attrs, unique_by: %i[ckb_transaction_id index]) - end - end - - # calculate address and balance change for each cell output - # @param cell_input [CellInput] - def process_input(cell_input) - cell_output = cell_input.previous_cell_output - - address_id = cell_output.address_id - changes = address_changes[address_id] ||= - { - balance: 0, - balance_occupied: 0, - } - changes[:balance] -= cell_output.capacity - changes[:balance_occupied] -= cell_output.occupied_capacity if cell_output.occupied_capacity - end - - # # calculate address and balance change for each cell output - # @param cell_output [CellOutput] - def process_output(cell_output) - address_id = cell_output.address_id - changes = address_changes[address_id] ||= - { - balance: 0, - balance_occupied: 0, - } - changes[:balance] += cell_output.capacity - changes[:balance_occupied] += cell_output.occupied_capacity - end - - def save_changes - if address_changes.present? - attrs = - address_changes.map do |address_id, c| - { - address_id:, - ckb_transaction_id: txid, - changes: c, - } - end - TransactionAddressChange.upsert_all( - attrs, - unique_by: %i[address_id ckb_transaction_id], - on_duplicate: Arel.sql( - "changes = transaction_address_changes.changes || excluded.changes", - ), - ) - AccountBook.upsert_all address_changes.keys.map { |address_id| { ckb_transaction_id: tx.id, address_id: } } - end - end -end diff --git a/app/jobs/revert_block_job.rb b/app/jobs/revert_block_job.rb index e1e49c928..54e3de4ab 100644 --- a/app/jobs/revert_block_job.rb +++ b/app/jobs/revert_block_job.rb @@ -31,7 +31,6 @@ def perform(local_tip_block = nil) benchmark :recalculate_udt_accounts, udt_type_hashes, local_tip_block benchmark :update_address_balance_and_ckb_transactions_count, local_tip_block benchmark :revert_block_rewards, local_tip_block - benchmark :revert_referring_cells, local_tip_block ForkedEvent.create!(block_number: local_tip_block.number, epoch_number: local_tip_block.epoch, block_timestamp: local_tip_block.timestamp) ApplicationRecord.benchmark "BlockStatisticGenerator" do @@ -208,9 +207,4 @@ def decrease_records_count(local_tip_block) normal_transactions = local_tip_block.ckb_transactions.normal ckb_transaction_counter.decrement!(:count, normal_transactions.count) if normal_transactions.present? end - - def revert_referring_cells(local_tip_block) - tx_ids = local_tip_block.ckb_transaction_ids - ReferringCell.where(ckb_transaction_id: tx_ids).delete_all - end end diff --git a/app/models/cell_output.rb b/app/models/cell_output.rb index d86a22b05..53eda33ef 100644 --- a/app/models/cell_output.rb +++ b/app/models/cell_output.rb @@ -42,8 +42,6 @@ class CellOutput < ApplicationRecord # but one cell may be included by many pending transactions, # the cell_inputs won't always be the same as `consumed_by`.`cell_inputs` has_many :cell_inputs, foreign_key: :previous_cell_output_id - # belongs_to :deployed_cell, optional: true - # has_many :referring_cells # the block_id is actually the same as ckb_transaction.block_id, must be on chain # but one cell may be included by pending transactions, so block_id may be null belongs_to :block, optional: true diff --git a/app/models/ckb_sync/new_node_data_processor.rb b/app/models/ckb_sync/new_node_data_processor.rb index bebdd415d..c68679762 100644 --- a/app/models/ckb_sync/new_node_data_processor.rb +++ b/app/models/ckb_sync/new_node_data_processor.rb @@ -93,7 +93,6 @@ def process_block(node_block, refresh_balance: true) async_update_udt_infos(local_block) flush_inputs_outputs_caches(local_block) generate_statistics_data(local_block) - # generate_deployed_cells_and_referring_cells(local_block) detect_cota_infos(local_block) detect_token_transfer(token_transfer_ckb_tx_ids) detect_bitcoin_transactions(local_block) @@ -122,10 +121,6 @@ def check_invalid_address(address) private - def generate_deployed_cells_and_referring_cells(local_block) - GenerateCellDependenciesWorker.perform_async(local_block.id) - end - def generate_statistics_data(local_block) GenerateStatisticsDataWorker.perform_async(local_block.id) end @@ -794,51 +789,14 @@ def build_cells_and_locks!( input_capacities = [] output_capacities = [] lock_scripts_attributes, type_scripts_attributes = build_scripts(outputs) - lock_script_ids = [] - type_script_ids = [] - if lock_scripts_attributes.present? - lock_scripts_attributes.map! do |attr| - attr.merge!(created_at: Time.current, updated_at: Time.current) - end - LockScript.upsert_all(lock_scripts_attributes, unique_by: :script_hash, returning: [:id]) - - # lock_script_ids.each do |row| - # lock_script_id = row["id"] - # lock_script = LockScript.find lock_script_id - # contract = Contract.find_by code_hash: lock_script.code_hash - # temp_hash = { script_hash: lock_script&.script_hash, is_contract: false } - # if contract - # temp_hash = temp_hash.merge is_contract: true, contract_id: contract.id - # else - # contract = Contract.create code_hash: lock_script.script_hash - # temp_hash = temp_hash.merge contract_id: contract.id - # end - # # script = Script.find_or_create_by temp_hash - # # lock_script.update script_id: script.id - # end + if lock_scripts_attributes.any? + LockScript.upsert_all(lock_scripts_attributes, unique_by: :script_hash, returning: [:id], record_timestamps: true) end - - if type_scripts_attributes.present? - type_scripts_attributes.map! do |attr| - attr.merge!(created_at: Time.current, updated_at: Time.current) - end - TypeScript.upsert_all(type_scripts_attributes, unique_by: :script_hash, returning: [:id]) - # type_script_ids.each do |row| - # type_script_id = row["id"] - # type_script = TypeScript.find(type_script_id) - # temp_hash = { script_hash: type_script&.script_hash, is_contract: false } - # contract = Contract.find_by code_hash: type_script.code_hash - # if contract - # temp_hash = temp_hash.merge is_contract: true, contract_id: contract.id - # else - # contract = Contract.create code_hash: type_script.script_hash - # temp_hash = temp_hash.merge contract_id: contract.id - # end - # # script = Script.find_or_create_by temp_hash - # # type_script.update script_id: script.id - # end + if type_scripts_attributes.any? + TypeScript.upsert_all(type_scripts_attributes, unique_by: :script_hash, returning: [:id], record_timestamps: true) end + build_addresses!(outputs, local_block) # prepare script ids for insert cell_outputs prepare_script_ids(outputs) @@ -910,9 +868,6 @@ def build_cells_and_locks!( record_timestamps: true) end - # ScriptTransaction.create_from_scripts TypeScript.where(id: type_script_ids) - # ScriptTransaction.create_from_scripts LockScript.where(id: lock_script_ids) - [input_capacities, output_capacities] end diff --git a/app/models/ckb_transaction.rb b/app/models/ckb_transaction.rb index a8ba683a1..ef86f1dd9 100644 --- a/app/models/ckb_transaction.rb +++ b/app/models/ckb_transaction.rb @@ -24,11 +24,8 @@ class CkbTransaction < ApplicationRecord 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 :dao_events - has_many :referring_cells has_many :token_transfers, foreign_key: :transaction_id, inverse_of: :ckb_transaction has_many :cell_dependencies has_many :header_dependencies diff --git a/app/models/deployed_cell.rb b/app/models/deployed_cell.rb deleted file mode 100644 index 3cdf5fec5..000000000 --- a/app/models/deployed_cell.rb +++ /dev/null @@ -1,195 +0,0 @@ -class DeployedCell < ApplicationRecord - belongs_to :contract - belongs_to :cell_output - # one contract can has multiple deployed cells - validates :cell_output, uniqueness: true - - # find the corresponding contract defined in the specified cell output via cache - # @param cell_output_id [Integer] deployed cell output id - def self.cell_output_id_to_contract_id(cell_output_id) - Rails.cache.fetch(["cell_output_id_to_contract_id", cell_output_id], expires_in: 1.day) do - DeployedCell.where(cell_output_id:).pick(:contract_id) - end - end - - # save the contract <-> deployed cell mapping to cache - # @param cell_output_id [Integer] deployed cell output id - # @param contract_id [Integer] contract id - def self.write_cell_output_id_to_contract_id(cell_output_id, contract_id) - Rails.cache.write(["cell_output_id_to_contract_id", cell_output_id], contract_id, expires_in: 1.day) - end - - # create initial data for this table - # before running this method, - # 1. run Script.create_initial_data - # 2. run this method: DeployedCell.create_initial_data - def self.create_initial_data(ckb_transaction_id = 0) - Rails.logger.info "=== ckb_transaction_id: #{ckb_transaction_id.inspect}" - pool = Concurrent::FixedThreadPool.new(5, max_queue: 1000, - fallback_policy: :caller_runs) - CkbTransaction.tx_committed.where(is_cellbase: false).where("id >= ?", - ckb_transaction_id).find_each do |ckb_transaction| - Rails.logger.info "=== ckb_transaction: #{ckb_transaction.id}" - # pool.post do - Rails.application.executor.wrap do - ActiveRecord::Base.connection_pool.with_connection do - ActiveRecord::Base.cache do - if ckb_transaction.cell_dependencies.empty? - puts ckb_transaction.raw_hash["cell_deps"] - DeployedCell.create_initial_data_for_ckb_transaction ckb_transaction, - ckb_transaction.raw_hash["cell_deps"] - end - end - end - end - # end - end - pool.shutdown - pool.wait_for_termination - Rails.logger.info "== done" - end - - def self.create_initial_data_for_ckb_transaction(ckb_transaction, cell_deps) - return if cell_deps.blank? - - deployed_cells = [] - cell_dependencies_attrs = [] - by_type_hash = {} - by_data_hash = {} - - # initialize cell dependencies records - # the `cell_deps` field in ckb transactions stores the contract cell (referred by out point, - # which contains the compiled byte code of contract) the transaction should refer. - # the submitter of the transaction is responsible for including all the contract cells - # specified by all the `type_script` and `lock_script` of the cell inputs and cell outputs - - parse_code_dep = - ->(cell_dep) do - # this cell output is the contract cell, i.e. one of deployed cells of the contract - cell_output = CellOutput.find_by_pointer cell_dep["out_point"]["tx_hash"], cell_dep["out_point"]["index"] - - attr = { - contract_cell_id: cell_output.id, - dep_type: cell_dep["dep_type"], - ckb_transaction_id: ckb_transaction.id, - contract_id: DeployedCell.cell_output_id_to_contract_id(cell_output.id), # check if we already known the relationship between the contract cell and contract - implicit: cell_dep["implicit"] || false, - } - - # we don't know how the cells in transaction may refer to the contract cell - # so we make index for both `data` and `type` of `hash_type` - cell_output.data_hash ||= CKB::Blake2b.hexdigest(cell_output.binary_data) if cell_output.binary_data - - by_data_hash[cell_output.data_hash] = attr # data type refer by the hash value of data field of cell - # `type` type refer by the hash value of type field of cell - if cell_output.type_script_id - cell_output.type_hash ||= cell_output.type_script.script_hash - by_type_hash[cell_output.type_hash] = attr - end - cell_output.save if cell_output.changed? # save data_hash type_hash to cell_output - cell_dependencies_attrs << attr - cell_output - end - - cell_deps.each do |cell_dep| - if cell_dep.is_a?(CKB::Types::CellDep) - cell_dep = cell_dep.to_h.with_indifferent_access - end - case cell_dep["dep_type"] - when "code" - parse_code_dep[cell_dep] - when "dep_group" - # when the type of cell_dep is "dep_group", it means the cell specified by the `out_point` is a list of out points to the actual referred contract cells - mid_cell = CellOutput.find_by_pointer cell_dep["out_point"]["tx_hash"], cell_dep["out_point"]["index"] - cell_dependencies_attrs << { - contract_cell_id: mid_cell.id, - dep_type: cell_dep["dep_type"], - ckb_transaction_id: ckb_transaction.id, - contract_id: nil, - implicit: false, - } - binary_data = mid_cell.binary_data - # binary_data = [hex_data[2..-1]].pack("H*") - # parse the actual list of out points from the data field of the cell - out_points_count = binary_data[0, 4].unpack("L<") - out_points = [] - # iterate over the out point list and append actual referred contract cells to cell dependencies_attrs - 0.upto(out_points_count[0] - 1) do |i| - tx_hash, cell_index = binary_data[4 + i * 36, 36].unpack("H64L<") - # contract_cell = CellOutput.find_by_pointer "0x#{tx_hash}", cell_index - - co = parse_code_dep[{ - "out_point" => { - "tx_hash" => "0x#{tx_hash}", - "index" => cell_index, - }, - "dep_type" => "code", - "implicit" => true, # this is an implicit dependency - }] - end - end - end - - cells = ckb_transaction.cell_outputs.includes(:lock_script, :type_script).to_a + - ckb_transaction.cell_inputs.includes(:previous_cell_output).map(&:previous_cell_output) - scripts = cells.compact.inject([]) { |a, cell| a + [cell.lock_script, cell.type_script] }.compact.uniq - deployed_cells_attrs = [] - - scripts.each do |lock_script_or_type_script| - dep = - case lock_script_or_type_script.hash_type - when "data", "data1", "data2" - by_data_hash[lock_script_or_type_script.code_hash] - when "type" - by_type_hash[lock_script_or_type_script.code_hash] - end - next unless dep - - unless dep[:contract_id] # we don't know the corresponding contract - contract = Contract.find_or_initialize_by code_hash: lock_script_or_type_script.code_hash, - hash_type: lock_script_or_type_script.hash_type - - if contract.id.blank? # newly created contract record - contract.deployed_args = lock_script_or_type_script.args - contract.role = lock_script_or_type_script.class.name - contract.save! - end - dep[:contract_id] = contract.id - - deployed_cells_attrs << { - contract_id: contract.id, - cell_output_id: dep[:contract_cell_id], - } - end - end - - deployed_cells_attrs = deployed_cells_attrs.uniq { |a| a[:cell_output_id] } - - if cell_dependencies_attrs.present? - CellDependency.upsert_all cell_dependencies_attrs.uniq { |a| - a[:contract_cell_id] - }, unique_by: %i[ckb_transaction_id contract_cell_id] - end - DeployedCell.upsert_all deployed_cells_attrs, unique_by: [:cell_output_id] if deployed_cells_attrs.present? - deployed_cells_attrs.each do |deployed_cell_attr| - DeployedCell.write_cell_output_id_to_contract_id(deployed_cell_attr[:cell_output_id], - deployed_cell_attr[:contract_id]) - end - end -end - -# == Schema Information -# -# Table name: deployed_cells -# -# id :bigint not null, primary key -# cell_output_id :bigint not null -# contract_id :bigint not null -# created_at :datetime not null -# updated_at :datetime not null -# -# Indexes -# -# index_deployed_cells_on_cell_output_id (cell_output_id) UNIQUE -# index_deployed_cells_on_contract_id_and_cell_output_id (contract_id,cell_output_id) UNIQUE -# diff --git a/app/models/distribution_data.rb b/app/models/distribution_data.rb index da73c1367..bcc2d10eb 100644 --- a/app/models/distribution_data.rb +++ b/app/models/distribution_data.rb @@ -1,8 +1,7 @@ class DistributionData VALID_INDICATORS = %w( address_balance_distribution block_time_distribution epoch_time_distribution epoch_length_distribution - average_block_time nodes_distribution block_propagation_delay_history transaction_propagation_delay_history - miner_address_distribution + average_block_time nodes_distribution block_propagation_delay_history miner_address_distribution ).freeze def id @@ -55,28 +54,6 @@ def block_propagation_delay_history BlockPropagationDelay.connection.select_all(sql) end - def transaction_propagation_delay_history - round_num = 4 - sql = - <<-SQL - select created_at_unixtimestamp, - round(avg((durations->>0)::numeric), #{round_num}) avg5, round(avg((durations->>1)::numeric), #{round_num}) avg10, - round(avg((durations->>2)::numeric), #{round_num}) avg15, round(avg((durations->>3)::numeric), #{round_num}) avg20, - round(avg((durations->>4)::numeric), #{round_num}) avg25, round(avg((durations->>5)::numeric), #{round_num}) avg30, - round(avg((durations->>6)::numeric), #{round_num}) avg35, round(avg((durations->>7)::numeric), #{round_num}) avg40, - round(avg((durations->>8)::numeric), #{round_num}) avg45, round(avg((durations->>9)::numeric), #{round_num}) avg50, - round(avg((durations->>10)::numeric), #{round_num}) avg55, round(avg((durations->>11)::numeric), #{round_num}) avg60, - round(avg((durations->>12)::numeric), #{round_num}) avg65, round(avg((durations->>13)::numeric), #{round_num}) avg70, - round(avg((durations->>14)::numeric), #{round_num}) avg75, round(avg((durations->>15)::numeric), #{round_num}) avg80, - round(avg((durations->>16)::numeric), #{round_num}) avg85, round(avg((durations->>17)::numeric), #{round_num}) avg90 - from transaction_propagation_delays - group by created_at_unixtimestamp - order by created_at_unixtimestamp - SQL - - TransactionPropagationDelay.connection.select_all(sql) - end - def miner_address_distribution(checkpoint = 7) supported_checkpoints = [7, 90] return unless checkpoint.in?(supported_checkpoints) diff --git a/app/models/lock_script.rb b/app/models/lock_script.rb index 77984fb53..2445d2dbc 100644 --- a/app/models/lock_script.rb +++ b/app/models/lock_script.rb @@ -7,9 +7,6 @@ class LockScript < ApplicationRecord belongs_to :address, optional: true # will remove this later - belongs_to :script, optional: true - belongs_to :contract, optional: true, primary_key: "code_hash", foreign_key: "code_hash" - validates_presence_of :code_hash attribute :code_hash, :ckb_hash diff --git a/app/models/referring_cell.rb b/app/models/referring_cell.rb deleted file mode 100644 index 9ae25ebf2..000000000 --- a/app/models/referring_cell.rb +++ /dev/null @@ -1,60 +0,0 @@ -# TODO keep ReferringCell or CellDependency -# referring cells v2. -class ReferringCell < ApplicationRecord - belongs_to :contract - belongs_to :ckb_transaction - belongs_to :cell_output - - # create initial data - # please run this script - def self.create_initial_data(ckb_transaction_id = nil) - CkbTransaction.where("id <= ?", ckb_transaction_id).find_each do |ckb_transaction| - self.create_initial_data_for_ckb_transaction ckb_transaction - end - end - - def self.create_initial_data_for_ckb_transaction(ckb_transaction) - inputs = ckb_transaction.inputs - outputs = ckb_transaction.outputs - - (inputs + outputs).each do |cell| - contracts = [cell.lock_script.contract, cell.type_script&.contract].compact - - next if contracts.empty? - - contracts.each do |contract| - if cell.live? - ReferringCell.create_or_find_by( - cell_output_id: cell.id, - ckb_transaction_id: ckb_transaction.id, - contract_id: contract.id - ) - elsif cell.dead? - referring_cell = ReferringCell.find_by( - cell_output_id: cell.id, - ckb_transaction_id: ckb_transaction.id, - contract_id: contract.id - ) - - referring_cell.destroy if referring_cell - end - end - end - end -end - -# == Schema Information -# -# Table name: referring_cells -# -# id :bigint not null, primary key -# cell_output_id :bigint -# contract_id :bigint -# ckb_transaction_id :bigint -# created_at :datetime not null -# updated_at :datetime not null -# -# Indexes -# -# index_referring_cells_on_contract_id_and_cell_output_id (contract_id,cell_output_id) UNIQUE -# diff --git a/app/models/script.rb b/app/models/script.rb deleted file mode 100644 index 12a5f00ec..000000000 --- a/app/models/script.rb +++ /dev/null @@ -1,58 +0,0 @@ -class Script < ActiveRecord::Base - has_many :lock_scripts - has_many :type_scripts - has_many :cell_dependencies - - has_many :script_transactions - has_many :ckb_transactions, through: :script_transactions - - belongs_to :contract, optional: true - - def self.create_initial_data - contracts = {} - Contract.all.each do |contract| - contracts[contract.code_hash] = contract - end - TypeScript.find_each do |type_script| - contract_id = contracts[type_script.code_hash]&.id - - temp_hash = { args: type_script.args, script_hash: type_script.script_hash, is_contract: false } - if contract_id - temp_hash = temp_hash.merge is_contract: true, contract_id: contract_id - end - - script = Script.find_or_create_by temp_hash - type_script.update script_id: script.id - end - - LockScript.find_each do |lock_script| - contract_id = contracts[lock_script.code_hash]&.id - - temp_hash = { args: lock_script.args, script_hash: lock_script.script_hash, is_contract: false } - if contract_id - temp_hash = temp_hash.merge is_contract: true, contract_id: contract_id - end - script = Script.find_or_create_by temp_hash - lock_script.update script_id: script.id - end - - Rails.logger.info "== Script.create_initial_data done" - end -end - -# == Schema Information -# -# Table name: scripts -# -# id :bigint not null, primary key -# args :string -# script_hash :string -# is_contract :boolean default(FALSE) -# contract_id :bigint -# created_at :datetime not null -# updated_at :datetime not null -# -# Indexes -# -# index_scripts_on_contract_id (contract_id) -# diff --git a/app/models/script_transaction.rb b/app/models/script_transaction.rb deleted file mode 100644 index 98f011976..000000000 --- a/app/models/script_transaction.rb +++ /dev/null @@ -1,73 +0,0 @@ -class ScriptTransaction < ApplicationRecord - belongs_to :script - belongs_to :ckb_transaction - - # run these methods: - # ScriptTransaction.create_initial_data - def self.create_initial_data - connection.execute <<-SQL - insert into script_transactions (ckb_transaction_id, script_id) - select co.ckb_transaction_id, ls.script_id from cell_outputs co inner join lock_scripts ls on co.lock_script_id = ls.id where ls.script_id is not null - on conflict do nothing - SQL - - connection.execute <<-SQL - insert into script_transactions (ckb_transaction_id, script_id) - select co.ckb_transaction_id, ts.script_id from cell_outputs co inner join type_scripts ts on co.type_script_id = ts.id where ts.script_id is not null - on conflict do nothing - SQL - end - - def self.create_from_scripts(type_scripts_or_lock_scripts) - ls_ids = [] - ts_ids = [] - type_scripts_or_lock_scripts.each do |s| - if s.is_a?(TypeScript) - ts_ids << s.id - else - ls_ids << s.id - end - end - if ls_ids.present? - connection.execute <<-SQL - insert into script_transactions (ckb_transaction_id, script_id) - select ckb_transaction_id, script_id from lock_scripts ls - inner join ( - select co.ckb_transaction_id, co.lock_script_id - from cell_outputs co - where co.lock_script_id in (#{ls_ids.join(',')}) - ) as tmp on ls.id = tmp.lock_script_id - where ls.script_id is not null - on conflict do nothing - SQL - end - if ts_ids.present? - connection.execute <<-SQL - insert into script_transactions (ckb_transaction_id, script_id) - select ckb_transaction_id, script_id from type_scripts ts - inner join ( - select co.ckb_transaction_id, co.type_script_id - from cell_outputs co - where co.type_script_id in (#{ts_ids.join(',')}) - ) as tmp on ts.id = tmp.type_script_id - where ts.script_id is not null - on conflict do nothing - SQL - end - end -end - -# == Schema Information -# -# Table name: script_transactions -# -# id :bigint not null, primary key -# script_id :bigint not null -# ckb_transaction_id :bigint not null -# -# Indexes -# -# index_script_transactions_on_ckb_transaction_id (ckb_transaction_id) -# index_script_transactions_on_ckb_transaction_id_and_script_id (ckb_transaction_id,script_id) UNIQUE -# index_script_transactions_on_script_id (script_id) -# diff --git a/app/models/transaction_propagation_delay.rb b/app/models/transaction_propagation_delay.rb deleted file mode 100644 index 24b2c554c..000000000 --- a/app/models/transaction_propagation_delay.rb +++ /dev/null @@ -1,18 +0,0 @@ -class TransactionPropagationDelay < ApplicationRecord -end - -# == Schema Information -# -# Table name: transaction_propagation_delays -# -# id :bigint not null, primary key -# tx_hash :string -# created_at_unixtimestamp :integer -# durations :jsonb -# created_at :datetime not null -# updated_at :datetime not null -# -# Indexes -# -# index_tx_propagation_timestamp (created_at_unixtimestamp) -# diff --git a/app/models/type_script.rb b/app/models/type_script.rb index c0173ea2f..b4ee0db07 100644 --- a/app/models/type_script.rb +++ b/app/models/type_script.rb @@ -4,9 +4,6 @@ class TypeScript < ApplicationRecord belongs_to :cell_output, optional: true # will remove this later before_validation :generate_script_hash - belongs_to :script, optional: true - belongs_to :contract, optional: true, primary_key: "code_hash", foreign_key: "code_hash" - validates_presence_of :code_hash attribute :code_hash, :ckb_hash diff --git a/app/serializers/scripts_ckb_transactions_serializer.rb b/app/serializers/scripts_ckb_transactions_serializer.rb deleted file mode 100644 index 09a718b45..000000000 --- a/app/serializers/scripts_ckb_transactions_serializer.rb +++ /dev/null @@ -1,29 +0,0 @@ -class ScriptsCkbTransactionsSerializer - include FastJsonapi::ObjectSerializer - - def to_json(tx) - { - id: tx.id, - tx_hash: tx.tx_hash, - block_id: tx.block_id, - block_number: tx.block_number, - block_timestamp: tx.block_timestamp, - transaction_fee: tx.transaction_fee, - is_cellbase: tx.is_cellbase, - header_deps: tx.header_deps, - cell_deps: tx.cell_deps, - witnesses: tx.witnesses, - live_cell_changes: tx.live_cell_changes, - capacity_involved: tx.capacity_involved, - contained_address_ids: tx.contained_address_ids, - tags: tx.tags, - contained_udt_ids: tx.contained_udt_ids, - dao_address_ids: tx.contained_dao_address_ids, - udt_address_ids: tx.contained_udt_address_ids, - bytes: tx.bytes, - tx_status: tx.tx_status, - display_inputs: tx.display_inputs, - display_outputs: tx.display_outputs - } - end -end diff --git a/app/views/api/v2/scripts/deployed_cells.json.jbuilder b/app/views/api/v2/scripts/deployed_cells.json.jbuilder deleted file mode 100644 index ddf21033d..000000000 --- a/app/views/api/v2/scripts/deployed_cells.json.jbuilder +++ /dev/null @@ -1,29 +0,0 @@ -json.data do - json.deployed_cells @deployed_cells do |deployed_cell| - json.id deployed_cell.id - json.capacity deployed_cell.capacity - json.ckb_transaction_id deployed_cell.ckb_transaction_id - json.created_at deployed_cell.created_at - json.updated_at deployed_cell.updated_at - json.status deployed_cell.status - json.address_id deployed_cell.address_id - json.block_id deployed_cell.block_id - json.tx_hash deployed_cell.tx_hash - json.cell_index deployed_cell.cell_index - json.consumed_by_id deployed_cell.consumed_by_id - json.cell_type deployed_cell.cell_type - json.data_size deployed_cell.data_size - json.occupied_capacity deployed_cell.occupied_capacity - json.block_timestamp deployed_cell.block_timestamp - json.consumed_block_timestamp deployed_cell.consumed_block_timestamp - json.type_hash deployed_cell.type_hash - json.udt_amount deployed_cell.udt_amount - json.dao deployed_cell.dao - json.lock_script_id deployed_cell.lock_script_id - json.type_script_id deployed_cell.type_script_id - end - json.meta do - json.total @deployed_cells.total_count - json.page_size @page_size.to_i - end -end diff --git a/app/views/api/v2/scripts/referring_cells.json.jbuilder b/app/views/api/v2/scripts/referring_cells.json.jbuilder deleted file mode 100644 index c496c2e9e..000000000 --- a/app/views/api/v2/scripts/referring_cells.json.jbuilder +++ /dev/null @@ -1,29 +0,0 @@ -json.data do - json.referring_cells @referring_cells do |referring_cell| - json.id referring_cell.id - json.capacity referring_cell.capacity - json.ckb_transaction_id referring_cell.ckb_transaction_id - json.created_at referring_cell.created_at - json.updated_at referring_cell.updated_at - json.status referring_cell.status - json.address_id referring_cell.address_id - json.block_id referring_cell.block_id - json.tx_hash referring_cell.tx_hash - json.cell_index referring_cell.cell_index - json.consumed_by_id referring_cell.consumed_by_id - json.cell_type referring_cell.cell_type - json.data_size referring_cell.data_size - json.occupied_capacity referring_cell.occupied_capacity - json.block_timestamp referring_cell.block_timestamp - json.consumed_block_timestamp referring_cell.consumed_block_timestamp - json.type_hash referring_cell.type_hash - json.udt_amount referring_cell.udt_amount - json.dao referring_cell.dao - json.lock_script_id referring_cell.lock_script_id - json.type_script_id referring_cell.type_script_id - end - json.meta do - json.total @referring_cells.total_count - json.page_size @page_size.to_i - end -end diff --git a/db/migrate/20241205023729_drop_scripts_and_scripts_transactions.rb b/db/migrate/20241205023729_drop_scripts_and_scripts_transactions.rb new file mode 100644 index 000000000..a37b268ae --- /dev/null +++ b/db/migrate/20241205023729_drop_scripts_and_scripts_transactions.rb @@ -0,0 +1,9 @@ +class DropScriptsAndScriptsTransactions < ActiveRecord::Migration[7.0] + def change + drop_table :scripts, if_exists: true + drop_table :script_transactions, if_exists: true + drop_table :deployed_cells, if_exists: true + drop_table :referring_cells, if_exists: true + drop_table :transaction_propagation_delays, if_exists: true + end +end diff --git a/db/structure.sql b/db/structure.sql index bbe7b508d..8cb05c305 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1654,38 +1654,6 @@ CREATE SEQUENCE public.dao_events_id_seq ALTER SEQUENCE public.dao_events_id_seq OWNED BY public.dao_events.id; --- --- Name: deployed_cells; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.deployed_cells ( - id bigint NOT NULL, - cell_output_id bigint NOT NULL, - contract_id bigint NOT NULL, - created_at timestamp(6) without time zone NOT NULL, - updated_at timestamp(6) without time zone NOT NULL -); - - --- --- Name: deployed_cells_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.deployed_cells_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: deployed_cells_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.deployed_cells_id_seq OWNED BY public.deployed_cells.id; - - -- -- Name: epoch_statistics; Type: TABLE; Schema: public; Owner: - -- @@ -2103,39 +2071,6 @@ CREATE SEQUENCE public.portfolios_id_seq ALTER SEQUENCE public.portfolios_id_seq OWNED BY public.portfolios.id; --- --- Name: referring_cells; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.referring_cells ( - id bigint NOT NULL, - cell_output_id bigint, - contract_id bigint, - ckb_transaction_id bigint, - created_at timestamp(6) without time zone NOT NULL, - updated_at timestamp(6) without time zone NOT NULL -); - - --- --- Name: referring_cells_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.referring_cells_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: referring_cells_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.referring_cells_id_seq OWNED BY public.referring_cells.id; - - -- -- Name: reject_reasons; Type: TABLE; Schema: public; Owner: - -- @@ -2187,70 +2122,6 @@ CREATE TABLE public.schema_migrations ( ); --- --- Name: script_transactions; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.script_transactions ( - id bigint NOT NULL, - script_id bigint NOT NULL, - ckb_transaction_id bigint NOT NULL -); - - --- --- Name: script_transactions_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.script_transactions_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: script_transactions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.script_transactions_id_seq OWNED BY public.script_transactions.id; - - --- --- Name: scripts; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.scripts ( - id bigint NOT NULL, - args character varying, - script_hash character varying, - is_contract boolean DEFAULT false, - contract_id bigint, - created_at timestamp(6) without time zone NOT NULL, - updated_at timestamp(6) without time zone NOT NULL -); - - --- --- Name: scripts_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.scripts_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: scripts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.scripts_id_seq OWNED BY public.scripts.id; - - -- -- Name: statistic_infos; Type: TABLE; Schema: public; Owner: - -- @@ -2473,39 +2344,6 @@ CREATE SEQUENCE public.transaction_address_changes_id_seq ALTER SEQUENCE public.transaction_address_changes_id_seq OWNED BY public.transaction_address_changes.id; --- --- Name: transaction_propagation_delays; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.transaction_propagation_delays ( - id bigint NOT NULL, - tx_hash character varying, - created_at_unixtimestamp integer, - durations jsonb, - created_at timestamp(6) without time zone NOT NULL, - updated_at timestamp(6) without time zone NOT NULL -); - - --- --- Name: transaction_propagation_delays_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.transaction_propagation_delays_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: transaction_propagation_delays_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.transaction_propagation_delays_id_seq OWNED BY public.transaction_propagation_delays.id; - - -- -- Name: type_scripts; Type: TABLE; Schema: public; Owner: - -- @@ -3094,13 +2932,6 @@ ALTER TABLE ONLY public.dao_contracts ALTER COLUMN id SET DEFAULT nextval('publi ALTER TABLE ONLY public.dao_events ALTER COLUMN id SET DEFAULT nextval('public.dao_events_id_seq'::regclass); --- --- Name: deployed_cells id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.deployed_cells ALTER COLUMN id SET DEFAULT nextval('public.deployed_cells_id_seq'::regclass); - - -- -- Name: epoch_statistics id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3171,13 +3002,6 @@ ALTER TABLE ONLY public.omiga_inscription_infos ALTER COLUMN id SET DEFAULT next ALTER TABLE ONLY public.portfolios ALTER COLUMN id SET DEFAULT nextval('public.portfolios_id_seq'::regclass); --- --- Name: referring_cells id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.referring_cells ALTER COLUMN id SET DEFAULT nextval('public.referring_cells_id_seq'::regclass); - - -- -- Name: reject_reasons id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3185,20 +3009,6 @@ ALTER TABLE ONLY public.referring_cells ALTER COLUMN id SET DEFAULT nextval('pub ALTER TABLE ONLY public.reject_reasons ALTER COLUMN id SET DEFAULT nextval('public.reject_reasons_id_seq'::regclass); --- --- Name: script_transactions id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.script_transactions ALTER COLUMN id SET DEFAULT nextval('public.script_transactions_id_seq'::regclass); - - --- --- Name: scripts id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.scripts ALTER COLUMN id SET DEFAULT nextval('public.scripts_id_seq'::regclass); - - -- -- Name: statistic_infos id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3241,13 +3051,6 @@ ALTER TABLE ONLY public.token_transfers ALTER COLUMN id SET DEFAULT nextval('pub ALTER TABLE ONLY public.transaction_address_changes ALTER COLUMN id SET DEFAULT nextval('public.transaction_address_changes_id_seq'::regclass); --- --- Name: transaction_propagation_delays id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.transaction_propagation_delays ALTER COLUMN id SET DEFAULT nextval('public.transaction_propagation_delays_id_seq'::regclass); - - -- -- Name: type_scripts id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3631,14 +3434,6 @@ ALTER TABLE ONLY public.dao_events ADD CONSTRAINT dao_events_pkey PRIMARY KEY (id); --- --- Name: deployed_cells deployed_cells_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.deployed_cells - ADD CONSTRAINT deployed_cells_pkey PRIMARY KEY (id); - - -- -- Name: epoch_statistics epoch_statistics_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -3719,14 +3514,6 @@ ALTER TABLE ONLY public.portfolios ADD CONSTRAINT portfolios_pkey PRIMARY KEY (id); --- --- Name: referring_cells referring_cells_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.referring_cells - ADD CONSTRAINT referring_cells_pkey PRIMARY KEY (id); - - -- -- Name: reject_reasons reject_reasons_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -3743,22 +3530,6 @@ ALTER TABLE ONLY public.schema_migrations ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version); --- --- Name: script_transactions script_transactions_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.script_transactions - ADD CONSTRAINT script_transactions_pkey PRIMARY KEY (id); - - --- --- Name: scripts scripts_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.scripts - ADD CONSTRAINT scripts_pkey PRIMARY KEY (id); - - -- -- Name: statistic_infos statistic_infos_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -3807,14 +3578,6 @@ ALTER TABLE ONLY public.transaction_address_changes ADD CONSTRAINT transaction_address_changes_pkey PRIMARY KEY (id); --- --- Name: transaction_propagation_delays transaction_propagation_delays_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.transaction_propagation_delays - ADD CONSTRAINT transaction_propagation_delays_pkey PRIMARY KEY (id); - - -- -- Name: type_scripts type_scripts_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -4779,20 +4542,6 @@ CREATE INDEX index_dao_events_on_block_timestamp ON public.dao_events USING btre CREATE INDEX index_dao_events_on_status_and_event_type ON public.dao_events USING btree (status, event_type); --- --- Name: index_deployed_cells_on_cell_output_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX index_deployed_cells_on_cell_output_id ON public.deployed_cells USING btree (cell_output_id); - - --- --- Name: index_deployed_cells_on_contract_id_and_cell_output_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX index_deployed_cells_on_contract_id_and_cell_output_id ON public.deployed_cells USING btree (contract_id, cell_output_id); - - -- -- Name: index_epoch_statistics_on_epoch_number; Type: INDEX; Schema: public; Owner: - -- @@ -4905,13 +4654,6 @@ CREATE INDEX index_on_cell_dependencies_contract_cell_block_tx ON public.cell_de CREATE UNIQUE INDEX index_portfolios_on_user_id_and_address_id ON public.portfolios USING btree (user_id, address_id); --- --- Name: index_referring_cells_on_contract_id_and_cell_output_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX index_referring_cells_on_contract_id_and_cell_output_id ON public.referring_cells USING btree (contract_id, cell_output_id); - - -- -- Name: index_reject_reasons_on_ckb_transaction_id; Type: INDEX; Schema: public; Owner: - -- @@ -4926,34 +4668,6 @@ CREATE UNIQUE INDEX index_reject_reasons_on_ckb_transaction_id ON public.reject_ CREATE UNIQUE INDEX index_rolling_avg_block_time_on_timestamp ON public.rolling_avg_block_time USING btree ("timestamp"); --- --- Name: index_script_transactions_on_ckb_transaction_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_script_transactions_on_ckb_transaction_id ON public.script_transactions USING btree (ckb_transaction_id); - - --- --- Name: index_script_transactions_on_ckb_transaction_id_and_script_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX index_script_transactions_on_ckb_transaction_id_and_script_id ON public.script_transactions USING btree (ckb_transaction_id, script_id); - - --- --- Name: index_script_transactions_on_script_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_script_transactions_on_script_id ON public.script_transactions USING btree (script_id); - - --- --- Name: index_scripts_on_contract_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_scripts_on_contract_id ON public.scripts USING btree (contract_id); - - -- -- Name: index_table_record_counts_on_table_name_and_count; Type: INDEX; Schema: public; Owner: - -- @@ -5045,13 +4759,6 @@ CREATE INDEX index_token_transfers_on_transaction_id ON public.token_transfers U CREATE INDEX index_transaction_address_changes_on_ckb_transaction_id ON public.transaction_address_changes USING btree (ckb_transaction_id); --- --- Name: index_tx_propagation_timestamp; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_tx_propagation_timestamp ON public.transaction_propagation_delays USING btree (created_at_unixtimestamp); - - -- -- Name: index_type_scripts_on_cell_output_id; Type: INDEX; Schema: public; Owner: - -- @@ -6026,6 +5733,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20241121073245'), ('20241125100650'), ('20241129000339'), -('20241202072604'); +('20241202072604'), +('20241205023729'); diff --git a/lib/tasks/migration/generate_referring_cells.rake b/lib/tasks/migration/generate_referring_cells.rake deleted file mode 100644 index 9de2d6a81..000000000 --- a/lib/tasks/migration/generate_referring_cells.rake +++ /dev/null @@ -1,54 +0,0 @@ -namespace :migration do - desc "Usage: RAILS_ENV=production bundle exec rake migration:generate_referring_cells" - task generate_referring_cells: :environment do - live_cells = CellOutput.live.left_joins(:referring_cell).where(referring_cells: { id: nil }) - progress_bar = ProgressBar.create({ total: live_cells.count, - format: "%e %B %p%% %c/%C" }) - - live_cells.find_in_batches do |outputs| - outputs.each do |output| - progress_bar.increment - - contracts = [output.lock_script.contract, - output.type_script&.contract].compact - - next if contracts.empty? - - contracts.each do |contract| - ReferringCell.create_or_find_by( - cell_output_id: output.id, - ckb_transaction_id: output.ckb_transaction_id, - contract_id: contract.id, - ) - end - end - end - - puts "done" - end - - desc "Usage: RAILS_ENV=production bundle exec rake migration:generate_missed_type_script_contract_referring_cells" - task generate_missed_type_script_contract_referring_cells: :environment do - contract_hashes = Contract.where(role: "type_script").pluck(:code_hash) - binary_hashes = CkbUtils.hexes_to_bins_sql(contract_hashes) - contract_type_ids = TypeScript.where("code_hash IN (#{binary_hashes})").pluck(:id) - contract_type_ids.each do |type_id| - puts "============#{type_id}" - live_cells = CellOutput.live.where(type_script_id: type_id) - - live_cells.find_in_batches do |outputs| - outputs.each do |output| - contract = output.type_script&.contract - - ReferringCell.create_or_find_by( - cell_output_id: output.id, - ckb_transaction_id: output.ckb_transaction_id, - contract_id: contract.id, - ) - end - end - end - - puts "done" - end -end diff --git a/test/jobs/import_transaction_job_test.rb b/test/jobs/import_transaction_job_test.rb deleted file mode 100644 index dd535afe2..000000000 --- a/test/jobs/import_transaction_job_test.rb +++ /dev/null @@ -1,138 +0,0 @@ -require "test_helper" - -class ImportTransactionJobTest < ActiveJob::TestCase - # test "the truth" do - # assert true - # end - - # setup the previous cell outputs and contract that the raw tx requires - setup do - end - - test "import normal ckb transaction" do - @cell_base_transaction = create :ckb_transaction, :with_single_output - @cell_base = @cell_base_transaction.cell_outputs.first - @raw_tx = { - "cell_deps" => - [ - { - "dep_type" => "code", - "out_point" => { - "index" => "0x3", - "tx_hash" => "0x8f8c79eb6671709633fe6a46de93c0fedc9c1b8a6527a18d3983879542635c9f" } }, - { - "dep_type" => "code", - "out_point" => { - "index" => "0x1", - "tx_hash" => "0x8f8c79eb6671709633fe6a46de93c0fedc9c1b8a6527a18d3983879542635c9f" } } - ], - "hash" => "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37", - "header_deps" => [], - "inputs" => [ - { - "previous_output" => { - "index" => CkbUtils.int_to_hex(@cell_base.cell_index), - "tx_hash" => @cell_base_transaction.tx_hash - }, - "since" => "0x0" - } - ], - "outputs" => - [ - { - "capacity" => CkbUtils.int_to_hex(10**8 * 4), - "lock" => { - "args" => "0x57ccb07be6875f61d93636b0ee11b675494627d2", - "code_hash" => "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", - "hash_type" => "type" - }, - "type" => nil - }, - { - "capacity" => CkbUtils.int_to_hex(10**8 * 4 - 1), - "lock" => { - "args" => "0x64257f00b6b63e987609fa9be2d0c86d351020fb", - "code_hash" => "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", - "hash_type" => "type" - }, - "type" => nil - } - ], - "outputs_data" => [], - "version" => "0x0", - "witnesses" => [ - "0x55f49d7979ba246aa2f05a6e9afd25a23dc39ed9085a0b1e33b6b3bb80d34dbd4031a04ea389d6d8ff5604828889aa06a827e930a7e89411b80f6c3e1404951f00" - ] - } - ImportTransactionJob.new.perform @raw_tx - assert_equal 2, CkbTransaction.count - assert_equal 1, CellInput.count - assert_equal 3, CellOutput.count - assert_equal 4, Address.count - assert_equal 4, AccountBook.count - end - - test "import transaction which wants to consume non-exists cells" do - # this will halt the import process, only leave a pending transaction - raw_tx = { - "cell_deps" => - [ - { - "dep_type" => "code", - "out_point" => { - "index" => "0x3", - "tx_hash" => "0x8f8c79eb6671709633fe6a46de93c0fedc9c1b8a6527a18d3983879542635c9f" } }, - { - "dep_type" => "code", - "out_point" => { - "index" => "0x1", - "tx_hash" => "0x8f8c79eb6671709633fe6a46de93c0fedc9c1b8a6527a18d3983879542635c9f" } } - ], - "hash" => "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37", - "header_deps" => [], - "inputs" => [ - { - "previous_output" => { - "index" => "0x0", - "tx_hash" => "0x519c09b28e1170b8ee89523b75965dae2f7dd209e88c98008286e996bad46e07" - }, - "since" => "0x0" - } - ], - "outputs" => - [ - { - "capacity" => CkbUtils.int_to_hex(10**8 * 4), - "lock" => { - "args" => "0x57ccb07be6875f61d93636b0ee11b675494627d2", - "code_hash" => "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", - "hash_type" => "type" - }, - "type" => nil - }, - { - "capacity" => CkbUtils.int_to_hex(10**8 * 4 - 1), - "lock" => { - "args" => "0x64257f00b6b63e987609fa9be2d0c86d351020fb", - "code_hash" => "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", - "hash_type" => "type" - }, - "type" => nil - } - ], - "outputs_data" => [], - "version" => "0x0", - "witnesses" => [ - "0x55f49d7979ba246aa2f05a6e9afd25a23dc39ed9085a0b1e33b6b3bb80d34dbd4031a04ea389d6d8ff5604828889aa06a827e930a7e89411b80f6c3e1404951f00" - ] - } - - assert_difference -> { CkbTransaction.count } => 1, - -> { CellInput.count } => 1, - -> { CellOutput.count } => 2, - -> { AccountBook.count } => 2, - -> { Address.count } => 2 do - ImportTransactionJob.new.perform raw_tx - end - end -end diff --git a/test/models/cell_output_test.rb b/test/models/cell_output_test.rb index 54f62a353..73b62c66d 100644 --- a/test/models/cell_output_test.rb +++ b/test/models/cell_output_test.rb @@ -6,7 +6,6 @@ class CellOutputTest < ActiveSupport::TestCase should belong_to(:address) # should belong_to(:block) should have_many(:cell_dependencies) - # should have_many(:referring_cells) end context "validations" do @@ -17,14 +16,14 @@ class CellOutputTest < ActiveSupport::TestCase test "should have cell_type column" do block = create(:block) - cell_output = create(:cell_output, :with_full_transaction, block: block) + cell_output = create(:cell_output, :with_full_transaction, block:) assert_equal "normal", cell_output.cell_type end test "#to_raw should contain correct keys" do block = create(:block) - cell_output = create(:cell_output, :with_full_transaction, block: block) + cell_output = create(:cell_output, :with_full_transaction, block:) raw = cell_output.to_raw assert_equal %i(capacity lock type).sort, raw.keys.sort assert_equal raw[:lock][:code_hash], cell_output.lock_script.code_hash diff --git a/test/models/ckb_transaction_test.rb b/test/models/ckb_transaction_test.rb index e886069a5..41e589cb8 100644 --- a/test/models/ckb_transaction_test.rb +++ b/test/models/ckb_transaction_test.rb @@ -15,7 +15,6 @@ class CkbTransactionTest < ActiveSupport::TestCase context "associations" do # should belong_to(:block, required: false) should have_many(:account_books) - should have_many(:referring_cells) should have_many(:addresses).through(:account_books) should have_many(:cell_inputs) should have_many(:cell_outputs) diff --git a/test/models/deployed_cell_test.rb b/test/models/deployed_cell_test.rb deleted file mode 100644 index 06ba4d5a4..000000000 --- a/test/models/deployed_cell_test.rb +++ /dev/null @@ -1,172 +0,0 @@ -require "test_helper" - -# class DeployedCellTest < ActiveSupport::TestCase -# context "associations" do -# should belong_to(:contract) -# should belong_to(:cell_output) -# end - -# setup do -# @block = create :block, :with_block_hash -# @ckb_transaction = create :ckb_transaction, :with_multiple_inputs_and_outputs, block_id: @block.id - -# code_hash = "0x671ddda336db68ce0daebde885f44e2f46406d6c838484b4bd8934173e518876" -# @cell_output = create :cell_output, :with_full_transaction, ckb_transaction_id: @ckb_transaction.id, block: @block, -# data: "0x", data_hash: code_hash -# @contract = create :contract -# @deployed_cell = create :deployed_cell, contract_id: @contract.id, cell_output_id: @cell_output.id -# CellOutput.stubs(:find_by_pointer).returns(@cell_output) -# CellOutput.any_instance.stubs(:data_hash).returns(code_hash) -# CellOutput.any_instance.stubs(:type_hash).returns(code_hash) -# end - -# test "it should create deployed_cell" do -# assert_equal @cell_output.id, @deployed_cell.cell_output_id -# assert_equal @contract.id, @deployed_cell.contract_id -# end - -# test "it should create_initial_data_for_ckb_transaction for cell_outputs when hash_type is type" do -# # step 1 delete redundant data -# delete_redundant_data - -# # step 2 prepare test data -# prepare_test_data_for_hash_type_for_cell_outputs - -# # step 3 start unit test -# # for the 1st time, it will create -# DeployedCell.create_initial_data_for_ckb_transaction @ckb_transaction_with_cell_deps, @cell_deps -# @deployed_cell = DeployedCell.first -# contract_id = @ckb_transaction_with_cell_deps.cell_outputs.first.lock_script.script.contract_id -# assert_equal 1, DeployedCell.all.count -# assert_equal contract_id, @deployed_cell.contract_id - -# # for the 2nd time, it should NOT create record -# DeployedCell.create_initial_data_for_ckb_transaction @ckb_transaction_with_cell_deps, @cell_deps -# assert_equal 1, DeployedCell.all.count -# end - -# test "it should create_initial_data_for_ckb_transaction for cell_outputs when hash_type is data" do -# # step 1 delete redundant data -# delete_redundant_data -# # step 2 prepare test data -# prepare_test_data_for_hash_type_for_cell_outputs hash_type: "data" -# # step 3 start unit test -# # for the 1st time, it will create -# DeployedCell.create_initial_data_for_ckb_transaction @ckb_transaction_with_cell_deps, @cell_deps -# @deployed_cell = DeployedCell.first -# contract_id = @ckb_transaction_with_cell_deps.cell_outputs.first.lock_script.script.contract_id -# assert_equal 1, DeployedCell.all.count -# assert_equal contract_id, @deployed_cell.contract_id - -# # for the 2nd time, it should NOT create record -# # DeployedCell.create_initial_data_for_ckb_transaction @ckb_transaction_with_cell_deps -# assert_equal 1, DeployedCell.all.count -# end - -# test "it should create_initial_data_for_ckb_transaction for cell_inputs when hash_type is type" do -# # step 1 delete redundant data -# delete_redundant_data - -# # step 2 prepare test data -# prepare_test_data_for_hash_type_for_cell_inputs - -# # step 3 start unit test -# # for the 1st time, it will create -# # DeployedCell.create_initial_data_for_ckb_transaction @ckb_transaction_with_cell_deps -# @deployed_cell = DeployedCell.first -# contract_id = @ckb_transaction_with_cell_deps.cell_inputs.first.previous_cell_output.lock_script.script.contract_id -# assert_equal contract_id, @deployed_cell.contract_id -# assert_equal 1, DeployedCell.all.count - -# # for the 2nd time, it should NOT create record -# DeployedCell.create_initial_data_for_ckb_transaction @ckb_transaction_with_cell_deps, @cell_deps -# assert_equal 1, DeployedCell.all.count -# end - -# test "it should create_initial_data_for_ckb_transaction for cell_inputs when hash_type is data" do -# # step 1 delete redundant data -# delete_redundant_data -# # step 2 prepare test data -# prepare_test_data_for_hash_type_for_cell_inputs hash_type: "data" -# # step 3 start unit test -# # for the 1st time, it will create -# # DeployedCell.create_initial_data_for_ckb_transaction @ckb_transaction_with_cell_deps, @cell_deps -# @deployed_cell = DeployedCell.first -# contract_id = @ckb_transaction_with_cell_deps.cell_inputs.first.previous_cell_output.lock_script.script.contract_id -# assert_equal contract_id, @deployed_cell.contract_id -# assert_equal 1, DeployedCell.all.count - -# # for the 2nd time, it should NOT create record -# DeployedCell.create_initial_data_for_ckb_transaction @ckb_transaction_with_cell_deps, @cell_deps -# assert_equal 1, DeployedCell.all.count -# end - -# private - -# def delete_redundant_data -# Script.delete_all -# ScriptTransaction.delete_all -# Contract.delete_all -# DeployedCell.delete_all -# CkbTransaction.delete_all -# Block.delete_all -# end - -# def prepare_test_data_for_hash_type_for_cell_outputs(hash_type: "type") -# @contract = create :contract, hash_type: hash_type -# # CKB::Blake2b.hexdigest('0x010200000000008d01f3') -# @deployed_cell = @contract.deployed_cells.first -# code_hash = @contract.code_hash -# tx_hash = @deployed_cell.cell_output.ckb_transaction.tx_hash -# cell_deps = @cell_deps = [ -# { -# "dep_type" => "code", -# "out_point" => { -# "index" => @deployed_cell.cell_output.cell_index, -# "tx_hash" => tx_hash } } -# ] - -# block = create :block, :with_block_hash -# @ckb_transaction_with_cell_deps = create :ckb_transaction, block: block, cell_deps: cell_deps -# CkbTransaction.where("id < ?", @ckb_transaction_with_cell_deps.id).delete_all -# script = create :script, contract_id: @contract.id, is_contract: true -# type_script = create :type_script, code_hash: code_hash, hash_type: hash_type, script: script -# lock_script = create :lock_script, code_hash: code_hash, hash_type: hash_type, script: script -# # create test data: cell_outputs -# cell_output = create :cell_output, block: block, ckb_transaction: @ckb_transaction_with_cell_deps, -# lock_script: lock_script, type_script: type_script -# end - -# def prepare_test_data_for_hash_type_for_cell_inputs(hash_type: "type") -# @contract = create :contract, hash_type: hash_type -# @deployed_cell = @contract.deployed_cells.first -# code_hash = @contract.code_hash -# tx_hash = @deployed_cell.cell_output.ckb_transaction.tx_hash -# cell_deps = @cell_deps = [ -# { -# "dep_type" => "code", -# "out_point" => { -# "index" => @deployed_cell.cell_output.cell_index, -# "tx_hash" => tx_hash } } -# ] - -# block = create :block, :with_block_hash -# @ckb_transaction_with_cell_deps = create :ckb_transaction, block: block, cell_deps: cell_deps -# CkbTransaction.where("id < ?", @ckb_transaction_with_cell_deps.id).delete_all -# script = create :script, contract_id: @contract.id, is_contract: true -# type_script = create :type_script, code_hash: code_hash, hash_type: hash_type, script_id: script.id -# lock_script = create :lock_script, code_hash: code_hash, hash_type: hash_type, script_id: script.id -# # create test data: cell_outputs -# cell_output = create :cell_output, block: block, ckb_transaction: @ckb_transaction_with_cell_deps, -# lock_script: lock_script, type_script: type_script -# temp_ckb_transaction = CkbTransaction.first -# temp_ckb_transaction.update tx_hash: tx_hash -# temp_cell_output = create :cell_output, :with_full_transaction, block: block, ckb_transaction: temp_ckb_transaction -# temp_cell_output.lock_script.update script_id: script.id - -# cell_input = create :cell_input, :with_full_transaction, block: block, -# ckb_transaction: @ckb_transaction_with_cell_deps -# cell_input.update ckb_transaction_id: @ckb_transaction_with_cell_deps.id, previous_cell_output_id: cell_output.id -# cell_input.previous_cell_output.lock_script.update script_id: script.id -# end -# end diff --git a/test/models/referring_cell_test.rb b/test/models/referring_cell_test.rb deleted file mode 100644 index 09c6aac57..000000000 --- a/test/models/referring_cell_test.rb +++ /dev/null @@ -1,30 +0,0 @@ -require "test_helper" - -class ReferringCellTest < ActiveSupport::TestCase - context "associations" do - should belong_to(:ckb_transaction) - should belong_to(:contract) - should belong_to(:cell_output) - end - - setup do - @block = create(:block, :with_block_hash) - @ckb_transaction = create(:ckb_transaction, :with_multiple_inputs_and_outputs, block_id: @block.id) - @cell_output = create(:cell_output, :with_full_transaction, ckb_transaction_id: @ckb_transaction.id, block: @block) - @contract = create :contract - @referring_cell = create :referring_cell, ckb_transaction_id: @ckb_transaction.id, cell_output_id: @cell_output.id, contract_id: @contract.id - end - - test "it should create referring_cell" do - assert_equal @cell_output.id, @referring_cell.cell_output_id - assert_equal @contract.id, @referring_cell.contract_id - assert_equal @ckb_transaction.id, @referring_cell.ckb_transaction_id - end - - test "it should belongs_to ckb_transaction, cell_output and contract" do - assert_equal @cell_output, @referring_cell.cell_output - assert_equal @contract, @referring_cell.contract - assert_equal @ckb_transaction, @referring_cell.ckb_transaction - end - -end diff --git a/test/models/script_test.rb b/test/models/script_test.rb deleted file mode 100644 index 308d54552..000000000 --- a/test/models/script_test.rb +++ /dev/null @@ -1,33 +0,0 @@ -require "test_helper" - -# class ScriptTest < ActiveSupport::TestCase -# setup do -# @script = create :script -# # create for @cell_dependency -# @block = create :block, :with_block_hash -# @ckb_transaction = create :ckb_transaction, :with_multiple_inputs_and_outputs, block: @block -# @cell_output = create :cell_output, :with_full_transaction, block: @block -# @cell_dependency = create :cell_dependency, ckb_transaction_id: @ckb_transaction.id, contract_cell_id: @cell_output.id, -# script_id: @script.id -# end - -# context "associations" do -# should have_many(:type_scripts) -# should have_many(:cell_dependencies) -# should have_many(:ckb_transactions) -# should have_many(:lock_scripts) -# should have_many(:script_transactions) -# end - -# test "create script" do -# assert_equal false, @script.is_contract -# assert_equal "0x34551bdd3db215970d4dd031146c4bb5adc74a1faea5c717773c1a72c8f01855", @script.script_hash -# end - -# test "update script" do -# @script.update is_contract: true, args: "0x441714e000fedf3247292c7f34fb16db14f49d9f1", script_hash: "0x34551bdd3db215970d4dd031146c4bb5adc74a1faea5c717773c1a72c8f018551" -# assert_equal true, @script.is_contract -# assert_equal "0x441714e000fedf3247292c7f34fb16db14f49d9f1", @script.args -# assert_equal "0x34551bdd3db215970d4dd031146c4bb5adc74a1faea5c717773c1a72c8f018551", @script.script_hash -# end -# end diff --git a/test/models/script_transaction_test.rb b/test/models/script_transaction_test.rb deleted file mode 100644 index a83aed7b0..000000000 --- a/test/models/script_transaction_test.rb +++ /dev/null @@ -1,61 +0,0 @@ -require "test_helper" - -# class ScriptTransactionTest < ActiveSupport::TestCase -# setup do -# @contract = create :contract -# @block = create(:block, :with_block_hash) -# @script = create :script, contract_id: @contract.id -# @ckb_transaction = create(:ckb_transaction, :with_multiple_inputs_and_outputs, block: @block) -# @script_transaction = create :script_transaction, script_id: @script.id, ckb_transaction_id: @ckb_transaction.id -# end - -# context "associations" do -# should belong_to(:script) -# should belong_to(:ckb_transaction) -# end - -# test "it should create script_transaction" do -# assert_equal @ckb_transaction.id, @script_transaction.ckb_transaction_id -# assert_equal @script.id, @script_transaction.script_id -# end - -# test "it should update script_transaction" do -# @script_transaction.update ckb_transaction_id: @ckb_transaction.id - 1, script_id: @script.id - 1 -# assert_equal @ckb_transaction.id - 1, @script_transaction.ckb_transaction_id -# assert_equal @script.id - 1, @script_transaction.script_id -# end - -# test "it should create_initial_data" do -# TypeScript.delete_all -# LockScript.delete_all -# Script.delete_all -# ScriptTransaction.delete_all -# Block.delete_all -# Contract.delete_all -# CellOutput.delete_all - -# hash_type = 'type' -# code_hash = "0x1c04df09d9adede5bfc40ff1a39a3a17fc8e29f15c56f16b7e48680c600ee5ac" -# contract = create :contract, code_hash: code_hash, hash_type: hash_type -# block = create :block, :with_block_hash -# ckb_transaction = create(:ckb_transaction, :with_multiple_inputs_and_outputs, block: block) -# CkbTransaction.where('id > ?', ckb_transaction.id).delete_all -# script = create :script -# type_script = create :type_script, code_hash: code_hash, hash_type: hash_type, script_id: script.id -# lock_script = create :lock_script, code_hash: code_hash, hash_type: hash_type, script_id: script.id -# cell_output = create :cell_output, :with_full_transaction, block_id: block.id -# cell_output.update lock_script_id: lock_script.id, type_script_id: type_script.id, ckb_transaction_id: ckb_transaction.id - -# # for the 1st time, it will create -# ScriptTransaction.create_initial_data -# @script_transaction = ScriptTransaction.first -# assert_equal 1, ScriptTransaction.all.count -# assert_equal ckb_transaction.id, @script_transaction.ckb_transaction_id -# assert_equal script.id, @script_transaction.script_id - -# # for the 2nd time, it should NOT create new record -# ScriptTransaction.create_initial_data -# assert_equal 1, ScriptTransaction.all.count -# end - -# end