Skip to content

Commit

Permalink
Merge pull request #2011 from nervosnetwork/testnet
Browse files Browse the repository at this point in the history
Deploy to mainnet
  • Loading branch information
rabbitz authored Jun 28, 2024
2 parents 8382c4a + bf445ba commit 9e605fa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
10 changes: 6 additions & 4 deletions app/jobs/import_btc_time_cells_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def perform(cell_ids)
end
rescue StandardError => e
Rails.logger.error("ImportBtcTimeCells failed: #{e.message}")
Rails.logger.error("Backtrace:\n#{e.backtrace.join("\n")}")
end

def build_utxo_map(cell_outputs)
Expand Down Expand Up @@ -61,7 +62,7 @@ def fetch_raw_transactions!(utxo_map)
end

def build_transactions!(cell_outputs, raw_tx_data, utxo_map)
transaction_attributes = []
transaction_attributes = {}

cell_outputs.each do |cell_output|
txid = utxo_map[cell_output.id]
Expand All @@ -70,7 +71,7 @@ def build_transactions!(cell_outputs, raw_tx_data, utxo_map)
next unless raw_tx

created_at = Time.at((cell_output.block_timestamp / 1000).to_i).in_time_zone
transaction_attributes << {
transaction_attributes[txid] = {
txid: raw_tx["txid"],
tx_hash: raw_tx["hash"],
time: raw_tx["time"],
Expand All @@ -80,8 +81,9 @@ def build_transactions!(cell_outputs, raw_tx_data, utxo_map)
}
end

BitcoinTransaction.upsert_all(transaction_attributes, unique_by: :txid)
BitcoinTransaction.where(txid: transaction_attributes.map { _1[:txid] }).index_by(&:txid)
unique_transaction_attributes = transaction_attributes.values
BitcoinTransaction.upsert_all(unique_transaction_attributes, unique_by: :txid)
BitcoinTransaction.where(txid: unique_transaction_attributes.map { |tx| tx[:txid] }).index_by(&:txid)
end

def rpc
Expand Down
15 changes: 9 additions & 6 deletions app/jobs/import_rgbpp_cells_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def perform(cell_ids)

# build op_returns
op_returns = build_op_returns!(raw_tx, tx, cell_output.ckb_transaction)
op_returns_attributes.concat(op_returns) if op_returns.present?
op_returns_attributes.concat(op_returns).uniq! if op_returns.present?

# build vouts
vout = build_vout!(raw_tx, tx, out_index, cell_output)
Expand Down Expand Up @@ -73,6 +73,7 @@ def perform(cell_ids)
end
rescue StandardError => e
Rails.logger.error("ImportRgbppCells failed: #{e.message}")
Rails.logger.error("Backtrace:\n#{e.backtrace.join("\n")}")
end

def build_utxo_map(cell_outputs)
Expand Down Expand Up @@ -101,16 +102,17 @@ def fetch_raw_transactions!(utxo_map)
end

def build_transactions!(cell_outputs, raw_tx_data, utxo_map)
transaction_attributes = []
transaction_attributes = {}

cell_outputs.each do |cell_output|
txid = utxo_map[cell_output.id][:txid]
utxo = utxo_map[cell_output.id]
txid = utxo[:txid]
raw_tx = raw_tx_data[txid]

next unless raw_tx

created_at = Time.at((cell_output.block_timestamp / 1000).to_i).in_time_zone
transaction_attributes << {
transaction_attributes[txid] = {
txid: raw_tx["txid"],
tx_hash: raw_tx["hash"],
time: raw_tx["time"],
Expand All @@ -120,8 +122,9 @@ def build_transactions!(cell_outputs, raw_tx_data, utxo_map)
}
end

BitcoinTransaction.upsert_all(transaction_attributes, unique_by: :txid)
BitcoinTransaction.where(txid: transaction_attributes.map { _1[:txid] }).index_by(&:txid)
unique_transaction_attributes = transaction_attributes.values
BitcoinTransaction.upsert_all(unique_transaction_attributes, unique_by: :txid)
BitcoinTransaction.where(txid: unique_transaction_attributes.map { |tx| tx[:txid] }).index_by(&:txid)
end

def build_op_returns!(raw_tx, tx, ckb_tx)
Expand Down

0 comments on commit 9e605fa

Please sign in to comment.