mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00

* Problem: core.py contains an unused class, `Bigchain` Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain. * Problem: core.py contains an unused class, `Bigchain` Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain. * Fixed flake8 complaint about too many blank lines * Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI... Sorry in advance! * Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI... Sorry in advance! * Updating from master changed BigchainDB.process_post_response to a private method, so I had to align with that. * Fixed a couple stale references to bigchaindb.Bigchain in docstrings * Missed a reference to `Bigchain` in a patch call... * Problem: BigchainDB class should be part of project root Solution: Removed the /tendermint directory and moved its contents to project root * Problem: Flake8 complained that imports were not at the top of the file Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now * Problem: Stale reference to /tendermint directory in the index Solution: Removed the references to /tendermint * Problem: Flake8 complaining of unused import in __init__.py Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8. * Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead * Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test Solution: Updated the @patch for completeness * Problem: BigchainDB class should be part of project root Solution: Removed the /tendermint directory and moved its contents to project root * Problem: Flake8 complained that imports were not at the top of the file Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now * Problem: Stale reference to /tendermint directory in the index Solution: Removed the references to /tendermint * Problem: Flake8 complaining of unused import in __init__.py Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8. * Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead * Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test Solution: Updated the @patch for completeness
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
from bigchaindb.utils import condition_details_has_owner
|
|
from bigchaindb.backend import query
|
|
from bigchaindb.common.transaction import TransactionLink
|
|
|
|
|
|
class FastQuery():
|
|
"""
|
|
Database queries that join on block results from a single node.
|
|
"""
|
|
def __init__(self, connection):
|
|
self.connection = connection
|
|
|
|
def get_outputs_by_public_key(self, public_key):
|
|
"""
|
|
Get outputs for a public key
|
|
"""
|
|
txs = list(query.get_owned_ids(self.connection, public_key))
|
|
return [TransactionLink(tx['id'], index)
|
|
for tx in txs
|
|
for index, output in enumerate(tx['outputs'])
|
|
if condition_details_has_owner(output['condition']['details'],
|
|
public_key)]
|
|
|
|
def filter_spent_outputs(self, outputs):
|
|
"""
|
|
Remove outputs that have been spent
|
|
|
|
Args:
|
|
outputs: list of TransactionLink
|
|
"""
|
|
links = [o.to_dict() for o in outputs]
|
|
txs = list(query.get_spending_transactions(self.connection, links))
|
|
spends = {TransactionLink.from_dict(input_['fulfills'])
|
|
for tx in txs
|
|
for input_ in tx['inputs']}
|
|
return [ff for ff in outputs if ff not in spends]
|
|
|
|
def filter_unspent_outputs(self, outputs):
|
|
"""
|
|
Remove outputs that have not been spent
|
|
|
|
Args:
|
|
outputs: list of TransactionLink
|
|
"""
|
|
links = [o.to_dict() for o in outputs]
|
|
txs = list(query.get_spending_transactions(self.connection, links))
|
|
spends = {TransactionLink.from_dict(input_['fulfills'])
|
|
for tx in txs
|
|
for input_ in tx['inputs']}
|
|
return [ff for ff in outputs if ff in spends]
|