Skip to content

Commit

Permalink
chore: update bitcoin txids cache key (#1674)
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz authored Mar 13, 2024
1 parent 0c0c7b8 commit bc79d09
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/workers/bitcoin_transaction_detect_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def build_vout_attributes!(raw_tx, tx)

def get_txid(cell)
number = cell.ckb_transaction.block_number
txids = Kredis.unique_list "bitcoin_#{number}"
txids = Kredis.unique_list "bitcoin_#{number / 20}"
txid = txids.elements[0]

raise ArgumentError, "Get rgb cell txid error" unless txid
Expand Down
12 changes: 5 additions & 7 deletions app/workers/sync_bitcoin_transaction_txids_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ class SyncBitcoinTransactionTxidsWorker
sidekiq_options queue: "bitcoin"

def perform
txids = Kredis.unique_list "bitcoin_#{tip_block_number}"
tip_block_number = StatisticInfo.default.tip_block_number
# The synchronization ratio of Bitcoin blocks
bitcoin_block_number = tip_block_number / 20
txids = Kredis.unique_list "bitcoin_#{bitcoin_block_number}"
return if txids.elements.present?

block_hash = rpc.getblockhash(tip_block_number / 20)
block_hash = rpc.getblockhash(bitcoin_block_number)
# verbose set to 1 for JSON object
block = rpc.getblock(block_hash, 1)
txids.append(block["tx"].slice(1..-1))
end

private

def tip_block_number
# The synchronization ratio of Bitcoin blocks
@number ||= StatisticInfo.default.tip_block_number
end

def rpc
@rpc ||= Bitcoin::Rpc.instance
end
Expand Down

0 comments on commit bc79d09

Please sign in to comment.