mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-06-28 08:37:45 +02:00
address nomenclature issues
This commit is contained in:
parent
01ba01083d
commit
b4f14b26ce
|
@ -395,7 +395,7 @@ class Bigchain(object):
|
||||||
"""
|
"""
|
||||||
Get a list of output links filtered on some criteria
|
Get a list of output links filtered on some criteria
|
||||||
"""
|
"""
|
||||||
outputs = self.fastquery.get_outputs_by_pubkey(owner)
|
outputs = self.fastquery.get_outputs_by_public_key(owner)
|
||||||
if not include_spent:
|
if not include_spent:
|
||||||
outputs = self.fastquery.filter_spent_outputs(outputs)
|
outputs = self.fastquery.filter_spent_outputs(outputs)
|
||||||
return outputs
|
return outputs
|
||||||
|
|
|
@ -22,32 +22,37 @@ class FastQuery:
|
||||||
self.connection = connection
|
self.connection = connection
|
||||||
self.me = me
|
self.me = me
|
||||||
|
|
||||||
def filter_block_ids(self, block_ids, include_undecided=True):
|
def filter_valid_block_ids(self, block_ids, include_undecided=False):
|
||||||
"""
|
"""
|
||||||
Given block ids, filter the invalid blocks.
|
Given block ids, return only the ones that are valid.
|
||||||
"""
|
"""
|
||||||
block_ids = list(set(block_ids))
|
block_ids = list(set(block_ids))
|
||||||
votes = query.get_votes_for_blocks_by_voter(
|
votes = query.get_votes_for_blocks_by_voter(
|
||||||
self.connection, block_ids, self.me)
|
self.connection, block_ids, self.me)
|
||||||
votes = {v['vote']['voting_for_block']: v['vote']['is_block_valid'] for v in votes}
|
votes = {vote['vote']['voting_for_block']: vote['vote']['is_block_valid']
|
||||||
return [b for b in block_ids if votes.get(b, include_undecided)]
|
for vote in votes}
|
||||||
|
return [block_id for block_id in block_ids
|
||||||
|
if votes.get(block_id, include_undecided)]
|
||||||
|
|
||||||
def filter_valid_blocks(self, blocks, key=lambda b: b[0]):
|
def filter_valid_items(self, items, block_id_key=lambda b: b[0]):
|
||||||
"""
|
"""
|
||||||
Given things with block ids, remove the invalid ones.
|
Given items with block ids, return only the ones that are valid or undecided.
|
||||||
"""
|
"""
|
||||||
blocks = list(blocks)
|
items = list(items)
|
||||||
valid_block_ids = set(self.filter_block_ids(key(b) for b in blocks))
|
block_ids = map(block_id_key, items)
|
||||||
return [b for b in blocks if key(b) in valid_block_ids]
|
valid_block_ids = set(self.filter_valid_block_ids(block_ids, True))
|
||||||
|
return [b for b in items if block_id_key(b) in valid_block_ids]
|
||||||
|
|
||||||
def get_outputs_by_pubkey(self, pubkey):
|
def get_outputs_by_public_key(self, public_key):
|
||||||
""" Get outputs for a public key """
|
"""
|
||||||
res = list(query.get_owned_ids(self.connection, pubkey))
|
Get outputs for a public key
|
||||||
txs = [tx for _, tx in self.filter_valid_blocks(res)]
|
"""
|
||||||
return [TransactionLink(tx['id'], i)
|
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 tx in txs
|
||||||
for i, o in enumerate(tx['outputs'])
|
for index, output in enumerate(tx['outputs'])
|
||||||
if output_has_owner(o, pubkey)]
|
if output_has_owner(output, public_key)]
|
||||||
|
|
||||||
def filter_spent_outputs(self, outputs):
|
def filter_spent_outputs(self, outputs):
|
||||||
"""
|
"""
|
||||||
|
@ -58,7 +63,7 @@ class FastQuery:
|
||||||
"""
|
"""
|
||||||
links = [o.to_dict() for o in outputs]
|
links = [o.to_dict() for o in outputs]
|
||||||
res = query.get_spending_transactions(self.connection, links)
|
res = query.get_spending_transactions(self.connection, links)
|
||||||
txs = [tx for _, tx in self.filter_valid_blocks(res)]
|
txs = [tx for _, tx in self.filter_valid_items(res)]
|
||||||
spends = {TransactionLink.from_dict(input_['fulfills'])
|
spends = {TransactionLink.from_dict(input_['fulfills'])
|
||||||
for tx in txs
|
for tx in txs
|
||||||
for input_ in tx['inputs']}
|
for input_ in tx['inputs']}
|
||||||
|
|
|
@ -1119,7 +1119,7 @@ def test_get_owned_ids_calls_get_outputs_filtered():
|
||||||
def test_get_outputs_filtered_only_unspent():
|
def test_get_outputs_filtered_only_unspent():
|
||||||
from bigchaindb.common.transaction import TransactionLink
|
from bigchaindb.common.transaction import TransactionLink
|
||||||
from bigchaindb.core import Bigchain
|
from bigchaindb.core import Bigchain
|
||||||
with patch('bigchaindb.fastquery.FastQuery.get_outputs_by_pubkey') as get_outputs:
|
with patch('bigchaindb.fastquery.FastQuery.get_outputs_by_public_key') as get_outputs:
|
||||||
get_outputs.return_value = [TransactionLink('a', 1),
|
get_outputs.return_value = [TransactionLink('a', 1),
|
||||||
TransactionLink('b', 2)]
|
TransactionLink('b', 2)]
|
||||||
with patch('bigchaindb.fastquery.FastQuery.filter_spent_outputs') as filter_spent:
|
with patch('bigchaindb.fastquery.FastQuery.filter_spent_outputs') as filter_spent:
|
||||||
|
@ -1132,7 +1132,7 @@ def test_get_outputs_filtered_only_unspent():
|
||||||
def test_get_outputs_filtered():
|
def test_get_outputs_filtered():
|
||||||
from bigchaindb.common.transaction import TransactionLink
|
from bigchaindb.common.transaction import TransactionLink
|
||||||
from bigchaindb.core import Bigchain
|
from bigchaindb.core import Bigchain
|
||||||
with patch('bigchaindb.fastquery.FastQuery.get_outputs_by_pubkey') as get_outputs:
|
with patch('bigchaindb.fastquery.FastQuery.get_outputs_by_public_key') as get_outputs:
|
||||||
get_outputs.return_value = [TransactionLink('a', 1),
|
get_outputs.return_value = [TransactionLink('a', 1),
|
||||||
TransactionLink('b', 2)]
|
TransactionLink('b', 2)]
|
||||||
with patch('bigchaindb.fastquery.FastQuery.filter_spent_outputs') as filter_spent:
|
with patch('bigchaindb.fastquery.FastQuery.filter_spent_outputs') as filter_spent:
|
||||||
|
|
|
@ -21,30 +21,30 @@ def blockdata(b, user_pk, user2_pk):
|
||||||
return blocks, [b['id'] for b in blocks]
|
return blocks, [b['id'] for b in blocks]
|
||||||
|
|
||||||
|
|
||||||
def test_filter_block_ids_with_undecided(b, blockdata):
|
def test_filter_valid_block_ids_with_undecided(b, blockdata):
|
||||||
blocks, block_ids = blockdata
|
blocks, block_ids = blockdata
|
||||||
valid_ids = b.fastquery.filter_block_ids(block_ids)
|
valid_ids = b.fastquery.filter_valid_block_ids(block_ids, include_undecided=True)
|
||||||
assert set(valid_ids) == {blocks[0]['id'], blocks[1]['id']}
|
assert set(valid_ids) == {blocks[0]['id'], blocks[1]['id']}
|
||||||
|
|
||||||
|
|
||||||
def test_filter_block_ids_only_valid(b, blockdata):
|
def test_filter_valid_block_ids_only_valid(b, blockdata):
|
||||||
blocks, block_ids = blockdata
|
blocks, block_ids = blockdata
|
||||||
valid_ids = b.fastquery.filter_block_ids(block_ids, include_undecided=False)
|
valid_ids = b.fastquery.filter_valid_block_ids(block_ids)
|
||||||
assert set(valid_ids) == {blocks[1]['id']}
|
assert set(valid_ids) == {blocks[1]['id']}
|
||||||
|
|
||||||
|
|
||||||
def test_filter_valid_blocks(b, blockdata):
|
def test_filter_valid_items(b, blockdata):
|
||||||
blocks, _ = blockdata
|
blocks, _ = blockdata
|
||||||
assert (b.fastquery.filter_valid_blocks(blocks, key=lambda b: b['id'])
|
assert (b.fastquery.filter_valid_items(blocks, block_id_key=lambda b: b['id'])
|
||||||
== [blocks[0], blocks[1]])
|
== [blocks[0], blocks[1]])
|
||||||
|
|
||||||
|
|
||||||
def test_get_outputs_by_pubkey(b, user_pk, user2_pk, blockdata):
|
def test_get_outputs_by_public_key(b, user_pk, user2_pk, blockdata):
|
||||||
blocks, _ = blockdata
|
blocks, _ = blockdata
|
||||||
assert b.fastquery.get_outputs_by_pubkey(user_pk) == [
|
assert b.fastquery.get_outputs_by_public_key(user_pk) == [
|
||||||
TransactionLink(blocks[1]['block']['transactions'][0]['id'], 0)
|
TransactionLink(blocks[1]['block']['transactions'][0]['id'], 0)
|
||||||
]
|
]
|
||||||
assert b.fastquery.get_outputs_by_pubkey(user2_pk) == [
|
assert b.fastquery.get_outputs_by_public_key(user2_pk) == [
|
||||||
TransactionLink(blocks[0]['block']['transactions'][0]['id'], 0)
|
TransactionLink(blocks[0]['block']['transactions'][0]['id'], 0)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ def test_filter_spent_outputs(b, user_pk):
|
||||||
block = Block([tx4])
|
block = Block([tx4])
|
||||||
b.write_block(block)
|
b.write_block(block)
|
||||||
|
|
||||||
outputs = b.fastquery.get_outputs_by_pubkey(user_pk)
|
outputs = b.fastquery.get_outputs_by_public_key(user_pk)
|
||||||
unspents = b.fastquery.filter_spent_outputs(outputs)
|
unspents = b.fastquery.filter_spent_outputs(outputs)
|
||||||
|
|
||||||
assert set(unspents) == {
|
assert set(unspents) == {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user