Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Add filter data field to get transactions endpoint - Closes #2404 #2470

Merged
merged 14 commits into from
Oct 18, 2018

Conversation

diego-G
Copy link

@diego-G diego-G commented Oct 15, 2018

What was the problem?

There was no way to get a transaction from its attached additional data field.

How did I fix it?

Adding a subquery filter on GET transactions endpoint.

How to test it?

mocha test/functional/http/get/transactions.js

Review checklist

@diego-G diego-G self-assigned this Oct 15, 2018
@diego-G diego-G changed the title Add filter data field get transactions - Closes #2404 Add filter data field to get transactions endpoint - Closes #2404 Oct 15, 2018
@diego-G diego-G force-pushed the 2404-add_filter_data_field_get_transactions branch from 8d644d1 to 8882e71 Compare October 15, 2018 11:35
in: query
description: Additional data field to query
type: string
format: data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no format defined with this name data

@@ -121,6 +121,9 @@ __private.list = function(filter, cb) {
maxAmount: '"t_amount" <= ${maxAmount}',
type: '"t_type" = ${type}',
minConfirmations: 'confirmations >= ${minConfirmations}',
data: `ENCODE((SELECT data FROM transfer WHERE transfer."transactionId" = trs_list."t_id"), 'escape') LIKE '${
filter.data
}'`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After research, I suggest for now we go with exact match instead of regexpr:

  1. This must be going to impact the performance
  2. The encode with escape just escape the special characters so will change the actual content
    • If user added a transaction with \u0000 hey how :), escaping it will turn it to \000 hey how :)
    • If user search with key word 00 the query will match and return the transaction
  3. Since the actual content is different then escaped one so match will not result accurate

So until we have this data field as binary, we should only provide the exact match. Once we find way to convert it to utf8 strings, then we may provide the pattern matching.

Instead of encoding the cases existing in the database from bytea to utf8, we convert the filter required by the user from utf8 to hex and later decode it to bytea finally making the comparision in plain bytea.
It covers edge cases related to SQL injection.
Copy link
Contributor

@4miners 4miners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the impact of the new subquery on performance.

modules/transactions.js Outdated Show resolved Hide resolved
@diego-G diego-G requested review from 4miners and shuse2 and removed request for vitaly-t October 18, 2018 09:52
@nazarhussain nazarhussain self-requested a review October 18, 2018 13:39
nazarhussain
nazarhussain previously approved these changes Oct 18, 2018
4miners
4miners previously approved these changes Oct 18, 2018
modules/transactions.js Outdated Show resolved Hide resolved
@4miners 4miners dismissed stale reviews from nazarhussain and themself via 89f685f October 18, 2018 14:03
@4miners 4miners requested a review from shuse2 October 18, 2018 14:25
@shuse2 shuse2 merged commit 427da7e into development Oct 18, 2018
@shuse2 shuse2 deleted the 2404-add_filter_data_field_get_transactions branch October 18, 2018 14:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to search for transactions by data field
4 participants