mirror of
https://github.com/planetmint/planetmint.git
synced 2025-07-02 02:42:29 +00:00
blackified
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
367b101fb2
commit
50d1276e29
@ -81,7 +81,9 @@ class ApplicationLogic(BaseApplication):
|
|||||||
chain_id = known_chain["chain_id"]
|
chain_id = known_chain["chain_id"]
|
||||||
|
|
||||||
if known_chain["is_synced"]:
|
if known_chain["is_synced"]:
|
||||||
msg = f"Got invalid InitChain ABCI request ({genesis}) - " f"the chain {chain_id} is already synced."
|
msg = (
|
||||||
|
f"Got invalid InitChain ABCI request ({genesis}) - " f"the chain {chain_id} is already synced."
|
||||||
|
)
|
||||||
logger.error(msg)
|
logger.error(msg)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if chain_id != genesis.chain_id:
|
if chain_id != genesis.chain_id:
|
||||||
@ -127,13 +129,13 @@ class ApplicationLogic(BaseApplication):
|
|||||||
# logger.info(f"Tendermint version: {request.version}")
|
# logger.info(f"Tendermint version: {request.version}")
|
||||||
|
|
||||||
r = ResponseInfo()
|
r = ResponseInfo()
|
||||||
block= None
|
block = None
|
||||||
try:
|
try:
|
||||||
block = self.validator.models.get_latest_block()
|
block = self.validator.models.get_latest_block()
|
||||||
except DBConcurrencyError:
|
except DBConcurrencyError:
|
||||||
block= None
|
block = None
|
||||||
except ValueError:
|
except ValueError:
|
||||||
block=None
|
block = None
|
||||||
if block:
|
if block:
|
||||||
chain_shift = 0 if self.chain is None else self.chain["height"]
|
chain_shift = 0 if self.chain is None else self.chain["height"]
|
||||||
r.last_block_height = block["height"] - chain_shift
|
r.last_block_height = block["height"] - chain_shift
|
||||||
@ -167,7 +169,6 @@ class ApplicationLogic(BaseApplication):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def begin_block(self, req_begin_block):
|
def begin_block(self, req_begin_block):
|
||||||
"""Initialize list of transaction.
|
"""Initialize list of transaction.
|
||||||
Args:
|
Args:
|
||||||
@ -196,7 +197,9 @@ class ApplicationLogic(BaseApplication):
|
|||||||
logger.debug("deliver_tx: %s", raw_transaction)
|
logger.debug("deliver_tx: %s", raw_transaction)
|
||||||
transaction = None
|
transaction = None
|
||||||
try:
|
try:
|
||||||
transaction = self.validator.is_valid_transaction(decode_transaction(raw_transaction), self.block_transactions)
|
transaction = self.validator.is_valid_transaction(
|
||||||
|
decode_transaction(raw_transaction), self.block_transactions
|
||||||
|
)
|
||||||
except DBConcurrencyError:
|
except DBConcurrencyError:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -21,8 +21,10 @@ class OperationError(BackendError):
|
|||||||
class OperationDataInsertionError(BackendError):
|
class OperationDataInsertionError(BackendError):
|
||||||
"""Exception raised when a Database operation fails."""
|
"""Exception raised when a Database operation fails."""
|
||||||
|
|
||||||
|
|
||||||
class DBConcurrencyError(BackendError):
|
class DBConcurrencyError(BackendError):
|
||||||
"""Exception raised when a Database operation fails."""
|
"""Exception raised when a Database operation fails."""
|
||||||
|
|
||||||
|
|
||||||
class DuplicateKeyError(OperationError):
|
class DuplicateKeyError(OperationError):
|
||||||
"""Exception raised when an insert fails because the key is not unique"""
|
"""Exception raised when an insert fails because the key is not unique"""
|
||||||
|
@ -89,7 +89,7 @@ def get_complete_transactions_by_ids(connection, txids: list) -> list[DbTransact
|
|||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def get_outputs_by_tx_id(connection, tx_id: str) -> list[Output]:
|
def get_outputs_by_tx_id(connection, tx_id: str) -> list[Output]:
|
||||||
_outputs = connection.connect().select(TARANT_TABLE_OUTPUT,tx_id, index=TARANT_TX_ID_SEARCH).data
|
_outputs = connection.connect().select(TARANT_TABLE_OUTPUT, tx_id, index=TARANT_TX_ID_SEARCH).data
|
||||||
_sorted_outputs = sorted(_outputs, key=itemgetter(4))
|
_sorted_outputs = sorted(_outputs, key=itemgetter(4))
|
||||||
return [Output.from_tuple(output) for output in _sorted_outputs]
|
return [Output.from_tuple(output) for output in _sorted_outputs]
|
||||||
|
|
||||||
@ -106,7 +106,11 @@ def get_transaction(connection, tx_id: str) -> Union[DbTransaction, None]:
|
|||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def get_transactions_by_asset(connection, asset: str, limit: int = 1000) -> list[DbTransaction]:
|
def get_transactions_by_asset(connection, asset: str, limit: int = 1000) -> list[DbTransaction]:
|
||||||
txs = connection.connect().select(TARANT_TABLE_TRANSACTION,asset, limit=limit, index="transactions_by_asset_cid").data
|
txs = (
|
||||||
|
connection.connect()
|
||||||
|
.select(TARANT_TABLE_TRANSACTION, asset, limit=limit, index="transactions_by_asset_cid")
|
||||||
|
.data
|
||||||
|
)
|
||||||
tx_ids = [tx[0] for tx in txs]
|
tx_ids = [tx[0] for tx in txs]
|
||||||
return get_complete_transactions_by_ids(connection, tx_ids)
|
return get_complete_transactions_by_ids(connection, tx_ids)
|
||||||
|
|
||||||
@ -115,8 +119,9 @@ def get_transactions_by_asset(connection, asset: str, limit: int = 1000) -> list
|
|||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def get_transactions_by_metadata(connection, metadata: str, limit: int = 1000) -> list[DbTransaction]:
|
def get_transactions_by_metadata(connection, metadata: str, limit: int = 1000) -> list[DbTransaction]:
|
||||||
txs = (
|
txs = (
|
||||||
connection.connect().select(TARANT_TABLE_TRANSACTION,
|
connection.connect()
|
||||||
metadata, limit=limit, index="transactions_by_metadata_cid").data
|
.select(TARANT_TABLE_TRANSACTION, metadata, limit=limit, index="transactions_by_metadata_cid")
|
||||||
|
.data
|
||||||
)
|
)
|
||||||
tx_ids = [tx[0] for tx in txs]
|
tx_ids = [tx[0] for tx in txs]
|
||||||
return get_complete_transactions_by_ids(connection, tx_ids)
|
return get_complete_transactions_by_ids(connection, tx_ids)
|
||||||
@ -125,7 +130,8 @@ def get_transactions_by_metadata(connection, metadata: str, limit: int = 1000) -
|
|||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def store_transaction_outputs(connection, output: Output, index: int) -> str:
|
def store_transaction_outputs(connection, output: Output, index: int) -> str:
|
||||||
output_id = uuid4().hex
|
output_id = uuid4().hex
|
||||||
connection.connect().insert(TARANT_TABLE_OUTPUT,
|
connection.connect().insert(
|
||||||
|
TARANT_TABLE_OUTPUT,
|
||||||
(
|
(
|
||||||
output_id,
|
output_id,
|
||||||
int(output.amount),
|
int(output.amount),
|
||||||
@ -133,7 +139,7 @@ def store_transaction_outputs(connection, output: Output, index: int) -> str:
|
|||||||
output.condition.to_dict(),
|
output.condition.to_dict(),
|
||||||
index,
|
index,
|
||||||
output.transaction_id,
|
output.transaction_id,
|
||||||
)
|
),
|
||||||
).data
|
).data
|
||||||
return output_id
|
return output_id
|
||||||
|
|
||||||
@ -168,7 +174,7 @@ def store_transaction(connection, transaction, table=TARANT_TABLE_TRANSACTION):
|
|||||||
transaction["inputs"],
|
transaction["inputs"],
|
||||||
scripts,
|
scripts,
|
||||||
)
|
)
|
||||||
connection.connect().insert(table,tx)
|
connection.connect().insert(table, tx)
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@ -194,7 +200,7 @@ def get_transactions(connection, transactions_ids: list) -> list[DbTransaction]:
|
|||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def get_asset(connection, asset_id: str) -> Asset:
|
def get_asset(connection, asset_id: str) -> Asset:
|
||||||
connection.connect().select(TARANT_TABLE_TRANSACTION,asset_id, index=TARANT_INDEX_TX_BY_ASSET_ID).data
|
connection.connect().select(TARANT_TABLE_TRANSACTION, asset_id, index=TARANT_INDEX_TX_BY_ASSET_ID).data
|
||||||
return Asset.from_dict(_data[0])
|
return Asset.from_dict(_data[0])
|
||||||
|
|
||||||
|
|
||||||
@ -203,7 +209,7 @@ def get_asset(connection, asset_id: str) -> Asset:
|
|||||||
def get_assets(connection, assets_ids: list) -> list[Asset]:
|
def get_assets(connection, assets_ids: list) -> list[Asset]:
|
||||||
_returned_data = []
|
_returned_data = []
|
||||||
for _id in list(set(assets_ids)):
|
for _id in list(set(assets_ids)):
|
||||||
res = connection.connect().select(TARANT_TABLE_TRANSACTION,_id, index=TARANT_INDEX_TX_BY_ASSET_ID).data
|
res = connection.connect().select(TARANT_TABLE_TRANSACTION, _id, index=TARANT_INDEX_TX_BY_ASSET_ID).data
|
||||||
if len(res) == 0:
|
if len(res) == 0:
|
||||||
continue
|
continue
|
||||||
_returned_data.append(res[0])
|
_returned_data.append(res[0])
|
||||||
@ -216,7 +222,12 @@ def get_assets(connection, assets_ids: list) -> list[Asset]:
|
|||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def get_spent(connection, fullfil_transaction_id: str, fullfil_output_index: str) -> list[DbTransaction]:
|
def get_spent(connection, fullfil_transaction_id: str, fullfil_output_index: str) -> list[DbTransaction]:
|
||||||
_inputs = (
|
_inputs = (
|
||||||
connection.connect().select(TARANT_TABLE_TRANSACTION, [fullfil_transaction_id, fullfil_output_index], index=TARANT_INDEX_SPENDING_BY_ID_AND_OUTPUT_INDEX)
|
connection.connect()
|
||||||
|
.select(
|
||||||
|
TARANT_TABLE_TRANSACTION,
|
||||||
|
[fullfil_transaction_id, fullfil_output_index],
|
||||||
|
index=TARANT_INDEX_SPENDING_BY_ID_AND_OUTPUT_INDEX,
|
||||||
|
)
|
||||||
.data
|
.data
|
||||||
)
|
)
|
||||||
return get_complete_transactions_by_ids(txids=[inp[0] for inp in _inputs], connection=connection)
|
return get_complete_transactions_by_ids(txids=[inp[0] for inp in _inputs], connection=connection)
|
||||||
@ -238,7 +249,9 @@ def get_latest_block(connection) -> Union[dict, None]:
|
|||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def store_block(connection, block: dict):
|
def store_block(connection, block: dict):
|
||||||
block_unique_id = uuid4().hex
|
block_unique_id = uuid4().hex
|
||||||
connection.connect().insert(TARANT_TABLE_BLOCKS, (block_unique_id, block["app_hash"], block["height"], block[TARANT_TABLE_TRANSACTION]))
|
connection.connect().insert(
|
||||||
|
TARANT_TABLE_BLOCKS, (block_unique_id, block["app_hash"], block["height"], block[TARANT_TABLE_TRANSACTION])
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@ -247,17 +260,18 @@ def get_txids_filtered(connection, asset_ids: list[str], operation: str = "", la
|
|||||||
transactions = []
|
transactions = []
|
||||||
if operation == "CREATE":
|
if operation == "CREATE":
|
||||||
transactions = (
|
transactions = (
|
||||||
connection.connect().select(TARANT_TABLE_TRANSACTION,[asset_ids[0], operation], index="transactions_by_id_and_operation")
|
connection.connect()
|
||||||
|
.select(TARANT_TABLE_TRANSACTION, [asset_ids[0], operation], index="transactions_by_id_and_operation")
|
||||||
.data
|
.data
|
||||||
)
|
)
|
||||||
elif operation == "TRANSFER":
|
elif operation == "TRANSFER":
|
||||||
transactions = (
|
transactions = (
|
||||||
connection.connect().select(TARANT_TABLE_TRANSACTION,asset_ids, index=TARANT_INDEX_TX_BY_ASSET_ID).data
|
connection.connect().select(TARANT_TABLE_TRANSACTION, asset_ids, index=TARANT_INDEX_TX_BY_ASSET_ID).data
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
txs = connection.connect().select(TARANT_TABLE_TRANSACTION,asset_ids, index=TARANT_ID_SEARCH).data
|
txs = connection.connect().select(TARANT_TABLE_TRANSACTION, asset_ids, index=TARANT_ID_SEARCH).data
|
||||||
asset_txs = (
|
asset_txs = (
|
||||||
connection.connect().select(TARANT_TABLE_TRANSACTION,asset_ids, index=TARANT_INDEX_TX_BY_ASSET_ID).data
|
connection.connect().select(TARANT_TABLE_TRANSACTION, asset_ids, index=TARANT_INDEX_TX_BY_ASSET_ID).data
|
||||||
)
|
)
|
||||||
transactions = txs + asset_txs
|
transactions = txs + asset_txs
|
||||||
|
|
||||||
@ -273,7 +287,7 @@ def get_txids_filtered(connection, asset_ids: list[str], operation: str = "", la
|
|||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def get_owned_ids(connection, owner: str) -> list[DbTransaction]:
|
def get_owned_ids(connection, owner: str) -> list[DbTransaction]:
|
||||||
outputs = connection.connect().select(TARANT_TABLE_OUTPUT,owner, index="public_keys").data
|
outputs = connection.connect().select(TARANT_TABLE_OUTPUT, owner, index="public_keys").data
|
||||||
if len(outputs) == 0:
|
if len(outputs) == 0:
|
||||||
return []
|
return []
|
||||||
txids = [output[5] for output in outputs]
|
txids = [output[5] for output in outputs]
|
||||||
@ -324,8 +338,8 @@ def delete_transactions(connection, txn_ids: list):
|
|||||||
for x in range(len(_outputs)):
|
for x in range(len(_outputs)):
|
||||||
connection.connect().call("delete_output", (_outputs[x].id))
|
connection.connect().call("delete_output", (_outputs[x].id))
|
||||||
for _id in txn_ids:
|
for _id in txn_ids:
|
||||||
connection.connect().delete(TARANT_TABLE_TRANSACTION,_id)
|
connection.connect().delete(TARANT_TABLE_TRANSACTION, _id)
|
||||||
connection.connect().delete(TARANT_TABLE_GOVERNANCE,_id)
|
connection.connect().delete(TARANT_TABLE_GOVERNANCE, _id)
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@ -336,8 +350,8 @@ def store_unspent_outputs(connection, *unspent_outputs: list):
|
|||||||
for utxo in unspent_outputs:
|
for utxo in unspent_outputs:
|
||||||
try:
|
try:
|
||||||
output = (
|
output = (
|
||||||
connection.connect().insert(TARANT_TABLE_UTXOS,
|
connection.connect()
|
||||||
(uuid4().hex, utxo["transaction_id"], utxo["output_index"], utxo))
|
.insert(TARANT_TABLE_UTXOS, (uuid4().hex, utxo["transaction_id"], utxo["output_index"], utxo))
|
||||||
.data
|
.data
|
||||||
)
|
)
|
||||||
result.append(output)
|
result.append(output)
|
||||||
@ -354,8 +368,11 @@ def delete_unspent_outputs(connection, *unspent_outputs: list):
|
|||||||
if unspent_outputs:
|
if unspent_outputs:
|
||||||
for utxo in unspent_outputs:
|
for utxo in unspent_outputs:
|
||||||
output = (
|
output = (
|
||||||
connection.connect().delete(TARANT_TABLE_UTXOS,
|
connection.connect()
|
||||||
(utxo["transaction_id"], utxo["output_index"]), index="utxo_by_transaction_id_and_output_index"
|
.delete(
|
||||||
|
TARANT_TABLE_UTXOS,
|
||||||
|
(utxo["transaction_id"], utxo["output_index"]),
|
||||||
|
index="utxo_by_transaction_id_and_output_index",
|
||||||
)
|
)
|
||||||
.data
|
.data
|
||||||
)
|
)
|
||||||
@ -366,20 +383,21 @@ def delete_unspent_outputs(connection, *unspent_outputs: list):
|
|||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def get_unspent_outputs(connection, query=None): # for now we don't have implementation for 'query'.
|
def get_unspent_outputs(connection, query=None): # for now we don't have implementation for 'query'.
|
||||||
_utxos = connection.connect().select(TARANT_TABLE_UTXOS,[]).data
|
_utxos = connection.connect().select(TARANT_TABLE_UTXOS, []).data
|
||||||
return [utx[3] for utx in _utxos]
|
return [utx[3] for utx in _utxos]
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def store_pre_commit_state(connection, state: dict):
|
def store_pre_commit_state(connection, state: dict):
|
||||||
_precommit = connection.connect().select(TARANT_TABLE_PRE_COMMITS,[], limit=1).data
|
_precommit = connection.connect().select(TARANT_TABLE_PRE_COMMITS, [], limit=1).data
|
||||||
_precommitTuple = (
|
_precommitTuple = (
|
||||||
(uuid4().hex, state["height"], state[TARANT_TABLE_TRANSACTION])
|
(uuid4().hex, state["height"], state[TARANT_TABLE_TRANSACTION])
|
||||||
if _precommit is None or len(_precommit) == 0
|
if _precommit is None or len(_precommit) == 0
|
||||||
else _precommit[0]
|
else _precommit[0]
|
||||||
)
|
)
|
||||||
connection.connect().upsert(TARANT_TABLE_PRE_COMMITS,
|
connection.connect().upsert(
|
||||||
|
TARANT_TABLE_PRE_COMMITS,
|
||||||
_precommitTuple,
|
_precommitTuple,
|
||||||
op_list=[("=", 1, state["height"]), ("=", 2, state[TARANT_TABLE_TRANSACTION])],
|
op_list=[("=", 1, state["height"]), ("=", 2, state[TARANT_TABLE_TRANSACTION])],
|
||||||
)
|
)
|
||||||
@ -388,7 +406,7 @@ def store_pre_commit_state(connection, state: dict):
|
|||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def get_pre_commit_state(connection) -> dict:
|
def get_pre_commit_state(connection) -> dict:
|
||||||
_commit = connection.connect().select(TARANT_TABLE_PRE_COMMITS,[], index=TARANT_ID_SEARCH).data
|
_commit = connection.connect().select(TARANT_TABLE_PRE_COMMITS, [], index=TARANT_ID_SEARCH).data
|
||||||
if _commit is None or len(_commit) == 0:
|
if _commit is None or len(_commit) == 0:
|
||||||
return None
|
return None
|
||||||
_commit = sorted(_commit, key=itemgetter(1), reverse=False)[0]
|
_commit = sorted(_commit, key=itemgetter(1), reverse=False)[0]
|
||||||
@ -402,7 +420,8 @@ def store_validator_set(conn, validators_update: dict):
|
|||||||
conn.connect().select(TARANT_TABLE_VALIDATOR_SETS, validators_update["height"], index="height", limit=1).data
|
conn.connect().select(TARANT_TABLE_VALIDATOR_SETS, validators_update["height"], index="height", limit=1).data
|
||||||
)
|
)
|
||||||
unique_id = uuid4().hex if _validator is None or len(_validator) == 0 else _validator[0][0]
|
unique_id = uuid4().hex if _validator is None or len(_validator) == 0 else _validator[0][0]
|
||||||
conn.connect().upsert(TARANT_TABLE_VALIDATOR_SETS,
|
conn.connect().upsert(
|
||||||
|
TARANT_TABLE_VALIDATOR_SETS,
|
||||||
(unique_id, validators_update["height"], validators_update["validators"]),
|
(unique_id, validators_update["height"], validators_update["validators"]),
|
||||||
op_list=[("=", 1, validators_update["height"]), ("=", 2, validators_update["validators"])],
|
op_list=[("=", 1, validators_update["height"]), ("=", 2, validators_update["validators"])],
|
||||||
)
|
)
|
||||||
@ -411,16 +430,16 @@ def store_validator_set(conn, validators_update: dict):
|
|||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def delete_validator_set(connection, height: int):
|
def delete_validator_set(connection, height: int):
|
||||||
_validators = connection.connect().select(TARANT_TABLE_VALIDATOR_SETS,height, index="height").data
|
_validators = connection.connect().select(TARANT_TABLE_VALIDATOR_SETS, height, index="height").data
|
||||||
for _valid in _validators:
|
for _valid in _validators:
|
||||||
connection.connect().delete(TARANT_TABLE_VALIDATOR_SETS,_valid[0])
|
connection.connect().delete(TARANT_TABLE_VALIDATOR_SETS, _valid[0])
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def store_election(connection, election_id: str, height: int, is_concluded: bool):
|
def store_election(connection, election_id: str, height: int, is_concluded: bool):
|
||||||
connection.connect().upsert(TARANT_TABLE_ELECTIONS,
|
connection.connect().upsert(
|
||||||
(election_id, height, is_concluded), op_list=[("=", 1, height), ("=", 2, is_concluded)]
|
TARANT_TABLE_ELECTIONS, (election_id, height, is_concluded), op_list=[("=", 1, height), ("=", 2, is_concluded)]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -428,17 +447,17 @@ def store_election(connection, election_id: str, height: int, is_concluded: bool
|
|||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def store_elections(connection, elections: list):
|
def store_elections(connection, elections: list):
|
||||||
for election in elections:
|
for election in elections:
|
||||||
_election = connection.connect().insert(TARANT_TABLE_ELECTIONS,
|
_election = connection.connect().insert(
|
||||||
(election["election_id"], election["height"], election["is_concluded"])
|
TARANT_TABLE_ELECTIONS, (election["election_id"], election["height"], election["is_concluded"])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def delete_elections(connection, height: int):
|
def delete_elections(connection, height: int):
|
||||||
_elections = connection.connect().select(TARANT_TABLE_ELECTIONS,height, index="height").data
|
_elections = connection.connect().select(TARANT_TABLE_ELECTIONS, height, index="height").data
|
||||||
for _elec in _elections:
|
for _elec in _elections:
|
||||||
connection.connect().delete(TARANT_TABLE_ELECTIONS,_elec[0])
|
connection.connect().delete(TARANT_TABLE_ELECTIONS, _elec[0])
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@ -459,7 +478,7 @@ def get_validator_set(connection, height: int = None):
|
|||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def get_election(connection, election_id: str) -> dict:
|
def get_election(connection, election_id: str) -> dict:
|
||||||
_elections = connection.connect().select(TARANT_TABLE_ELECTIONS,election_id, index=TARANT_ID_SEARCH).data
|
_elections = connection.connect().select(TARANT_TABLE_ELECTIONS, election_id, index=TARANT_ID_SEARCH).data
|
||||||
if _elections is None or len(_elections) == 0:
|
if _elections is None or len(_elections) == 0:
|
||||||
return None
|
return None
|
||||||
_election = sorted(_elections, key=itemgetter(0), reverse=True)[0]
|
_election = sorted(_elections, key=itemgetter(0), reverse=True)[0]
|
||||||
@ -469,9 +488,9 @@ def get_election(connection, election_id: str) -> dict:
|
|||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def get_asset_tokens_for_public_key(connection, asset_id: str, public_key: str) -> list[DbTransaction]:
|
def get_asset_tokens_for_public_key(connection, asset_id: str, public_key: str) -> list[DbTransaction]:
|
||||||
id_transactions = connection.connect().select(TARANT_TABLE_GOVERNANCE,[asset_id]).data
|
id_transactions = connection.connect().select(TARANT_TABLE_GOVERNANCE, [asset_id]).data
|
||||||
asset_id_transactions = (
|
asset_id_transactions = (
|
||||||
connection.connect().select(TARANT_TABLE_GOVERNANCE,[asset_id], index="governance_by_asset_id").data
|
connection.connect().select(TARANT_TABLE_GOVERNANCE, [asset_id], index="governance_by_asset_id").data
|
||||||
)
|
)
|
||||||
|
|
||||||
transactions = id_transactions + asset_id_transactions
|
transactions = id_transactions + asset_id_transactions
|
||||||
@ -481,7 +500,8 @@ def get_asset_tokens_for_public_key(connection, asset_id: str, public_key: str)
|
|||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def store_abci_chain(connection, height: int, chain_id: str, is_synced: bool = True):
|
def store_abci_chain(connection, height: int, chain_id: str, is_synced: bool = True):
|
||||||
connection.connect().upsert(TARANT_TABLE_ABCI_CHAINS,
|
connection.connect().upsert(
|
||||||
|
TARANT_TABLE_ABCI_CHAINS,
|
||||||
(chain_id, height, is_synced),
|
(chain_id, height, is_synced),
|
||||||
op_list=[("=", 0, chain_id), ("=", 1, height), ("=", 2, is_synced)],
|
op_list=[("=", 0, chain_id), ("=", 1, height), ("=", 2, is_synced)],
|
||||||
)
|
)
|
||||||
@ -490,8 +510,8 @@ def store_abci_chain(connection, height: int, chain_id: str, is_synced: bool = T
|
|||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def delete_abci_chain(connection, height: int):
|
def delete_abci_chain(connection, height: int):
|
||||||
chains = connection.connect().select(TARANT_TABLE_ABCI_CHAINS,height, index="height")
|
chains = connection.connect().select(TARANT_TABLE_ABCI_CHAINS, height, index="height")
|
||||||
connection.connect().delete(TARANT_TABLE_ABCI_CHAINS,chains[0][0], index="id")
|
connection.connect().delete(TARANT_TABLE_ABCI_CHAINS, chains[0][0], index="id")
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
|
@ -33,6 +33,8 @@ BANNER = """
|
|||||||
* *
|
* *
|
||||||
****************************************************************************
|
****************************************************************************
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def start_web_api(args):
|
def start_web_api(args):
|
||||||
app_server = server.create_server(
|
app_server = server.create_server(
|
||||||
settings=Config().get()["server"], log_config=Config().get()["log"], planetmint_factory=Validator
|
settings=Config().get()["server"], log_config=Config().get()["log"], planetmint_factory=Validator
|
||||||
@ -69,13 +71,13 @@ def start_abci_server(args):
|
|||||||
|
|
||||||
abci_server_app = None
|
abci_server_app = None
|
||||||
|
|
||||||
publisher_queue=exchange.get_publisher_queue()
|
publisher_queue = exchange.get_publisher_queue()
|
||||||
if args.experimental_parallel_validation:
|
if args.experimental_parallel_validation:
|
||||||
abci_server_app = ParallelValidationApp(events_queue=publisher_queue)
|
abci_server_app = ParallelValidationApp(events_queue=publisher_queue)
|
||||||
else:
|
else:
|
||||||
abci_server_app = ApplicationLogic(events_queue=publisher_queue)
|
abci_server_app = ApplicationLogic(events_queue=publisher_queue)
|
||||||
|
|
||||||
app = ABCIServer( abci_server_app )
|
app = ABCIServer(abci_server_app)
|
||||||
app.run()
|
app.run()
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ def test_store_block(db_conn):
|
|||||||
block = Block(app_hash="random_utxo", height=3, transactions=[])
|
block = Block(app_hash="random_utxo", height=3, transactions=[])
|
||||||
query.store_block(connection=db_conn, block=block._asdict())
|
query.store_block(connection=db_conn, block=block._asdict())
|
||||||
# block = query.get_block(connection=db_conn)
|
# block = query.get_block(connection=db_conn)
|
||||||
blocks = db_conn.connect().select("blocks",[]).data
|
blocks = db_conn.connect().select("blocks", []).data
|
||||||
assert len(blocks) == 1
|
assert len(blocks) == 1
|
||||||
|
|
||||||
|
|
||||||
@ -86,9 +86,9 @@ def test_store_pre_commit_state(db_conn):
|
|||||||
def test_get_pre_commit_state(db_conn):
|
def test_get_pre_commit_state(db_conn):
|
||||||
from planetmint.backend.tarantool.sync_io import query
|
from planetmint.backend.tarantool.sync_io import query
|
||||||
|
|
||||||
all_pre = db_conn.connect().select("pre_commits",[]).data
|
all_pre = db_conn.connect().select("pre_commits", []).data
|
||||||
for pre in all_pre:
|
for pre in all_pre:
|
||||||
db_conn.connect().delete("pre_commits",pre[0])
|
db_conn.connect().delete("pre_commits", pre[0])
|
||||||
# TODO First IN, First OUT
|
# TODO First IN, First OUT
|
||||||
state = dict(height=3, transactions=[])
|
state = dict(height=3, transactions=[])
|
||||||
# db_context.conn.db.pre_commit.insert_one
|
# db_context.conn.db.pre_commit.insert_one
|
||||||
|
@ -38,7 +38,7 @@ def test_middleware_does_notstrip_content_type_from_other_methods():
|
|||||||
assert "CONTENT_TYPE" in mock.call_args[0][0]
|
assert "CONTENT_TYPE" in mock.call_args[0][0]
|
||||||
|
|
||||||
|
|
||||||
def test_get_outputs_endpoint_with_content_type(client, user_pk,_bdb):
|
def test_get_outputs_endpoint_with_content_type(client, user_pk, _bdb):
|
||||||
res = client.get(
|
res = client.get(
|
||||||
OUTPUTS_ENDPOINT + "?public_key={}".format(user_pk), headers=[("Content-Type", "application/json")]
|
OUTPUTS_ENDPOINT + "?public_key={}".format(user_pk), headers=[("Content-Type", "application/json")]
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user