From 475b9d97ce91dbd84f0568e45abd5455e55351ad Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 5 May 2016 11:49:55 +0200 Subject: [PATCH] factor out secondary index search --- bigchaindb/core.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/bigchaindb/core.py b/bigchaindb/core.py index ddbb74d4..19bdbd3e 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -169,6 +169,22 @@ class Bigchain(object): else: return None + def search_block_election_on_index(self, value, index): + """Retrieves block election information given a secondary index and value + + Args: + value: a value to search (e.g. transaction id string, payload hash string) + index (str): name of a secondary index, e.g. 'transaction_id' + + Returns: + A list of blocks with with only election information + """ + # First, get information on all blocks which contain this transaction + response = r.table('bigchain').get_all(value, index=index)\ + .pluck('votes', 'id', {'block': ['voters']}).run(self.conn) + + return list(response) + def get_blocks_status_containing_tx(self, txid): """Retrieves block ids and statuses related to a transaction @@ -182,10 +198,7 @@ class Bigchain(object): """ # First, get information on all blocks which contain this transaction - response = r.table('bigchain').get_all(txid, index='transaction_id')\ - .pluck('votes', 'id', {'block': ['voters']}).run(self.conn) - - blocks = list(response) + blocks = self.search_block_election_on_index(txid, 'transaction_id') if blocks: # Determine the election status of each block