mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-25 23:15:44 +00:00
solved transaction hash problem
This commit is contained in:
parent
89b63920a6
commit
7442ebe5be
@ -9,6 +9,7 @@ from planetmint.upsert_validator import ValidatorElection # noqa
|
|||||||
from planetmint.elections.vote import Vote # noqa
|
from planetmint.elections.vote import Vote # noqa
|
||||||
from planetmint.migrations.chain_migration_election import ChainMigrationElection
|
from planetmint.migrations.chain_migration_election import ChainMigrationElection
|
||||||
from planetmint.lib import Planetmint
|
from planetmint.lib import Planetmint
|
||||||
|
from planetmint.core import App
|
||||||
|
|
||||||
Transaction.register_type(Transaction.CREATE, models.Transaction)
|
Transaction.register_type(Transaction.CREATE, models.Transaction)
|
||||||
Transaction.register_type(Transaction.TRANSFER, models.Transaction)
|
Transaction.register_type(Transaction.TRANSFER, models.Transaction)
|
||||||
|
|||||||
@ -35,10 +35,11 @@ def _group_transaction_by_ids(connection, txids: list):
|
|||||||
_txkeys = keysxspace.select(txid, index="txid_search").data
|
_txkeys = keysxspace.select(txid, index="txid_search").data
|
||||||
_txassets = assetsxspace.select(txid, index="assetid_search").data
|
_txassets = assetsxspace.select(txid, index="assetid_search").data
|
||||||
_txmeta = metaxspace.select(txid, index="id_search").data
|
_txmeta = metaxspace.select(txid, index="id_search").data
|
||||||
|
|
||||||
|
_txinputs = sorted(_txinputs, key=itemgetter(6), reverse=False)
|
||||||
|
_txoutputs = sorted(_txoutputs, key=itemgetter(8), reverse=False)
|
||||||
|
|
||||||
_obj = {
|
_obj = {
|
||||||
"id": txid,
|
|
||||||
"version": _txobject[2],
|
|
||||||
"operation": _txobject[1],
|
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
"owners_before": _in[2],
|
"owners_before": _in[2],
|
||||||
@ -47,14 +48,20 @@ def _group_transaction_by_ids(connection, txids: list):
|
|||||||
_in[4]) > 0 else None,
|
_in[4]) > 0 else None,
|
||||||
"fulfillment": _in[1]
|
"fulfillment": _in[1]
|
||||||
} for _in in _txinputs
|
} for _in in _txinputs
|
||||||
]
|
],
|
||||||
|
"outputs": [],
|
||||||
|
"operation": _txobject[1],
|
||||||
|
"metadata": None,
|
||||||
|
"asset": None,
|
||||||
|
"version": _txobject[2],
|
||||||
|
"id": txid,
|
||||||
}
|
}
|
||||||
if _txoutputs[0][7] is None:
|
if _txoutputs[0][7] is None:
|
||||||
_obj["outputs"] = [
|
_obj["outputs"] = [
|
||||||
{
|
{
|
||||||
"public_keys": [_key[3] for _key in _txkeys if _key[2] == _out[5]],
|
"public_keys": [_key[3] for _key in _txkeys if _key[2] == _out[5]],
|
||||||
"amount": _out[1],
|
"condition": {"details": {"type": _out[3], "public_key": _out[4]}, "uri": _out[2]},
|
||||||
"condition": {"details": {"type": _out[3], "public_key": _out[4]}, "uri": _out[2]}
|
"amount": _out[1]
|
||||||
} for _out in _txoutputs
|
} for _out in _txoutputs
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
@ -62,7 +69,8 @@ def _group_transaction_by_ids(connection, txids: list):
|
|||||||
{
|
{
|
||||||
"public_keys": [_key[3] for _key in _txkeys if _key[2] == _out[5]],
|
"public_keys": [_key[3] for _key in _txkeys if _key[2] == _out[5]],
|
||||||
"amount": _out[1],
|
"amount": _out[1],
|
||||||
"condition": {"uri": _out[2], "details": {"subconditions": _out[7]}, "type": _out[3], "treshold": _out[6]}
|
"condition": {"uri": _out[2], "details": {"subconditions": _out[7]}, "type": _out[3],
|
||||||
|
"treshold": _out[6]}
|
||||||
} for _out in _txoutputs
|
} for _out in _txoutputs
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -76,28 +84,9 @@ def _group_transaction_by_ids(connection, txids: list):
|
|||||||
}
|
}
|
||||||
_obj["metadata"] = _txmeta[0][1] if len(_txmeta) == 1 else None
|
_obj["metadata"] = _txmeta[0][1] if len(_txmeta) == 1 else None
|
||||||
_transactions.append(_obj)
|
_transactions.append(_obj)
|
||||||
|
|
||||||
return _transactions
|
return _transactions
|
||||||
|
|
||||||
|
|
||||||
def __asset_check(object: dict, connection):
|
|
||||||
_asset = object.get("asset")
|
|
||||||
data = None
|
|
||||||
_id = None
|
|
||||||
if _asset is not None:
|
|
||||||
_id = _asset.get("id")
|
|
||||||
data = _asset.get("data") if _id is None else None
|
|
||||||
|
|
||||||
if data is not None:
|
|
||||||
store_asset(connection=connection, asset=object["asset"], tx_id=object["id"], is_data=True)
|
|
||||||
elif _id is not None:
|
|
||||||
data = _id
|
|
||||||
else:
|
|
||||||
data = ""
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDB)
|
@register_query(TarantoolDB)
|
||||||
def store_transactions(connection, signed_transactions: list):
|
def store_transactions(connection, signed_transactions: list):
|
||||||
txspace = connection.space("transactions")
|
txspace = connection.space("transactions")
|
||||||
@ -262,25 +251,25 @@ def get_txids_filtered(connection, asset_id: str, operation: str = None,
|
|||||||
return tuple([elem[0] for elem in _transactions])
|
return tuple([elem[0] for elem in _transactions])
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDB)
|
# @register_query(TarantoolDB)
|
||||||
def text_search(conn, search, *, language='english', case_sensitive=False,
|
# def text_search(conn, search, *, language='english', case_sensitive=False,
|
||||||
# TODO review text search in tarantool (maybe, remove)
|
# # TODO review text search in tarantool (maybe, remove)
|
||||||
diacritic_sensitive=False, text_score=False, limit=0, table='assets'):
|
# diacritic_sensitive=False, text_score=False, limit=0, table='assets'):
|
||||||
cursor = conn.run(
|
# cursor = conn.run(
|
||||||
conn.collection(table)
|
# conn.collection(table)
|
||||||
.find({'$text': {
|
# .find({'$text': {
|
||||||
'$search': search,
|
# '$search': search,
|
||||||
'$language': language,
|
# '$language': language,
|
||||||
'$caseSensitive': case_sensitive,
|
# '$caseSensitive': case_sensitive,
|
||||||
'$diacriticSensitive': diacritic_sensitive}},
|
# '$diacriticSensitive': diacritic_sensitive}},
|
||||||
{'score': {'$meta': 'textScore'}, '_id': False})
|
# {'score': {'$meta': 'textScore'}, '_id': False})
|
||||||
.sort([('score', {'$meta': 'textScore'})])
|
# .sort([('score', {'$meta': 'textScore'})])
|
||||||
.limit(limit))
|
# .limit(limit))
|
||||||
|
#
|
||||||
if text_score:
|
# if text_score:
|
||||||
return cursor
|
# return cursor
|
||||||
|
#
|
||||||
return (_remove_text_score(obj) for obj in cursor)
|
# return (_remove_text_score(obj) for obj in cursor)
|
||||||
|
|
||||||
|
|
||||||
def _remove_text_score(asset):
|
def _remove_text_score(asset):
|
||||||
|
|||||||
@ -1182,7 +1182,6 @@ class Transaction(object):
|
|||||||
|
|
||||||
tx_body_serialized = Transaction._to_str(tx_body)
|
tx_body_serialized = Transaction._to_str(tx_body)
|
||||||
valid_tx_id = Transaction._to_hash(tx_body_serialized)
|
valid_tx_id = Transaction._to_hash(tx_body_serialized)
|
||||||
|
|
||||||
if proposed_tx_id != valid_tx_id:
|
if proposed_tx_id != valid_tx_id:
|
||||||
err_msg = ("The transaction's id '{}' isn't equal to "
|
err_msg = ("The transaction's id '{}' isn't equal to "
|
||||||
"the hash of its body, i.e. it's not valid.")
|
"the hash of its body, i.e. it's not valid.")
|
||||||
@ -1344,6 +1343,7 @@ class TransactionPrepare:
|
|||||||
"asset_data": (),
|
"asset_data": (),
|
||||||
"is_data": False
|
"is_data": False
|
||||||
}
|
}
|
||||||
|
self.if_key = lambda dct, key: False if not key in dct.keys() else dct[key]
|
||||||
|
|
||||||
def __create_hash(self, n: int):
|
def __create_hash(self, n: int):
|
||||||
return token_hex(n)
|
return token_hex(n)
|
||||||
@ -1358,30 +1358,34 @@ class TransactionPrepare:
|
|||||||
self._tuple_transaction["asset"] = ""
|
self._tuple_transaction["asset"] = ""
|
||||||
return
|
return
|
||||||
|
|
||||||
_id = _asset.get("id")
|
_id = self.if_key(dct=_asset, key="id")
|
||||||
data = _asset.get("data")
|
# data = self.if_key(dct=_asset, key="data")
|
||||||
if _id is not None:
|
if _id is not False:
|
||||||
self._tuple_transaction["asset"] = _id
|
self._tuple_transaction["asset"] = _id
|
||||||
|
else:
|
||||||
if data is not None:
|
|
||||||
self._tuple_transaction["is_data"] = True
|
self._tuple_transaction["is_data"] = True
|
||||||
self._tuple_transaction["asset_data"] = (self._transaction["id"], data)
|
_key = list(_asset.keys())[0]
|
||||||
self._tuple_transaction["asset"] = self._transaction["id"]
|
self._tuple_transaction["asset_data"] = (self._transaction["id"], _asset[_key])
|
||||||
|
self._tuple_transaction["asset"] = ""
|
||||||
|
|
||||||
def __prepare_inputs(self):
|
def __prepare_inputs(self):
|
||||||
_inputs = []
|
_inputs = []
|
||||||
|
input_index = 0
|
||||||
for _input in self._transaction["inputs"]:
|
for _input in self._transaction["inputs"]:
|
||||||
_inputs.append((self._transaction["id"],
|
_inputs.append((self._transaction["id"],
|
||||||
_input["fulfillment"],
|
_input["fulfillment"],
|
||||||
_input["owners_before"],
|
_input["owners_before"],
|
||||||
_input["fulfills"]["transaction_id"] if _input["fulfills"] is not None else "",
|
_input["fulfills"]["transaction_id"] if _input["fulfills"] is not None else "",
|
||||||
str(_input["fulfills"]["output_index"]) if _input["fulfills"] is not None else "",
|
str(_input["fulfills"]["output_index"]) if _input["fulfills"] is not None else "",
|
||||||
self.__create_hash(7)))
|
self.__create_hash(7),
|
||||||
|
input_index))
|
||||||
|
input_index = input_index + 1
|
||||||
return _inputs
|
return _inputs
|
||||||
|
|
||||||
def __prepare_outputs(self):
|
def __prepare_outputs(self):
|
||||||
_outputs = []
|
_outputs = []
|
||||||
_keys = []
|
_keys = []
|
||||||
|
output_index = 0
|
||||||
for _output in self._transaction["outputs"]:
|
for _output in self._transaction["outputs"]:
|
||||||
output_id = self.__create_hash(7)
|
output_id = self.__create_hash(7)
|
||||||
if _output["condition"]["details"].get("subconditions") is None:
|
if _output["condition"]["details"].get("subconditions") is None:
|
||||||
@ -1392,7 +1396,8 @@ class TransactionPrepare:
|
|||||||
_output["condition"]["details"]["public_key"],
|
_output["condition"]["details"]["public_key"],
|
||||||
output_id,
|
output_id,
|
||||||
None,
|
None,
|
||||||
None
|
None,
|
||||||
|
output_index
|
||||||
))
|
))
|
||||||
else:
|
else:
|
||||||
_outputs.append((self._transaction["id"],
|
_outputs.append((self._transaction["id"],
|
||||||
@ -1402,8 +1407,10 @@ class TransactionPrepare:
|
|||||||
None,
|
None,
|
||||||
output_id,
|
output_id,
|
||||||
_output["condition"]["details"]["threshold"],
|
_output["condition"]["details"]["threshold"],
|
||||||
_output["condition"]["details"]["subconditions"]
|
_output["condition"]["details"]["subconditions"],
|
||||||
|
output_index
|
||||||
))
|
))
|
||||||
|
output_index = output_index + 1
|
||||||
for _key in _output["public_keys"]:
|
for _key in _output["public_keys"]:
|
||||||
key_id = self.__create_hash(7)
|
key_id = self.__create_hash(7)
|
||||||
_keys.append((key_id, self._transaction["id"], output_id, _key))
|
_keys.append((key_id, self._transaction["id"], output_id, _key))
|
||||||
|
|||||||
@ -153,13 +153,13 @@ class Planetmint(object):
|
|||||||
return backend.query.delete_transactions(self.connection, txs)
|
return backend.query.delete_transactions(self.connection, txs)
|
||||||
|
|
||||||
def update_utxoset(self, transaction):
|
def update_utxoset(self, transaction):
|
||||||
"""Update the UTXO set given ``transaction``. That is, remove
|
self.updated__ = """Update the UTXO set given ``transaction``. That is, remove
|
||||||
the outputs that the given ``transaction`` spends, and add the
|
the outputs that the given ``transaction`` spends, and add the
|
||||||
outputs that the given ``transaction`` creates.
|
outputs that the given ``transaction`` creates.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
transaction (:obj:`~planetmint.models.Transaction`): A new
|
transaction (:obj:`~planetmint.models.Transaction`): A new
|
||||||
transaction incoming into the system for which the UTXO
|
transaction incoming into the system for which the UTXOF
|
||||||
set needs to be updated.
|
set needs to be updated.
|
||||||
"""
|
"""
|
||||||
spent_outputs = [
|
spent_outputs = [
|
||||||
|
|||||||
@ -531,7 +531,7 @@ def test_threshold_same_public_key(alice, b, user_pk, user_sk):
|
|||||||
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [([alice.public_key], 100)],
|
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [([alice.public_key], 100)],
|
||||||
asset_id=tx_create.id)
|
asset_id=tx_create.id)
|
||||||
tx_transfer_signed = tx_transfer.sign([user_sk, user_sk])
|
tx_transfer_signed = tx_transfer.sign([user_sk, user_sk])
|
||||||
|
print("TX " + str(tx_transfer.to_dict()))
|
||||||
b.store_bulk_transactions([tx_create_signed])
|
b.store_bulk_transactions([tx_create_signed])
|
||||||
|
|
||||||
assert tx_transfer_signed.validate(b) == tx_transfer_signed
|
assert tx_transfer_signed.validate(b) == tx_transfer_signed
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
from planetmint.config import Config
|
from planetmint.config import Config
|
||||||
|
|
||||||
|
|
||||||
def test_init_database_is_graceful_if_db_exists():
|
def test_init_database_is_graceful_if_db_exists():
|
||||||
import planetmint
|
import planetmint
|
||||||
from planetmint import backend
|
from planetmint import backend
|
||||||
@ -44,7 +45,7 @@ def test_create_tables():
|
|||||||
index_info = conn.conn[dbname]['transactions'].index_information()
|
index_info = conn.conn[dbname]['transactions'].index_information()
|
||||||
indexes = index_info.keys()
|
indexes = index_info.keys()
|
||||||
assert set(indexes) == {
|
assert set(indexes) == {
|
||||||
'_id_', 'transaction_id', 'asset_id', 'outputs', 'inputs'}
|
'_id_', 'transaction_id', 'asset_id', 'outputs', 'inputs'}
|
||||||
assert index_info['transaction_id']['unique']
|
assert index_info['transaction_id']['unique']
|
||||||
|
|
||||||
index_info = conn.conn[dbname]['blocks'].index_information()
|
index_info = conn.conn[dbname]['blocks'].index_information()
|
||||||
|
|||||||
@ -472,7 +472,7 @@ def test_get_spent_key_order(b, user_pk, user_sk, user2_pk, user2_sk):
|
|||||||
asset=None)\
|
asset=None)\
|
||||||
.sign([user_sk])
|
.sign([user_sk])
|
||||||
b.store_bulk_transactions([tx1])
|
b.store_bulk_transactions([tx1])
|
||||||
|
assert tx1.validate(b)
|
||||||
inputs = tx1.to_inputs()
|
inputs = tx1.to_inputs()
|
||||||
tx2 = Transaction.transfer([inputs[1]], [([user2_pk], 2)], tx1.id).sign([user_sk])
|
tx2 = Transaction.transfer([inputs[1]], [([user2_pk], 2)], tx1.id).sign([user_sk])
|
||||||
assert tx2.validate(b)
|
assert tx2.validate(b)
|
||||||
|
|||||||
@ -62,7 +62,7 @@ def test_bigchain_class_initialization_with_parameters():
|
|||||||
assert planet.connection == connection
|
assert planet.connection == connection
|
||||||
assert planet.connection.host == init_db_kwargs['host']
|
assert planet.connection.host == init_db_kwargs['host']
|
||||||
assert planet.connection.port == init_db_kwargs['port']
|
assert planet.connection.port == init_db_kwargs['port']
|
||||||
#assert planet.connection.name == init_db_kwargs['name']
|
# assert planet.connection.name == init_db_kwargs['name']
|
||||||
assert planet.validation == BaseValidationRules
|
assert planet.validation == BaseValidationRules
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user