mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
return block status
This commit is contained in:
parent
ebe21e5907
commit
bd9979618d
@ -16,9 +16,14 @@ class Bigchain(object):
|
|||||||
Create, read, sign, write transactions to the database
|
Create, read, sign, write transactions to the database
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# return if a block has been voted invalid
|
||||||
BLOCK_INVALID = 'invalid'
|
BLOCK_INVALID = 'invalid'
|
||||||
BLOCK_VALID = 'valid'
|
# return if a block is valid, or tx is in valid block
|
||||||
BLOCK_UNDECIDED = 'undecided'
|
BLOCK_VALID = TX_VALID = 'valid'
|
||||||
|
# return if block is undecided, or tx is in undecided block
|
||||||
|
BLOCK_UNDECIDED = TX_UNDECIDED = 'undecided'
|
||||||
|
# return if transaction is in backlog
|
||||||
|
TX_IN_BACKLOG = 'backlog'
|
||||||
|
|
||||||
def __init__(self, host=None, port=None, dbname=None,
|
def __init__(self, host=None, port=None, dbname=None,
|
||||||
public_key=None, private_key=None, keyring=[],
|
public_key=None, private_key=None, keyring=[],
|
||||||
@ -135,15 +140,17 @@ class Bigchain(object):
|
|||||||
def get_transaction(self, txid):
|
def get_transaction(self, txid):
|
||||||
"""Retrieve a transaction with `txid` from bigchain.
|
"""Retrieve a transaction with `txid` from bigchain.
|
||||||
|
|
||||||
Queries the bigchain for a transaction that was already included in a block.
|
Queries the bigchain for a transaction, if it's in a valid or invalid
|
||||||
|
block.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
txid (str): transaction id of the transaction to query
|
txid (str): transaction id of the transaction to query
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A dict with the transaction details if the transaction was found.
|
A dict with the transaction details if the transaction was found.
|
||||||
|
Will add the transaction status to payload ('valid', 'undecided',
|
||||||
If no transaction with that `txid` was found it returns `None`
|
or 'backlog'). If no transaction with that `txid` was found it
|
||||||
|
returns `None`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
validity = self.get_blocks_status_containing_tx(txid)
|
validity = self.get_blocks_status_containing_tx(txid)
|
||||||
@ -161,17 +168,24 @@ class Bigchain(object):
|
|||||||
for _id in validity:
|
for _id in validity:
|
||||||
target_block_id = _id
|
target_block_id = _id
|
||||||
if validity[_id] == Bigchain.BLOCK_VALID:
|
if validity[_id] == Bigchain.BLOCK_VALID:
|
||||||
|
tx_status = self.TX_VALID
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
tx_status = self.TX_UNDECIDED
|
||||||
|
|
||||||
# Query the transaction in the target block and return
|
# Query the transaction in the target block and return
|
||||||
response = r.table('bigchain', read_mode=self.read_mode).get(target_block_id)\
|
response = r.table('bigchain', read_mode=self.read_mode).get(target_block_id)\
|
||||||
.get_field('block').get_field('transactions')\
|
.get_field('block').get_field('transactions')\
|
||||||
.filter(lambda tx: tx['id'] == txid).run(self.conn)
|
.filter(lambda tx: tx['id'] == txid).run(self.conn)[0]
|
||||||
|
response['validity'] = tx_status
|
||||||
return response[0]
|
return response
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return None
|
# Otherwise, check the backlog
|
||||||
|
response = r.table('backlog').get(txid).run(self.conn)
|
||||||
|
if response:
|
||||||
|
response['validity'] = self.TX_IN_BACKLOG
|
||||||
|
return response
|
||||||
|
|
||||||
def search_block_election_on_index(self, value, index):
|
def search_block_election_on_index(self, value, index):
|
||||||
"""Retrieve block election information given a secondary index and value
|
"""Retrieve block election information given a secondary index and value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user