mirror of
https://github.com/planetmint/planetmint.git
synced 2025-07-01 18:32:30 +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:
|
||||||
@ -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"""
|
||||||
|
@ -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
|
||||||
|
|
||||||
@ -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,7 +260,8 @@ 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":
|
||||||
@ -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
|
||||||
)
|
)
|
||||||
@ -379,7 +396,8 @@ def store_pre_commit_state(connection, state: dict):
|
|||||||
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])],
|
||||||
)
|
)
|
||||||
@ -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"])],
|
||||||
)
|
)
|
||||||
@ -419,8 +438,8 @@ def delete_validator_set(connection, height: int):
|
|||||||
@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,8 +447,8 @@ 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"])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -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)],
|
||||||
)
|
)
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user