Skip to content

Commit

Permalink
feat: filter by bitcoin address (#1677)
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz authored Mar 14, 2024
1 parent 675a342 commit d88f0c1
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions app/controllers/api/v1/address_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

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 @@ -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)

Expand Down
7 changes: 6 additions & 1 deletion app/models/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d88f0c1

Please sign in to comment.