mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 22:45:44 +00:00
blackified
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
8823514e6c
commit
eee5ae3d91
@ -39,7 +39,9 @@ class DbTransaction:
|
||||
operation=transaction[1],
|
||||
version=transaction[2],
|
||||
metadata=MetaData.from_dict(transaction[3]),
|
||||
assets=Asset.from_list_dict(transaction[4]) if transaction[2] != "2.0" else Asset.from_dict(transaction[4][0]),
|
||||
assets=Asset.from_list_dict(transaction[4])
|
||||
if transaction[2] != "2.0"
|
||||
else Asset.from_dict(transaction[4][0]),
|
||||
inputs=Input.from_list_dict(transaction[5]),
|
||||
script=Script.from_dict(transaction[6]),
|
||||
)
|
||||
@ -66,7 +68,7 @@ class DbTransaction:
|
||||
"outputs": Output.list_to_dict(self.outputs),
|
||||
"operation": self.operation,
|
||||
"metadata": self.metadata.to_dict() if self.metadata is not None else None,
|
||||
"assets": Asset.list_to_dict(self.assets) if self.version!="2.0" else Asset.to_dict(self.assets),
|
||||
"assets": Asset.list_to_dict(self.assets) if self.version != "2.0" else Asset.to_dict(self.assets),
|
||||
"version": self.version,
|
||||
"id": self.id,
|
||||
"script": self.script.to_dict() if self.script is not None else None,
|
||||
|
||||
@ -31,7 +31,7 @@ from planetmint.backend.tarantool.const import (
|
||||
TARANT_TABLE_VALIDATOR_SETS,
|
||||
TARANT_TABLE_UTXOS,
|
||||
TARANT_TABLE_PRE_COMMITS,
|
||||
TARANT_TABLE_ELECTIONS
|
||||
TARANT_TABLE_ELECTIONS,
|
||||
)
|
||||
from planetmint.backend.utils import module_dispatch_registrar
|
||||
from planetmint.backend.models import Asset, Block, Output
|
||||
@ -114,7 +114,7 @@ def store_transaction_outputs(connection, output: Output, index: int) -> str:
|
||||
|
||||
|
||||
@register_query(TarantoolDBConnection)
|
||||
def store_transactions(connection, signed_transactions: list, table = TARANT_TABLE_TRANSACTION):
|
||||
def store_transactions(connection, signed_transactions: list, table=TARANT_TABLE_TRANSACTION):
|
||||
for transaction in signed_transactions:
|
||||
store_transaction(connection, transaction, table)
|
||||
[
|
||||
@ -124,13 +124,13 @@ def store_transactions(connection, signed_transactions: list, table = TARANT_TAB
|
||||
|
||||
|
||||
@register_query(TarantoolDBConnection)
|
||||
def store_transaction(connection, transaction, table = TARANT_TABLE_TRANSACTION):
|
||||
def store_transaction(connection, transaction, table=TARANT_TABLE_TRANSACTION):
|
||||
scripts = None
|
||||
if TARANT_TABLE_SCRIPT in transaction:
|
||||
scripts = transaction[TARANT_TABLE_SCRIPT]
|
||||
asset_obj = Transaction.get_assets_tag(transaction["version"])
|
||||
if( transaction["version"] == "2.0"):
|
||||
asset_array = [ transaction[asset_obj] ]
|
||||
if transaction["version"] == "2.0":
|
||||
asset_array = [transaction[asset_obj]]
|
||||
else:
|
||||
asset_array = transaction[asset_obj]
|
||||
tx = (
|
||||
@ -146,7 +146,7 @@ def store_transaction(connection, transaction, table = TARANT_TABLE_TRANSACTION)
|
||||
connection.run(connection.space(table).insert(tx), only_data=False)
|
||||
except Exception as e:
|
||||
logger.info(f"Could not insert transactions: {e}")
|
||||
if e.args[0] == 3 and e.args[1].startswith('Duplicate key exists in'):
|
||||
if e.args[0] == 3 and e.args[1].startswith("Duplicate key exists in"):
|
||||
raise CriticalDoubleSpend()
|
||||
else:
|
||||
raise OperationDataInsertionError()
|
||||
@ -320,7 +320,7 @@ def get_block_with_transaction(connection, txid: str) -> list[Block]:
|
||||
def delete_transactions(connection, txn_ids: list):
|
||||
try:
|
||||
for _id in txn_ids:
|
||||
_outputs = get_outputs_by_tx_id( connection, _id)
|
||||
_outputs = get_outputs_by_tx_id(connection, _id)
|
||||
for x in range(len(_outputs)):
|
||||
connection.connect().call("delete_output", (_outputs[x].id))
|
||||
for _id in txn_ids:
|
||||
@ -338,7 +338,9 @@ def store_unspent_outputs(connection, *unspent_outputs: list):
|
||||
for utxo in unspent_outputs:
|
||||
try:
|
||||
output = connection.run(
|
||||
connection.space(TARANT_TABLE_UTXOS).insert((uuid4().hex, utxo["transaction_id"], utxo["output_index"], utxo))
|
||||
connection.space(TARANT_TABLE_UTXOS).insert(
|
||||
(uuid4().hex, utxo["transaction_id"], utxo["output_index"], utxo)
|
||||
)
|
||||
)
|
||||
result.append(output)
|
||||
except Exception as e:
|
||||
@ -400,7 +402,9 @@ def get_pre_commit_state(connection) -> dict:
|
||||
|
||||
@register_query(TarantoolDBConnection)
|
||||
def store_validator_set(conn, validators_update: dict):
|
||||
_validator = conn.run(conn.space(TARANT_TABLE_VALIDATOR_SETS).select(validators_update["height"], index="height", limit=1))
|
||||
_validator = conn.run(
|
||||
conn.space(TARANT_TABLE_VALIDATOR_SETS).select(validators_update["height"], index="height", limit=1)
|
||||
)
|
||||
unique_id = uuid4().hex if _validator is None or len(_validator) == 0 else _validator[0][0]
|
||||
try:
|
||||
conn.run(
|
||||
|
||||
@ -892,7 +892,7 @@ class Planetmint(object):
|
||||
self.delete_elections(new_height)
|
||||
|
||||
txns = [self.get_transaction(tx_id) for tx_id in txn_ids]
|
||||
|
||||
|
||||
txns = [Transaction.from_dict(tx.to_dict()) for tx in txns]
|
||||
|
||||
elections = self._get_votes(txns)
|
||||
|
||||
@ -24,7 +24,7 @@ def test_asset_transfer(b, signed_create_tx, user_pk, user_sk, _bdb):
|
||||
# from planetmint.transactions.common.exceptions import AssetIdMismatch
|
||||
|
||||
|
||||
def test_validate_transfer_asset_id_mismatch(b, signed_create_tx, user_pk, user_sk,_bdb):
|
||||
def test_validate_transfer_asset_id_mismatch(b, signed_create_tx, user_pk, user_sk, _bdb):
|
||||
from transactions.common.exceptions import AssetIdMismatch
|
||||
|
||||
tx_transfer = Transfer.generate(signed_create_tx.to_inputs(), [([user_pk], 1)], [signed_create_tx.id])
|
||||
|
||||
@ -50,7 +50,6 @@ class TestBigchainApi(object):
|
||||
with pytest.raises(CriticalDoubleSpend):
|
||||
b.store_bulk_transactions([transfer_tx2])
|
||||
|
||||
|
||||
def test_double_inclusion(self, b, alice):
|
||||
from tarantool.error import DatabaseError
|
||||
|
||||
|
||||
@ -173,11 +173,7 @@ def test_update_utxoset(b, signed_create_tx, signed_transfer_tx, db_conn):
|
||||
def test_store_transaction(mocker, b, signed_create_tx, signed_transfer_tx):
|
||||
mocked_store_transaction = mocker.patch("planetmint.backend.query.store_transactions")
|
||||
b.store_bulk_transactions([signed_create_tx])
|
||||
mocked_store_transaction.assert_any_call(
|
||||
b.connection,
|
||||
[signed_create_tx.to_dict()],
|
||||
"transactions"
|
||||
)
|
||||
mocked_store_transaction.assert_any_call(b.connection, [signed_create_tx.to_dict()], "transactions")
|
||||
mocked_store_transaction.reset_mock()
|
||||
b.store_bulk_transactions([signed_transfer_tx])
|
||||
|
||||
@ -186,11 +182,7 @@ def test_store_transaction(mocker, b, signed_create_tx, signed_transfer_tx):
|
||||
def test_store_bulk_transaction(mocker, b, signed_create_tx, signed_transfer_tx):
|
||||
mocked_store_transactions = mocker.patch("planetmint.backend.query.store_transactions")
|
||||
b.store_bulk_transactions((signed_create_tx,))
|
||||
mocked_store_transactions.assert_any_call(
|
||||
b.connection,
|
||||
[signed_create_tx.to_dict()],
|
||||
"transactions"
|
||||
)
|
||||
mocked_store_transactions.assert_any_call(b.connection, [signed_create_tx.to_dict()], "transactions")
|
||||
mocked_store_transactions.reset_mock()
|
||||
b.store_bulk_transactions((signed_transfer_tx,))
|
||||
|
||||
|
||||
@ -89,7 +89,7 @@ def test_get_spent_issue_1271(b, alice, bob, carol):
|
||||
assert b.validate_transaction(tx_5)
|
||||
|
||||
b.store_bulk_transactions([tx_5])
|
||||
assert b.get_spent(tx_2.id, 0) == tx_5.to_dict()
|
||||
assert b.get_spent(tx_2.id, 0) == tx_5.to_dict()
|
||||
assert not b.get_spent(tx_5.id, 0)
|
||||
assert b.get_outputs_filtered(alice.public_key)
|
||||
assert b.get_outputs_filtered(alice.public_key, spent=False)
|
||||
|
||||
@ -40,7 +40,9 @@ def generate_block(planet):
|
||||
from transactions.common.crypto import generate_key_pair
|
||||
|
||||
alice = generate_key_pair()
|
||||
tx = Create.generate([alice.public_key], [([alice.public_key], 1)], assets=[{"data":None}]).sign([alice.private_key])
|
||||
tx = Create.generate([alice.public_key], [([alice.public_key], 1)], assets=[{"data": None}]).sign(
|
||||
[alice.private_key]
|
||||
)
|
||||
|
||||
code, message = planet.write_transaction(tx, BROADCAST_TX_COMMIT)
|
||||
assert code == 202
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user