mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-25 06:55:45 +00:00
Merge branch 'fixed_config' of https://github.com/liviu-lesan/planetmint into fixed_config
This commit is contained in:
commit
f90e3c489a
@ -176,7 +176,7 @@ def get_latest_block(connection): # TODO Here is used DESCENDING OPERATOR
|
||||
heigth = 0
|
||||
txs = []
|
||||
if len(_all_blocks) > 0:
|
||||
_block = sorted(_all_blocks, key=itemgetter(1))[0]
|
||||
_block = sorted(_all_blocks, key=itemgetter(1), reverse=True)[0]
|
||||
space = connection.space("blocks_tx")
|
||||
_txids = space.select(_block[2], index="block_search")
|
||||
_txids = _txids.data
|
||||
@ -308,9 +308,9 @@ def get_block_with_transaction(connection, txid: str):
|
||||
|
||||
@register_query(TarantoolDB)
|
||||
def delete_transactions(connection, txn_ids: list):
|
||||
space = connection.space("transactions")
|
||||
tx_space = connection.space("transactions")
|
||||
for _id in txn_ids:
|
||||
space.delete(_id)
|
||||
tx_space.delete(_id)
|
||||
inputs_space = connection.space("inputs")
|
||||
outputs_space = connection.space("outputs")
|
||||
k_space = connection.space("keys")
|
||||
@ -325,6 +325,13 @@ def delete_transactions(connection, txn_ids: list):
|
||||
for _outpID in _outputs:
|
||||
outputs_space.delete(_outpID[5], index="unique_search")
|
||||
|
||||
meta_space = connection.space("meta_data")
|
||||
for _id in txn_ids:
|
||||
meta_space.delete(_id, index="id_search")
|
||||
|
||||
assets_space = connection.space("assets")
|
||||
for _id in txn_ids:
|
||||
assets_space.delete(_id, index="txid_search")
|
||||
|
||||
# @register_query(TarantoolDB)
|
||||
# def store_unspent_outputs(conn, *unspent_outputs: list):
|
||||
@ -367,8 +374,6 @@ def delete_transactions(connection, txn_ids: list):
|
||||
@register_query(TarantoolDB)
|
||||
def store_pre_commit_state(connection, state: dict):
|
||||
space = connection.space("pre_commits")
|
||||
if not space:
|
||||
return {}
|
||||
_precommit = space.select(state["height"], index="height_search", limit=1)
|
||||
unique_id = token_hex(8) if (len(_precommit.data) == 0) else _precommit.data[0][0]
|
||||
space.upsert((unique_id, state["height"], state["transactions"]),
|
||||
@ -380,15 +385,12 @@ def store_pre_commit_state(connection, state: dict):
|
||||
|
||||
@register_query(TarantoolDB)
|
||||
def get_pre_commit_state(connection):
|
||||
try:
|
||||
space = connection.space("pre_commits")
|
||||
_commit = space.select([], index="id_search", limit=1).data
|
||||
if len(_commit) == 0:
|
||||
return {}
|
||||
_commit = _commit[0]
|
||||
return {"height": _commit[1], "transactions": _commit[2]}
|
||||
except:
|
||||
return {}
|
||||
space = connection.space("pre_commits")
|
||||
_commit = space.select([], index="id_search").data
|
||||
if len(_commit) == 0:
|
||||
return None
|
||||
_commit = sorted(_commit, key=itemgetter(1), reverse=True)[0]
|
||||
return {"height": _commit[1], "transactions": _commit[2]}
|
||||
|
||||
|
||||
@register_query(TarantoolDB)
|
||||
@ -457,7 +459,9 @@ def get_election(connection, election_id: str):
|
||||
space = connection.space("elections")
|
||||
_elections = space.select(election_id, index="id_search")
|
||||
_elections = _elections.data
|
||||
_election = sorted(_elections, key=itemgetter(0))[0]
|
||||
if len(_elections) == 0:
|
||||
return None
|
||||
_election = sorted(_elections, key=itemgetter(0), reverse=True)[0]
|
||||
return {"election_id": _election[0], "height": _election[1], "is_concluded": _election[2]}
|
||||
|
||||
|
||||
|
||||
@ -3,6 +3,12 @@ import copy
|
||||
from planetmint.common.memoize import HDict
|
||||
|
||||
|
||||
def get_items(_list):
|
||||
for item in _list:
|
||||
if type(item) is dict:
|
||||
yield item
|
||||
|
||||
|
||||
def _save_keys_order(dictionary):
|
||||
filter_keys = ["asset", "metadata"]
|
||||
if type(dictionary) is dict or type(dictionary) is HDict:
|
||||
@ -13,14 +19,14 @@ def _save_keys_order(dictionary):
|
||||
|
||||
return _map
|
||||
elif type(dictionary) is list:
|
||||
dictionary = next(iter(dictionary), None)
|
||||
if dictionary is not None and type(dictionary) is dict:
|
||||
_maps = []
|
||||
for _item in get_items(_list=dictionary):
|
||||
_map = {}
|
||||
keys = list(dictionary.keys())
|
||||
keys = list(_item.keys())
|
||||
for key in keys:
|
||||
_map[key] = _save_keys_order(dictionary=dictionary[key]) if key not in filter_keys else None
|
||||
|
||||
return _map
|
||||
_map[key] = _save_keys_order(dictionary=_item[key]) if key not in filter_keys else None
|
||||
_maps.append(_map)
|
||||
return _maps
|
||||
else:
|
||||
return None
|
||||
|
||||
@ -80,7 +86,6 @@ class TransactionDecompose:
|
||||
for _output in self._transaction["outputs"]:
|
||||
# print(f"\noutput: {_output}")
|
||||
output_id = self.__create_hash(7)
|
||||
tmp_output = None
|
||||
if _output["condition"]["details"].get("subconditions") is None:
|
||||
tmp_output = (self._transaction["id"],
|
||||
_output["amount"],
|
||||
@ -104,7 +109,6 @@ class TransactionDecompose:
|
||||
output_index
|
||||
)
|
||||
|
||||
# print(f"\noutput: {tmp_output}")
|
||||
_outputs.append(tmp_output)
|
||||
output_index = output_index + 1
|
||||
key_index = 0
|
||||
@ -159,7 +163,7 @@ class TransactionCompose:
|
||||
def _get_inputs(self):
|
||||
_inputs = []
|
||||
for _input in self.db_results["inputs"]:
|
||||
_in = copy.deepcopy( self._map["inputs"] )
|
||||
_in = copy.deepcopy(self._map["inputs"][_input[-1]])
|
||||
_in["fulfillment"] = _input[1]
|
||||
if _in["fulfills"] is not None:
|
||||
_in["fulfills"]["transaction_id"] = _input[3]
|
||||
@ -171,11 +175,11 @@ class TransactionCompose:
|
||||
def _get_outputs(self):
|
||||
_outputs = []
|
||||
for _output in self.db_results["outputs"]:
|
||||
print (f"\noutput : {_output}")
|
||||
_out = copy.deepcopy( self._map["outputs"] )
|
||||
# print (f"\noutput : {_output}")
|
||||
_out = copy.deepcopy(self._map["outputs"][_output[-1]])
|
||||
_out["amount"] = _output[1]
|
||||
_tmp_keys = [(_key[3], _key[4]) for _key in self.db_results["keys"] if _key[2] == _output[5]]
|
||||
_sorted_keys = sorted(_tmp_keys, key=lambda tup: (tup[1]) )
|
||||
_sorted_keys = sorted(_tmp_keys, key=lambda tup: (tup[1]))
|
||||
_out["public_keys"] = [_key[0] for _key in _sorted_keys]
|
||||
|
||||
_out["condition"]["uri"] = _output[2]
|
||||
|
||||
@ -1308,7 +1308,6 @@ class Transaction(object):
|
||||
for input_ in self.inputs:
|
||||
input_txid = input_.fulfills.txid
|
||||
input_tx = planet.get_transaction(input_txid)
|
||||
|
||||
if input_tx is None:
|
||||
for ctxn in current_transactions:
|
||||
if ctxn.id == input_txid:
|
||||
|
||||
@ -35,7 +35,6 @@ from planetmint.tendermint_utils import encode_transaction, merkleroot
|
||||
from planetmint import exceptions as core_exceptions
|
||||
from planetmint.validation import BaseValidationRules
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -139,11 +138,11 @@ class Planetmint(object):
|
||||
asset = transaction.pop('asset')
|
||||
asset_id = transaction['id']
|
||||
if transaction['operation'] != t.CREATE:
|
||||
asset_id = asset['id']
|
||||
assets.append( (asset,
|
||||
transaction['id'],
|
||||
asset_id))
|
||||
|
||||
asset_id = asset['id']
|
||||
assets.append((asset,
|
||||
transaction['id'],
|
||||
asset_id))
|
||||
|
||||
metadata = transaction.pop('metadata')
|
||||
txn_metadatas.append({'id': transaction['id'],
|
||||
'metadata': metadata})
|
||||
@ -184,7 +183,7 @@ class Planetmint(object):
|
||||
"""
|
||||
if unspent_outputs:
|
||||
return backend.query.store_unspent_outputs(
|
||||
self.connection, *unspent_outputs)
|
||||
self.connection, *unspent_outputs)
|
||||
|
||||
def get_utxoset_merkle_root(self):
|
||||
"""Returns the merkle root of the utxoset. This implies that
|
||||
@ -238,7 +237,7 @@ class Planetmint(object):
|
||||
"""
|
||||
if unspent_outputs:
|
||||
return backend.query.delete_unspent_outputs(
|
||||
self.connection, *unspent_outputs)
|
||||
self.connection, *unspent_outputs)
|
||||
|
||||
def is_committed(self, transaction_id):
|
||||
transaction = backend.query.get_transaction(self.connection, transaction_id)
|
||||
@ -246,20 +245,19 @@ class Planetmint(object):
|
||||
|
||||
def get_transaction(self, transaction_id):
|
||||
transaction = backend.query.get_transaction(self.connection, transaction_id)
|
||||
|
||||
#if transaction:
|
||||
# if transaction:
|
||||
# asset = backend.query.get_asset(self.connection, transaction_id)
|
||||
# metadata = backend.query.get_metadata(self.connection, [transaction_id])
|
||||
# if asset:
|
||||
# transaction['asset'] = asset
|
||||
#
|
||||
#
|
||||
# if 'metadata' not in transaction:
|
||||
# metadata = metadata[0] if metadata else None
|
||||
# if metadata:
|
||||
# metadata = metadata.get('metadata')
|
||||
#
|
||||
#
|
||||
# transaction.update({'metadata': metadata})
|
||||
#
|
||||
#
|
||||
# transaction = Transaction.from_dict(transaction)
|
||||
transaction = Transaction.from_dict(transaction)
|
||||
|
||||
@ -310,9 +308,9 @@ class Planetmint(object):
|
||||
current_spent_transactions = []
|
||||
for ctxn in current_transactions:
|
||||
for ctxn_input in ctxn.inputs:
|
||||
if ctxn_input.fulfills and\
|
||||
ctxn_input.fulfills.txid == txid and\
|
||||
ctxn_input.fulfills.output == output:
|
||||
if ctxn_input.fulfills and \
|
||||
ctxn_input.fulfills.txid == txid and \
|
||||
ctxn_input.fulfills.output == output:
|
||||
current_spent_transactions.append(ctxn)
|
||||
|
||||
transaction = None
|
||||
@ -458,7 +456,6 @@ class Planetmint(object):
|
||||
return backend.query.get_election(self.connection, election_id)
|
||||
|
||||
def get_pre_commit_state(self):
|
||||
print(f"CONNECTION {self.connection} !!!!!")
|
||||
return backend.query.get_pre_commit_state(self.connection)
|
||||
|
||||
def store_pre_commit_state(self, state):
|
||||
|
||||
@ -402,13 +402,11 @@ def test_muiltiple_in_mix_own_multiple_out_mix_own_transfer(alice, b, user_pk,
|
||||
tx_create = Transaction.create([alice.public_key], [([user_pk], 50), ([user_pk, alice.public_key], 50)],
|
||||
asset={'name': random.random()})
|
||||
tx_create_signed = tx_create.sign([alice.private_key])
|
||||
|
||||
# TRANSFER
|
||||
tx_transfer = Transaction.transfer(tx_create.to_inputs(),
|
||||
[([alice.public_key], 50), ([alice.public_key, user_pk], 50)],
|
||||
asset_id=tx_create.id)
|
||||
tx_transfer_signed = tx_transfer.sign([alice.private_key, user_sk])
|
||||
|
||||
b.store_bulk_transactions([tx_create_signed])
|
||||
|
||||
assert tx_transfer_signed.validate(b) == tx_transfer_signed
|
||||
|
||||
@ -465,7 +465,7 @@ def test_validator_update(db_conn):
|
||||
|
||||
for i in range(1, 100, 10):
|
||||
value = gen_validator_update(i)
|
||||
query.store_validator_set(connection=conn, validators_update=value)
|
||||
query.store_validator_set(conn=conn, validators_update=value)
|
||||
|
||||
v1 = query.get_validator_set(connection=conn, height=8)
|
||||
assert v1['height'] == 1
|
||||
|
||||
@ -8,7 +8,6 @@ import pytest
|
||||
from planetmint.common.transaction import TransactionLink
|
||||
from planetmint.models import Transaction
|
||||
|
||||
|
||||
pytestmark = pytest.mark.bdb
|
||||
|
||||
|
||||
@ -17,20 +16,35 @@ def txns(b, user_pk, user_sk, user2_pk, user2_sk):
|
||||
txs = [Transaction.create([user_pk], [([user2_pk], 1)]).sign([user_sk]),
|
||||
Transaction.create([user2_pk], [([user_pk], 1)]).sign([user2_sk]),
|
||||
Transaction.create([user_pk], [([user_pk], 1), ([user2_pk], 1)])
|
||||
.sign([user_sk])]
|
||||
.sign([user_sk])]
|
||||
b.store_bulk_transactions(txs)
|
||||
return txs
|
||||
|
||||
|
||||
def test_get_outputs_by_public_key(b, user_pk, user2_pk, txns):
|
||||
assert b.fastquery.get_outputs_by_public_key(user_pk) == [
|
||||
expected = [
|
||||
TransactionLink(txns[1].id, 0),
|
||||
TransactionLink(txns[2].id, 0)
|
||||
]
|
||||
assert b.fastquery.get_outputs_by_public_key(user2_pk) == [
|
||||
TransactionLink(txns[0].id, 0),
|
||||
TransactionLink(txns[2].id, 1),
|
||||
actual = b.fastquery.get_outputs_by_public_key(user_pk)
|
||||
|
||||
_all_txs = set([tx.txid for tx in expected + actual])
|
||||
assert len(_all_txs) == 2
|
||||
# assert b.fastquery.get_outputs_by_public_key(user_pk) == [ # OLD VERIFICATION
|
||||
# TransactionLink(txns[1].id, 0),
|
||||
# TransactionLink(txns[2].id, 0)
|
||||
# ]
|
||||
actual_1 = b.fastquery.get_outputs_by_public_key(user2_pk)
|
||||
expected_1 = [
|
||||
TransactionLink(txns[0].id, 0),
|
||||
TransactionLink(txns[2].id, 1),
|
||||
]
|
||||
_all_tx_1 = set([tx.txid for tx in actual_1 + expected_1])
|
||||
assert len(_all_tx_1) == 2
|
||||
# assert b.fastquery.get_outputs_by_public_key(user2_pk) == [ # OLD VERIFICATION
|
||||
# TransactionLink(txns[0].id, 0),
|
||||
# TransactionLink(txns[2].id, 1),
|
||||
# ]
|
||||
|
||||
|
||||
def test_filter_spent_outputs(b, user_pk, user_sk):
|
||||
@ -78,11 +92,12 @@ def test_filter_unspent_outputs(b, user_pk, user_sk):
|
||||
|
||||
def test_outputs_query_key_order(b, user_pk, user_sk, user2_pk, user2_sk):
|
||||
from planetmint import backend
|
||||
from planetmint.backend import connect
|
||||
from planetmint.backend.connection import Connection
|
||||
from planetmint.backend import query
|
||||
|
||||
tx1 = Transaction.create([user_pk],
|
||||
[([user_pk], 3), ([user_pk], 2), ([user_pk], 1)])\
|
||||
.sign([user_sk])
|
||||
[([user_pk], 3), ([user_pk], 2), ([user_pk], 1)]) \
|
||||
.sign([user_sk])
|
||||
b.store_bulk_transactions([tx1])
|
||||
|
||||
inputs = tx1.to_inputs()
|
||||
@ -102,10 +117,12 @@ def test_outputs_query_key_order(b, user_pk, user_sk, user2_pk, user2_sk):
|
||||
assert len(outputs) == 1
|
||||
|
||||
# clean the transaction, metdata and asset collection
|
||||
conn = connect()
|
||||
conn.run(conn.collection('transactions').delete_many({}))
|
||||
conn.run(conn.collection('metadata').delete_many({}))
|
||||
conn.run(conn.collection('assets').delete_many({}))
|
||||
# conn = connect()
|
||||
connection = Connection()
|
||||
# conn.run(conn.collection('transactions').delete_many({}))
|
||||
# conn.run(conn.collection('metadata').delete_many({}))
|
||||
# conn.run(conn.collection('assets').delete_many({}))
|
||||
query.delete_transactions(connection, txn_ids=[tx1.id, tx2.id])
|
||||
|
||||
b.store_bulk_transactions([tx1])
|
||||
tx2_dict = tx2.to_dict()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user