mirror of
https://github.com/planetmint/planetmint.git
synced 2025-03-30 15:08:31 +00:00
blackified
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
fc987abe51
commit
826c803798
@ -126,6 +126,7 @@ def get_transactions_by_metadata(connection, metadata: str, limit: int = 1000) -
|
||||
tx_ids = [tx[0] for tx in txs]
|
||||
return get_complete_transactions_by_ids(connection, tx_ids)
|
||||
|
||||
|
||||
@register_query(TarantoolDBConnection)
|
||||
@catch_db_exception
|
||||
def store_transaction_outputs(connection, output: Output, index: int, table=TARANT_TABLE_OUTPUT) -> str:
|
||||
@ -337,7 +338,9 @@ def delete_transactions(connection, txn_ids: list):
|
||||
_outputs = get_outputs_by_tx_id(connection, _id)
|
||||
for x in range(len(_outputs)):
|
||||
connection.connect().call("delete_output", (_outputs[x].id))
|
||||
connection.connect().delete(TARANT_TABLE_UTXOS, (_id,_outputs[x].index), index="utxo_by_transaction_id_and_output_index")
|
||||
connection.connect().delete(
|
||||
TARANT_TABLE_UTXOS, (_id, _outputs[x].index), index="utxo_by_transaction_id_and_output_index"
|
||||
)
|
||||
for _id in txn_ids:
|
||||
connection.connect().delete(TARANT_TABLE_TRANSACTION, _id)
|
||||
connection.connect().delete(TARANT_TABLE_GOVERNANCE, _id)
|
||||
|
@ -12,7 +12,12 @@ from planetmint.const import GOVERNANCE_TRANSACTION_TYPES
|
||||
from planetmint.model.fastquery import FastQuery
|
||||
from planetmint.abci.utils import key_from_base64, merkleroot
|
||||
from planetmint.backend.connection import Connection
|
||||
from planetmint.backend.tarantool.const import TARANT_TABLE_TRANSACTION, TARANT_TABLE_GOVERNANCE, TARANT_TABLE_UTXOS, TARANT_TABLE_OUTPUT
|
||||
from planetmint.backend.tarantool.const import (
|
||||
TARANT_TABLE_TRANSACTION,
|
||||
TARANT_TABLE_GOVERNANCE,
|
||||
TARANT_TABLE_UTXOS,
|
||||
TARANT_TABLE_OUTPUT,
|
||||
)
|
||||
from planetmint.backend.models.block import Block
|
||||
from planetmint.backend.models.output import Output
|
||||
from planetmint.backend.models.asset import Asset
|
||||
@ -279,16 +284,20 @@ class DataAccessor:
|
||||
def get_asset_tokens_for_public_key(self, transaction_id, election_pk):
|
||||
txns = backend.query.get_asset_tokens_for_public_key(self.connection, transaction_id, election_pk)
|
||||
return txns
|
||||
|
||||
|
||||
def update_utxoset(self, transaction):
|
||||
spent_outputs = [
|
||||
{"output_index": input["fulfills"]["output_index"], "transaction_id": input["fulfills"]["transaction_id"]}
|
||||
for input in transaction["inputs"] if input["fulfills"] != None]
|
||||
{"output_index": input["fulfills"]["output_index"], "transaction_id": input["fulfills"]["transaction_id"]}
|
||||
for input in transaction["inputs"]
|
||||
if input["fulfills"] != None
|
||||
]
|
||||
|
||||
if spent_outputs:
|
||||
backend.query.delete_unspent_outputs(self.connection, spent_outputs)
|
||||
[
|
||||
backend.query.store_transaction_outputs(self.connection, Output.outputs_dict(output, transaction["id"]), index, TARANT_TABLE_UTXOS)
|
||||
backend.query.store_transaction_outputs(
|
||||
self.connection, Output.outputs_dict(output, transaction["id"]), index, TARANT_TABLE_UTXOS
|
||||
)
|
||||
for index, output in enumerate(transaction["outputs"])
|
||||
]
|
||||
|
||||
@ -318,9 +327,7 @@ class DataAccessor:
|
||||
utxoset = backend.query.get_unspent_outputs(self.connection)
|
||||
# TODO Once ready, use the already pre-computed utxo_hash field.
|
||||
# See common/transactions.py for details.
|
||||
|
||||
print(utxoset)
|
||||
|
||||
|
||||
hashes = [
|
||||
sha3_256("{}{}".format(utxo["transaction_id"], utxo["output_index"]).encode()).digest() for utxo in utxoset
|
||||
]
|
||||
|
@ -185,12 +185,12 @@ def test_store_bulk_transaction(mocker, b, signed_create_tx, signed_transfer_tx)
|
||||
@pytest.mark.bdb
|
||||
def test_delete_zero_unspent_outputs(b, alice):
|
||||
from planetmint.backend.tarantool.sync_io import query
|
||||
|
||||
utxo_space = b.models.connection.get_space("utxos")
|
||||
|
||||
tx = Create.generate(
|
||||
[alice.public_key],
|
||||
[([alice.public_key], 8), ([alice.public_key], 1)]
|
||||
).sign([alice.private_key])
|
||||
tx = Create.generate([alice.public_key], [([alice.public_key], 8), ([alice.public_key], 1)]).sign(
|
||||
[alice.private_key]
|
||||
)
|
||||
|
||||
b.models.store_bulk_transactions([tx])
|
||||
|
||||
@ -203,12 +203,12 @@ def test_delete_zero_unspent_outputs(b, alice):
|
||||
@pytest.mark.bdb
|
||||
def test_delete_one_unspent_outputs(b, alice):
|
||||
from planetmint.backend.tarantool.sync_io import query
|
||||
|
||||
utxo_space = b.models.connection.get_space("utxos")
|
||||
|
||||
tx = Create.generate(
|
||||
[alice.public_key],
|
||||
[([alice.public_key], 8), ([alice.public_key], 1)]
|
||||
).sign([alice.private_key])
|
||||
tx = Create.generate([alice.public_key], [([alice.public_key], 8), ([alice.public_key], 1)]).sign(
|
||||
[alice.private_key]
|
||||
)
|
||||
|
||||
b.models.store_bulk_transactions([tx])
|
||||
|
||||
@ -222,16 +222,19 @@ def test_delete_one_unspent_outputs(b, alice):
|
||||
@pytest.mark.bdb
|
||||
def test_delete_many_unspent_outputs(b, alice):
|
||||
from planetmint.backend.tarantool.sync_io import query
|
||||
|
||||
utxo_space = b.models.connection.get_space("utxos")
|
||||
|
||||
tx = Create.generate(
|
||||
[alice.public_key],
|
||||
[([alice.public_key], 8), ([alice.public_key], 1), ([alice.public_key], 4)]
|
||||
[alice.public_key], [([alice.public_key], 8), ([alice.public_key], 1), ([alice.public_key], 4)]
|
||||
).sign([alice.private_key])
|
||||
|
||||
b.models.store_bulk_transactions([tx])
|
||||
|
||||
query.delete_unspent_outputs(b.models.connection, [{"transaction_id": tx.id, "output_index": 0},{"transaction_id": tx.id, "output_index": 2}])
|
||||
query.delete_unspent_outputs(
|
||||
b.models.connection,
|
||||
[{"transaction_id": tx.id, "output_index": 0}, {"transaction_id": tx.id, "output_index": 2}],
|
||||
)
|
||||
res1 = utxo_space.select([tx.id, 1], index="utxo_by_transaction_id_and_output_index").data
|
||||
res2 = utxo_space.select([tx.id, 0], index="utxo_by_transaction_id_and_output_index").data
|
||||
assert len(res1) + len(res2) == 1
|
||||
@ -243,10 +246,7 @@ def test_get_utxoset_merkle_root_when_no_utxo(b):
|
||||
|
||||
@pytest.mark.bdb
|
||||
def test_get_utxoset_merkle_root(b, user_sk, user_pk):
|
||||
tx = Create.generate(
|
||||
[user_pk],
|
||||
[([user_pk], 8), ([user_pk], 1), ([user_pk], 4)]
|
||||
).sign([user_sk])
|
||||
tx = Create.generate([user_pk], [([user_pk], 8), ([user_pk], 1), ([user_pk], 4)]).sign([user_sk])
|
||||
|
||||
b.models.store_bulk_transactions([tx])
|
||||
|
||||
|
@ -125,10 +125,6 @@ def generate_election(b, cls, public_key, private_key, asset_data, voter_keys):
|
||||
return election, votes
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class ProcessGroup(object):
|
||||
def __init__(self, concurrency=None, group=None, target=None, name=None, args=None, kwargs=None, daemon=None):
|
||||
self.concurrency = concurrency or multiprocessing.cpu_count()
|
||||
|
Loading…
x
Reference in New Issue
Block a user