diff --git a/app/controllers/api/v1/address_pending_transactions_controller.rb b/app/controllers/api/v1/address_pending_transactions_controller.rb index 68632bf11..39edd539d 100644 --- a/app/controllers/api/v1/address_pending_transactions_controller.rb +++ b/app/controllers/api/v1/address_pending_transactions_controller.rb @@ -37,12 +37,7 @@ def pagination_params end def find_address - if BitcoinUtils.valid_address?(params[:id]) - bitcoin_address = BitcoinAddress.find_by(address_hash: params[:id]) - @address = bitcoin_address&.ckb_address - else - @address = Address.find_address!(params[:id]) - end + @address = Address.find_address!(params[:id]) raise Api::V1::Exceptions::AddressNotFoundError if @address.is_a?(NullAddress) end diff --git a/app/controllers/api/v1/address_transactions_controller.rb b/app/controllers/api/v1/address_transactions_controller.rb index 9f3ff1928..d2210a62e 100644 --- a/app/controllers/api/v1/address_transactions_controller.rb +++ b/app/controllers/api/v1/address_transactions_controller.rb @@ -78,13 +78,7 @@ def pagination_params end def find_address - if BitcoinUtils.valid_address?(params[:id]) - bitcoin_address = BitcoinAddress.find_by(address_hash: params[:id]) - @address = bitcoin_address&.ckb_address - else - @address = Address.find_address!(params[:id]) - end - + @address = Address.find_address!(params[:id]) raise Api::V1::Exceptions::AddressNotFoundError if @address.is_a?(NullAddress) end diff --git a/app/controllers/api/v2/ckb_transactions_controller.rb b/app/controllers/api/v2/ckb_transactions_controller.rb index f50cb55d2..772fcefd6 100644 --- a/app/controllers/api/v2/ckb_transactions_controller.rb +++ b/app/controllers/api/v2/ckb_transactions_controller.rb @@ -58,7 +58,7 @@ def rgb_digest vout = BitcoinVout.includes(:bitcoin_address).find_by(address_id:) next unless vout - { address: vout.bitcoin_address.address_hash, transfers: } + { address: vout&.bitcoin_address&.address_hash, transfers: } end vout = @ckb_transaction.bitcoin_vouts.find_by(op_return: true) diff --git a/app/models/address.rb b/app/models/address.rb index 438e1c61f..4c364830a 100644 --- a/app/models/address.rb +++ b/app/models/address.rb @@ -125,7 +125,12 @@ def self.find_or_create_address(lock_script, block_timestamp, lock_script_id = n end def self.find_address!(query_key) - cached_find(query_key) || raise(Api::V1::Exceptions::AddressNotFoundError) + if BitcoinUtils.valid_address?(query_key) + bitcoin_address = BitcoinAddress.find_by(address_hash: query_key) + bitcoin_address ? bitcoin_address.ckb_address : NullAddress.new(query_key) + else + cached_find(query_key) || raise(Api::V1::Exceptions::AddressNotFoundError) + end end def self.cached_find(query_key) diff --git a/lib/scheduler.rb b/lib/scheduler.rb index 3ac8ab08e..71cc292b7 100644 --- a/lib/scheduler.rb +++ b/lib/scheduler.rb @@ -121,7 +121,7 @@ def call_worker(clz) call_worker ContractStatisticWorker end -s.every "10m", overlap: false do +s.every "4m", overlap: false do call_worker SyncBitcoinTransactionTxidsWorker end