Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: Outputs API doesn't respond with correct unspent/spent outputs #2567

Merged
merged 6 commits into from Sep 26, 2018

Conversation

kansi
Copy link
Contributor

@kansi kansi commented Sep 21, 2018

Solution: Fix fastquery such that embedded document is queried properly

Fixes #2552
Fixes #2568

Solution: Fix fastquery such that embedded document is queried properly
@codecov-io
Copy link

codecov-io commented Sep 21, 2018

Codecov Report

Merging #2567 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #2567      +/-   ##
==========================================
+ Coverage   93.63%   93.64%   +<.01%     
==========================================
  Files          45       45              
  Lines        2623     2626       +3     
==========================================
+ Hits         2456     2459       +3     
  Misses        167      167

@@ -274,6 +274,15 @@ def to_dict(self):
'output_index': self.output,
}

def to_query(self):
if self.txid is None and self.output is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible for just one of these to be None?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, these fields cannot be None. I started off with to_dict, this code is leftover

Solution: remove to unnecesary if conditional
@@ -274,6 +274,12 @@ def to_dict(self):
'output_index': self.output,
}

def to_query(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about changing the transaction query the following way? The current approach disguises the caveat from the reader.

'$and': [
    {
        'inputs.fulfills.transaction_id': {
            '$in': transaction_ids,
        },
        'inputs.fulfills.output_index': {
            '$in': output_indexes,
        },
    }
]

Copy link
Contributor

@ldmberman ldmberman Sep 24, 2018

Choose a reason for hiding this comment

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

Actually, $and is applied to fulfills so:

{
    'inputs.fulfills: {
        '$and': [{
            transaction_id': {
                '$in': transaction_ids,
            },
            'output_index': {
                '$in': output_indexes,
            },
       }]
    }
]

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, and we also seem to need $elemMatch.

Solution: get_spent queries embedded documents which respect key order. This is
not expected by the application hence the query should be altered to query any
kind of key order
Solution: Simplify query using $elemMatch
Solution: Add test for `get_spending_transactions` to check that correct
matching is done when querying documents with multiple inputs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants