mirror of
https://github.com/planetmint/planetmint.git
synced 2025-06-10 08:06:39 +00:00
added update_utxoset, removed deprecated test utils
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
b69a217289
commit
ea8ef5395a
@ -208,7 +208,7 @@ def get_block_with_transaction(connection, txid):
|
|||||||
|
|
||||||
|
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def store_transaction_outputs(connection, output: Output, index: int):
|
def store_transaction_outputs(connection, output: Output, index: int, table: str):
|
||||||
"""Store the transaction outputs.
|
"""Store the transaction outputs.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -126,12 +126,12 @@ def get_transactions_by_metadata(connection, metadata: str, limit: int = 1000) -
|
|||||||
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)
|
||||||
|
|
||||||
|
@register_query(TarantoolDBConnection)
|
||||||
@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, table=TARANT_TABLE_OUTPUT) -> str:
|
||||||
output_id = uuid4().hex
|
output_id = uuid4().hex
|
||||||
connection.connect().insert(
|
connection.connect().insert(
|
||||||
TARANT_TABLE_OUTPUT,
|
table,
|
||||||
(
|
(
|
||||||
output_id,
|
output_id,
|
||||||
int(output.amount),
|
int(output.amount),
|
||||||
@ -363,7 +363,7 @@ def store_unspent_outputs(connection, *unspent_outputs: list):
|
|||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
@catch_db_exception
|
@catch_db_exception
|
||||||
def delete_unspent_outputs(connection, *unspent_outputs: list):
|
def delete_unspent_outputs(connection, unspent_outputs: list):
|
||||||
result = []
|
result = []
|
||||||
if unspent_outputs:
|
if unspent_outputs:
|
||||||
for utxo in unspent_outputs:
|
for utxo in unspent_outputs:
|
||||||
|
@ -11,7 +11,7 @@ from planetmint.const import GOVERNANCE_TRANSACTION_TYPES
|
|||||||
from planetmint.model.fastquery import FastQuery
|
from planetmint.model.fastquery import FastQuery
|
||||||
from planetmint.abci.utils import key_from_base64
|
from planetmint.abci.utils import key_from_base64
|
||||||
from planetmint.backend.connection import Connection
|
from planetmint.backend.connection import Connection
|
||||||
from planetmint.backend.tarantool.const import TARANT_TABLE_TRANSACTION, TARANT_TABLE_GOVERNANCE
|
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.block import Block
|
||||||
from planetmint.backend.models.output import Output
|
from planetmint.backend.models.output import Output
|
||||||
from planetmint.backend.models.asset import Asset
|
from planetmint.backend.models.asset import Asset
|
||||||
@ -37,6 +37,7 @@ class DataAccessor:
|
|||||||
|
|
||||||
backend.query.store_transactions(self.connection, txns, TARANT_TABLE_TRANSACTION)
|
backend.query.store_transactions(self.connection, txns, TARANT_TABLE_TRANSACTION)
|
||||||
backend.query.store_transactions(self.connection, gov_txns, TARANT_TABLE_GOVERNANCE)
|
backend.query.store_transactions(self.connection, gov_txns, TARANT_TABLE_GOVERNANCE)
|
||||||
|
[self.update_utxoset(t) for t in txns + gov_txns]
|
||||||
|
|
||||||
def delete_transactions(self, txs):
|
def delete_transactions(self, txs):
|
||||||
return backend.query.delete_transactions(self.connection, txs)
|
return backend.query.delete_transactions(self.connection, txs)
|
||||||
@ -277,6 +278,18 @@ class DataAccessor:
|
|||||||
txns = backend.query.get_asset_tokens_for_public_key(self.connection, transaction_id, election_pk)
|
txns = backend.query.get_asset_tokens_for_public_key(self.connection, transaction_id, election_pk)
|
||||||
return txns
|
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]
|
||||||
|
|
||||||
|
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)
|
||||||
|
for index, output in enumerate(transaction["outputs"])
|
||||||
|
]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fastquery(self):
|
def fastquery(self):
|
||||||
return FastQuery(self.connection)
|
return FastQuery(self.connection)
|
||||||
|
@ -22,7 +22,7 @@ from ipld import marshal, multihash
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from planetmint.abci.rpc import MODE_COMMIT, MODE_LIST
|
from planetmint.abci.rpc import MODE_COMMIT, MODE_LIST
|
||||||
from tests.utils import delete_unspent_outputs, get_utxoset_merkle_root, store_unspent_outputs, update_utxoset
|
from tests.utils import delete_unspent_outputs, get_utxoset_merkle_root
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.bdb
|
@pytest.mark.bdb
|
||||||
|
@ -171,33 +171,6 @@ def get_utxoset_merkle_root(connection):
|
|||||||
return merkleroot(sorted(hashes))
|
return merkleroot(sorted(hashes))
|
||||||
|
|
||||||
|
|
||||||
def store_unspent_outputs(connection, *unspent_outputs):
|
|
||||||
"""Store the given ``unspent_outputs`` (utxos).
|
|
||||||
|
|
||||||
Args:
|
|
||||||
*unspent_outputs (:obj:`tuple` of :obj:`dict`): Variable
|
|
||||||
length tuple or list of unspent outputs.
|
|
||||||
"""
|
|
||||||
if unspent_outputs:
|
|
||||||
return backend.query.store_unspent_outputs(connection, *unspent_outputs)
|
|
||||||
|
|
||||||
|
|
||||||
def update_utxoset(connection, transaction):
|
|
||||||
"""
|
|
||||||
Update the UTXO set given ``transaction``. That is, remove
|
|
||||||
the outputs that the given ``transaction`` spends, and add the
|
|
||||||
outputs that the given ``transaction`` creates.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
transaction (:obj:`~planetmint.models.Transaction`): A new
|
|
||||||
transaction incoming into the system for which the UTXOF
|
|
||||||
set needs to be updated.
|
|
||||||
"""
|
|
||||||
spent_outputs = [spent_output for spent_output in transaction.spent_outputs]
|
|
||||||
if spent_outputs:
|
|
||||||
delete_unspent_outputs(connection, *spent_outputs)
|
|
||||||
store_unspent_outputs(connection, *[utxo._asdict() for utxo in transaction.unspent_outputs])
|
|
||||||
|
|
||||||
|
|
||||||
class ProcessGroup(object):
|
class ProcessGroup(object):
|
||||||
def __init__(self, concurrency=None, group=None, target=None, name=None, args=None, kwargs=None, daemon=None):
|
def __init__(self, concurrency=None, group=None, target=None, name=None, args=None, kwargs=None, daemon=None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user