Skip to content

Commit

Permalink
refactor: fetch multi raw bitcoin transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz committed Mar 26, 2024
1 parent b4f7fa8 commit 160627d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions app/controllers/api/v2/bitcoin_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ def query
not_cached = cache_keys - res.keys
to_cache = {}

get_raw_transactions(not_cached).each do |tx|
next if tx.dig("error").present?
if not_cached.present?
get_raw_transactions(not_cached).each do |tx|
next if tx.dig("error").present?

txid = tx.dig("result", "txid")
res[txid] = tx
to_cache[txid] = tx
txid = tx.dig("result", "txid")
res[txid] = tx
to_cache[txid] = tx
end
end

Rails.cache.write_multi(to_cache, expires_in: 10.minutes) unless to_cache.empty?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v2/ckb_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def rgb_digest
end

op_return = @ckb_transaction.bitcoin_vouts.find_by(op_return: true)
bitcoin_transaction = BitcoinTransaction.includes(:bitcoin_vouts).find_by(bitcoin_vouts: { ckb_transaction_id: tx.id })
bitcoin_transaction = BitcoinTransaction.includes(:bitcoin_vouts).find_by(bitcoin_vouts: { ckb_transaction_id: @ckb_transaction.id })

render json: {
data: {
Expand Down

0 comments on commit 160627d

Please sign in to comment.