parent
ea4d01dec0
commit
1b3c909d51
|
@ -40,10 +40,20 @@ def get_stale_transactions(conn, reassign_delay):
|
|||
|
||||
|
||||
@register_query(MongoDBConnection)
|
||||
def get_transaction_from_block(conn, block_id, tx_id):
|
||||
# this is definitely wrong, but it's something like this
|
||||
return conn.db['bigchain'].find_one({'id': block_id,
|
||||
'block.transactions.id': tx_id})
|
||||
def get_transaction_from_block(conn, transaction_id, block_id):
|
||||
return conn.db['bigchain'].aggregate([
|
||||
{'$match': {'id': block_id}},
|
||||
{'$project': {
|
||||
'block.transactions': {
|
||||
'$filter': {
|
||||
'input': '$block.transactions',
|
||||
'as': 'transaction',
|
||||
'cond': {
|
||||
'$eq': ['$$transaction.id', transaction_id]
|
||||
}
|
||||
}
|
||||
}
|
||||
}}]).next()['block']['transactions'][0]
|
||||
|
||||
|
||||
@register_query(MongoDBConnection)
|
||||
|
@ -92,14 +102,16 @@ def get_owned_ids(conn, owner):
|
|||
@register_query(MongoDBConnection)
|
||||
def get_votes_by_block_id(conn, block_id):
|
||||
return conn.db['votes']\
|
||||
.find({'vote.voting_for_block': block_id})
|
||||
.find({'vote.voting_for_block': block_id},
|
||||
projection={'_id': False})
|
||||
|
||||
|
||||
@register_query(MongoDBConnection)
|
||||
def get_votes_by_block_id_and_voter(conn, block_id, node_pubkey):
|
||||
return conn.db['votes']\
|
||||
.find({'vote.voting_for_block': block_id,
|
||||
'node_pubkey': node_pubkey})
|
||||
'node_pubkey': node_pubkey},
|
||||
projection={'_id': False})
|
||||
|
||||
|
||||
@register_query(MongoDBConnection)
|
||||
|
|
|
@ -153,14 +153,14 @@ class TestBigchainApi(object):
|
|||
def test_get_transaction_in_invalid_and_valid_block(self, monkeypatch, b):
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
monkeypatch.setattr('time.time', lambda: 1)
|
||||
monkeypatch.setattr('time.time', lambda: 1000000000)
|
||||
tx1 = Transaction.create([b.me], [([b.me], 1)],
|
||||
metadata={'msg': random.random()})
|
||||
tx1 = tx1.sign([b.me_private])
|
||||
block1 = b.create_block([tx1])
|
||||
b.write_block(block1)
|
||||
|
||||
monkeypatch.setattr('time.time', lambda: 2222222222)
|
||||
monkeypatch.setattr('time.time', lambda: 2000000000)
|
||||
tx2 = Transaction.create([b.me], [([b.me], 1)],
|
||||
metadata={'msg': random.random()})
|
||||
tx2 = tx2.sign([b.me_private])
|
||||
|
|
Loading…
Reference in New Issue