Skip to content

Commit

Permalink
chore: update bitcoin txid query (#1687)
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz authored Mar 19, 2024
1 parent bced8c5 commit b3c7109
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
3 changes: 1 addition & 2 deletions app/controllers/validations/suggest_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def query_key_format_must_be_correct
query_key_invalid =
!QueryKeyUtils.integer_string?(query_key) &&
!QueryKeyUtils.valid_hex?(query_key) &&
!QueryKeyUtils.valid_address?(query_key) &&
!QueryKeyUtils.valid_bitcoin_txid?(query_key)
!QueryKeyUtils.valid_address?(query_key)

if query_key.blank? || query_key_invalid
errors.add(:query_key, "query key is invalid")
Expand Down
8 changes: 4 additions & 4 deletions app/models/suggest_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ def find_record_by_query_key!
find_by_hex
elsif QueryKeyUtils.valid_address?(query_key)
find_cached_address
elsif QueryKeyUtils.valid_bitcoin_txid?(query_key)
find_bitcoin_transaction_by_txid
end

raise ActiveRecord::RecordNotFound if result.blank?
Expand Down Expand Up @@ -67,11 +65,13 @@ def find_by_hex
find_ckb_transaction_by_hash ||
find_address_by_lock_hash ||
find_udt_by_type_hash ||
find_type_script_by_type_id
find_type_script_by_type_id ||
find_bitcoin_transaction_by_txid
end

def find_bitcoin_transaction_by_txid
bitcoin_transaction = BitcoinTransaction.find_by(txid: query_key)
txid = query_key.delete_prefix(Settings.default_hash_prefix)
bitcoin_transaction = BitcoinTransaction.find_by(txid:)
BitcoinTransactionSerializer.new(bitcoin_transaction) if bitcoin_transaction
end
end
4 changes: 0 additions & 4 deletions app/utils/query_key_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,5 @@ def valid_address?(query_key)
rescue StandardError
nil
end

def valid_bitcoin_txid?(query_key)
BitcoinTransaction.exists?(txid: query_key)
end
end
end

0 comments on commit b3c7109

Please sign in to comment.