Skip to content

Commit

Permalink
chore: fix suggest query param validation (#1671)
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz authored Mar 12, 2024
1 parent 5c56865 commit 76bc5fe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
12 changes: 6 additions & 6 deletions app/controllers/api/v2/ckb_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ def display_outputs
def rgb_digest
expires_in 10.seconds, public: true, must_revalidate: true

transfers = combine_transfers(@transaction).map do |address_id, transfers|
vout = BitcoinVout.include(:bitcoin_address).find_by(address_id:)
transfers = combine_transfers(@ckb_transaction).map do |address_id, transfers|
vout = BitcoinVout.includes(:bitcoin_address).find_by(address_id:)
next unless vout

{ address: vout.bitcoin_address.address_hash, transfers: }
end
vout = @transaction.bitcoin_vouts.find_by(op_return: true)
vout = @ckb_transaction.bitcoin_vouts.find_by(op_return: true)

render json: {
data: {
txid: vout.bitcoin_transaction.txid,
confirmations: vout.bitcoin_transaction.confirmations,
commitment: vout.bitcoin_transaction.commitment,
txid: vout&.bitcoin_transaction&.txid,
confirmations: vout&.bitcoin_transaction&.confirmations,
commitment: vout&.commitment,
transfers:,
},
}
Expand Down
10 changes: 8 additions & 2 deletions app/controllers/validations/suggest_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def error_object
api_errors << Api::V1::Exceptions::SuggestQueryKeyInvalidError.new if :query_key.in?(errors.attribute_names)
{
status: api_errors.first.status,
errors: RequestErrorSerializer.new(api_errors, message: api_errors.first.title)
errors: RequestErrorSerializer.new(api_errors, message: api_errors.first.title),
}
end
end
Expand All @@ -25,7 +25,13 @@ def error_object
attr_accessor :query_key

def query_key_format_must_be_correct
if query_key.blank? || (!QueryKeyUtils.integer_string?(query_key) && !QueryKeyUtils.valid_hex?(query_key) && !QueryKeyUtils.valid_address?(query_key))
query_key_invalid =
!QueryKeyUtils.integer_string?(query_key) &&
!QueryKeyUtils.valid_hex?(query_key) &&
!QueryKeyUtils.valid_address?(query_key) &&
!QueryKeyUtils.valid_bitcoin_txid?(query_key)

if query_key.blank? || query_key_invalid
errors.add(:query_key, "query key is invalid")
end
end
Expand Down
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 @@ -76,7 +76,7 @@ def build_vouts!

return if vout_attributes.blank?

`BitcoinVout`.upsert_all(vout_attributes, unique_by: %i[bitcoin_transaction_id index])
BitcoinVout.upsert_all(vout_attributes, unique_by: %i[bitcoin_transaction_id index])
end

def build_tx!(raw_tx)
Expand Down

0 comments on commit 76bc5fe

Please sign in to comment.