mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-25 15:05:49 +00:00
adding try except to some queries from tarantool/query.py.
This commit is contained in:
parent
bcddc754be
commit
18d0e8fbcf
@ -167,6 +167,7 @@ def get_spent(connection, fullfil_transaction_id: str, fullfil_output_index: str
|
|||||||
|
|
||||||
@register_query(TarantoolDB)
|
@register_query(TarantoolDB)
|
||||||
def get_latest_block(connection): # TODO Here is used DESCENDING OPERATOR
|
def get_latest_block(connection): # TODO Here is used DESCENDING OPERATOR
|
||||||
|
try:
|
||||||
space = connection.space("blocks")
|
space = connection.space("blocks")
|
||||||
_all_blocks = space.select()
|
_all_blocks = space.select()
|
||||||
_all_blocks = _all_blocks.data
|
_all_blocks = _all_blocks.data
|
||||||
@ -183,6 +184,10 @@ def get_latest_block(connection): # TODO Here is used DESCENDING OPERATOR
|
|||||||
else:
|
else:
|
||||||
block = None
|
block = None
|
||||||
return block
|
return block
|
||||||
|
except tarantool.error.SchemaError:
|
||||||
|
return None
|
||||||
|
except Exception as err:
|
||||||
|
raise err
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDB)
|
@register_query(TarantoolDB)
|
||||||
@ -441,6 +446,7 @@ def delete_elections(connection, height: int):
|
|||||||
|
|
||||||
@register_query(TarantoolDB)
|
@register_query(TarantoolDB)
|
||||||
def get_validator_set(connection, height: int = None):
|
def get_validator_set(connection, height: int = None):
|
||||||
|
try:
|
||||||
space = connection.space("validators")
|
space = connection.space("validators")
|
||||||
_validators = space.select()
|
_validators = space.select()
|
||||||
_validators = _validators.data
|
_validators = _validators.data
|
||||||
@ -451,10 +457,15 @@ def get_validator_set(connection, height: int = None):
|
|||||||
else:
|
else:
|
||||||
_validators = [{"height": validator[1], "validators": validator[2]} for validator in _validators]
|
_validators = [{"height": validator[1], "validators": validator[2]} for validator in _validators]
|
||||||
return next(iter(sorted(_validators, key=lambda k: k["height"], reverse=True)), None)
|
return next(iter(sorted(_validators, key=lambda k: k["height"], reverse=True)), None)
|
||||||
|
except tarantool.error.SchemaError:
|
||||||
|
return None
|
||||||
|
except Exception as err:
|
||||||
|
raise err
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDB)
|
@register_query(TarantoolDB)
|
||||||
def get_election(connection, election_id: str):
|
def get_election(connection, election_id: str):
|
||||||
|
try:
|
||||||
space = connection.space("elections")
|
space = connection.space("elections")
|
||||||
_elections = space.select(election_id, index="id_search")
|
_elections = space.select(election_id, index="id_search")
|
||||||
_elections = _elections.data
|
_elections = _elections.data
|
||||||
@ -462,6 +473,10 @@ def get_election(connection, election_id: str):
|
|||||||
return None
|
return None
|
||||||
_election = sorted(_elections, key=itemgetter(0), reverse=True)[0]
|
_election = sorted(_elections, key=itemgetter(0), reverse=True)[0]
|
||||||
return {"election_id": _election[0], "height": _election[1], "is_concluded": _election[2]}
|
return {"election_id": _election[0], "height": _election[1], "is_concluded": _election[2]}
|
||||||
|
except tarantool.error.SchemaError:
|
||||||
|
return None
|
||||||
|
except Exception as err:
|
||||||
|
raise err
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDB)
|
@register_query(TarantoolDB)
|
||||||
@ -496,9 +511,14 @@ def delete_abci_chain(connection, height: int):
|
|||||||
|
|
||||||
@register_query(TarantoolDB)
|
@register_query(TarantoolDB)
|
||||||
def get_latest_abci_chain(connection):
|
def get_latest_abci_chain(connection):
|
||||||
|
try:
|
||||||
space = connection.space("abci_chains")
|
space = connection.space("abci_chains")
|
||||||
_all_chains = space.select().data
|
_all_chains = space.select().data
|
||||||
if len(_all_chains) == 0:
|
if len(_all_chains) == 0:
|
||||||
return None
|
return None
|
||||||
_chain = sorted(_all_chains, key=itemgetter(0), reverse=True)[0]
|
_chain = sorted(_all_chains, key=itemgetter(0), reverse=True)[0]
|
||||||
return {"height": _chain[0], "is_synced": _chain[1], "chain_id": _chain[2]}
|
return {"height": _chain[0], "is_synced": _chain[1], "chain_id": _chain[2]}
|
||||||
|
except tarantool.error.SchemaError:
|
||||||
|
return None
|
||||||
|
except Exception as err:
|
||||||
|
raise err
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user