mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-25 06:55:45 +00:00
adding try except to some queries from tarantool/query.py.
This commit is contained in:
parent
bcddc754be
commit
18d0e8fbcf
@ -167,22 +167,27 @@ 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
|
||||||
space = connection.space("blocks")
|
try:
|
||||||
_all_blocks = space.select()
|
space = connection.space("blocks")
|
||||||
_all_blocks = _all_blocks.data
|
_all_blocks = space.select()
|
||||||
block = {"app_hash": '', "height": 0, "transactions": []}
|
_all_blocks = _all_blocks.data
|
||||||
|
block = {"app_hash": '', "height": 0, "transactions": []}
|
||||||
|
|
||||||
if len(_all_blocks) > 0:
|
if len(_all_blocks) > 0:
|
||||||
_block = sorted(_all_blocks, key=itemgetter(1), reverse=True)[0]
|
_block = sorted(_all_blocks, key=itemgetter(1), reverse=True)[0]
|
||||||
space = connection.space("blocks_tx")
|
space = connection.space("blocks_tx")
|
||||||
_txids = space.select(_block[2], index="block_search")
|
_txids = space.select(_block[2], index="block_search")
|
||||||
_txids = _txids.data
|
_txids = _txids.data
|
||||||
block["app_hash"] = _block[0]
|
block["app_hash"] = _block[0]
|
||||||
block["height"] = _block[1]
|
block["height"] = _block[1]
|
||||||
block["transactions"] = [tx[0] for tx in _txids]
|
block["transactions"] = [tx[0] for tx in _txids]
|
||||||
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,27 +446,37 @@ 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):
|
||||||
space = connection.space("validators")
|
try:
|
||||||
_validators = space.select()
|
space = connection.space("validators")
|
||||||
_validators = _validators.data
|
_validators = space.select()
|
||||||
if height is not None:
|
_validators = _validators.data
|
||||||
_validators = [{"height": validator[1], "validators": validator[2]} for validator in _validators if
|
if height is not None:
|
||||||
validator[1] <= height]
|
_validators = [{"height": validator[1], "validators": validator[2]} for validator in _validators if
|
||||||
return next(iter(sorted(_validators, key=lambda k: k["height"], reverse=True)), None)
|
validator[1] <= height]
|
||||||
else:
|
return next(iter(sorted(_validators, key=lambda k: k["height"], reverse=True)), None)
|
||||||
_validators = [{"height": validator[1], "validators": validator[2]} for validator in _validators]
|
else:
|
||||||
return next(iter(sorted(_validators, key=lambda k: k["height"], reverse=True)), None)
|
_validators = [{"height": validator[1], "validators": validator[2]} for validator in _validators]
|
||||||
|
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):
|
||||||
space = connection.space("elections")
|
try:
|
||||||
_elections = space.select(election_id, index="id_search")
|
space = connection.space("elections")
|
||||||
_elections = _elections.data
|
_elections = space.select(election_id, index="id_search")
|
||||||
if len(_elections) == 0:
|
_elections = _elections.data
|
||||||
|
if len(_elections) == 0:
|
||||||
|
return None
|
||||||
|
_election = sorted(_elections, key=itemgetter(0), reverse=True)[0]
|
||||||
|
return {"election_id": _election[0], "height": _election[1], "is_concluded": _election[2]}
|
||||||
|
except tarantool.error.SchemaError:
|
||||||
return None
|
return None
|
||||||
_election = sorted(_elections, key=itemgetter(0), reverse=True)[0]
|
except Exception as err:
|
||||||
return {"election_id": _election[0], "height": _election[1], "is_concluded": _election[2]}
|
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):
|
||||||
space = connection.space("abci_chains")
|
try:
|
||||||
_all_chains = space.select().data
|
space = connection.space("abci_chains")
|
||||||
if len(_all_chains) == 0:
|
_all_chains = space.select().data
|
||||||
|
if len(_all_chains) == 0:
|
||||||
|
return None
|
||||||
|
_chain = sorted(_all_chains, key=itemgetter(0), reverse=True)[0]
|
||||||
|
return {"height": _chain[0], "is_synced": _chain[1], "chain_id": _chain[2]}
|
||||||
|
except tarantool.error.SchemaError:
|
||||||
return None
|
return None
|
||||||
_chain = sorted(_all_chains, key=itemgetter(0), reverse=True)[0]
|
except Exception as err:
|
||||||
return {"height": _chain[0], "is_synced": _chain[1], "chain_id": _chain[2]}
|
raise err
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user