mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
* Problem: BigchainDB config has stale/deprecated parameters - Remove `keyring` and `keypair` from config - Update tests - Add `tendermint` config * Fix flake8 * Update some naming conventions and redundant changes * Remove redundant routine `fast_query` * Remove deprecated parameters and descriptions * remove some more unwanted code * Problem: Two flake8 errors made Travis fail Solution: Fix the two flake8 errors * Address comments - Remove reference of nodes_except_me and me_private and me as attributes of BigchainDB instances - Update and re-add test(s) - Do not introduce `tendermint` in configuration instead handle that in a separate PR along with docs * Address comments - Remove tests that are already covered with 2.0 - Remove tests that are no longer relevant - Add TODO for more cleanup * Remove tendermint config from configure command
61 lines
2.4 KiB
Python
61 lines
2.4 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.
|
|
|
|
* Votes are not validated for security (security is a replication concern)
|
|
* Votes come from only one node, and as such, non-byzantine fault tolerance
|
|
is reduced.
|
|
|
|
Previously, to consider the status of a block, all votes for that block
|
|
were retrieved and the election results were counted. This meant that a
|
|
faulty node may still have been able to obtain a correct election result.
|
|
However, from the point of view of a client, it is still neccesary to
|
|
query multiple nodes to insure against getting an incorrect response from
|
|
a byzantine node.
|
|
"""
|
|
|
|
def __init__(self, connection):
|
|
self.connection = connection
|
|
|
|
def get_outputs_by_public_key(self, public_key):
|
|
"""Get outputs for a public key"""
|
|
res = list(query.get_owned_ids(self.connection, public_key))
|
|
txs = [tx for _, tx in self.filter_valid_items(res)]
|
|
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]
|
|
res = query.get_spending_transactions(self.connection, links)
|
|
txs = [tx for _, tx in self.filter_valid_items(res)]
|
|
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]
|
|
res = query.get_spending_transactions(self.connection, links)
|
|
txs = [tx for _, tx in self.filter_valid_items(res)]
|
|
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]
|