Wrap queries with connection object

This commit is contained in:
vrde 2017-02-06 14:43:40 +01:00
parent 01da32d351
commit 3c45de70d0
No known key found for this signature in database
GPG Key ID: 6581C7C39B3D397D

View File

@ -121,7 +121,9 @@ def get_txids_filtered(conn, asset_id, operation=None):
{'$match': match}, {'$match': match},
{'$project': {'block.transactions.id': True}} {'$project': {'block.transactions.id': True}}
] ]
cursor = conn.db['bigchain'].aggregate(pipeline) cursor = conn.run(
conn.collection('bigchain')
.aggregate(pipeline))
return (elem['block']['transactions']['id'] for elem in cursor) return (elem['block']['transactions']['id'] for elem in cursor)
@ -281,18 +283,20 @@ def get_last_voted_block(conn, node_pubkey):
@register_query(MongoDBConnection) @register_query(MongoDBConnection)
def get_unvoted_blocks(conn, node_pubkey): def get_unvoted_blocks(conn, node_pubkey):
return conn.db['bigchain'].aggregate([ return conn.run(
{'$lookup': { conn.collection('bigchain')
'from': 'votes', .aggregate([
'localField': 'id', {'$lookup': {
'foreignField': 'vote.voting_for_block', 'from': 'votes',
'as': 'votes' 'localField': 'id',
}}, 'foreignField': 'vote.voting_for_block',
{'$match': { 'as': 'votes'
'votes.node_pubkey': {'$ne': node_pubkey}, }},
'block.transactions.operation': {'$ne': 'GENESIS'} {'$match': {
}}, 'votes.node_pubkey': {'$ne': node_pubkey},
{'$project': { 'block.transactions.operation': {'$ne': 'GENESIS'}
'votes': False, '_id': False }},
}} {'$project': {
]) 'votes': False, '_id': False
}}
]))