mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-25 06:55:45 +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.migrations.chain_migration_election import ChainMigrationElection
|
||||
from planetmint.lib import Planetmint
|
||||
from planetmint.core import App
|
||||
|
||||
Transaction.register_type(Transaction.CREATE, 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
|
||||
_txassets = assetsxspace.select(txid, index="assetid_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 = {
|
||||
"id": txid,
|
||||
"version": _txobject[2],
|
||||
"operation": _txobject[1],
|
||||
"inputs": [
|
||||
{
|
||||
"owners_before": _in[2],
|
||||
@ -47,14 +48,20 @@ def _group_transaction_by_ids(connection, txids: list):
|
||||
_in[4]) > 0 else None,
|
||||
"fulfillment": _in[1]
|
||||
} for _in in _txinputs
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"operation": _txobject[1],
|
||||
"metadata": None,
|
||||
"asset": None,
|
||||
"version": _txobject[2],
|
||||
"id": txid,
|
||||
}
|
||||
if _txoutputs[0][7] is None:
|
||||
_obj["outputs"] = [
|
||||
{
|
||||
"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
|
||||
]
|
||||
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]],
|
||||
"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
|
||||
]
|
||||
|
||||
@ -76,28 +84,9 @@ def _group_transaction_by_ids(connection, txids: list):
|
||||
}
|
||||
_obj["metadata"] = _txmeta[0][1] if len(_txmeta) == 1 else None
|
||||
_transactions.append(_obj)
|
||||
|
||||
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)
|
||||
def store_transactions(connection, signed_transactions: list):
|
||||
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])
|
||||
|
||||
|
||||
@register_query(TarantoolDB)
|
||||
def text_search(conn, search, *, language='english', case_sensitive=False,
|
||||
# TODO review text search in tarantool (maybe, remove)
|
||||
diacritic_sensitive=False, text_score=False, limit=0, table='assets'):
|
||||
cursor = conn.run(
|
||||
conn.collection(table)
|
||||
.find({'$text': {
|
||||
'$search': search,
|
||||
'$language': language,
|
||||
'$caseSensitive': case_sensitive,
|
||||
'$diacriticSensitive': diacritic_sensitive}},
|
||||
{'score': {'$meta': 'textScore'}, '_id': False})
|
||||
.sort([('score', {'$meta': 'textScore'})])
|
||||
.limit(limit))
|
||||
|
||||
if text_score:
|
||||
return cursor
|
||||
|
||||
return (_remove_text_score(obj) for obj in cursor)
|
||||
# @register_query(TarantoolDB)
|
||||
# def text_search(conn, search, *, language='english', case_sensitive=False,
|
||||
# # TODO review text search in tarantool (maybe, remove)
|
||||
# diacritic_sensitive=False, text_score=False, limit=0, table='assets'):
|
||||
# cursor = conn.run(
|
||||
# conn.collection(table)
|
||||
# .find({'$text': {
|
||||
# '$search': search,
|
||||
# '$language': language,
|
||||
# '$caseSensitive': case_sensitive,
|
||||
# '$diacriticSensitive': diacritic_sensitive}},
|
||||
# {'score': {'$meta': 'textScore'}, '_id': False})
|
||||
# .sort([('score', {'$meta': 'textScore'})])
|
||||
# .limit(limit))
|
||||
#
|
||||
# if text_score:
|
||||
# return cursor
|
||||
#
|
||||
# return (_remove_text_score(obj) for obj in cursor)
|
||||
|
||||
|
||||
def _remove_text_score(asset):
|
||||
|
||||
@ -1182,7 +1182,6 @@ class Transaction(object):
|
||||
|
||||
tx_body_serialized = Transaction._to_str(tx_body)
|
||||
valid_tx_id = Transaction._to_hash(tx_body_serialized)
|
||||
|
||||
if proposed_tx_id != valid_tx_id:
|
||||
err_msg = ("The transaction's id '{}' isn't equal to "
|
||||
"the hash of its body, i.e. it's not valid.")
|
||||
@ -1344,6 +1343,7 @@ class TransactionPrepare:
|
||||
"asset_data": (),
|
||||
"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):
|
||||
return token_hex(n)
|
||||
@ -1358,30 +1358,34 @@ class TransactionPrepare:
|
||||
self._tuple_transaction["asset"] = ""
|
||||
return
|
||||
|
||||
_id = _asset.get("id")
|
||||
data = _asset.get("data")
|
||||
if _id is not None:
|
||||
_id = self.if_key(dct=_asset, key="id")
|
||||
# data = self.if_key(dct=_asset, key="data")
|
||||
if _id is not False:
|
||||
self._tuple_transaction["asset"] = _id
|
||||
|
||||
if data is not None:
|
||||
else:
|
||||
self._tuple_transaction["is_data"] = True
|
||||
self._tuple_transaction["asset_data"] = (self._transaction["id"], data)
|
||||
self._tuple_transaction["asset"] = self._transaction["id"]
|
||||
_key = list(_asset.keys())[0]
|
||||
self._tuple_transaction["asset_data"] = (self._transaction["id"], _asset[_key])
|
||||
self._tuple_transaction["asset"] = ""
|
||||
|
||||
def __prepare_inputs(self):
|
||||
_inputs = []
|
||||
input_index = 0
|
||||
for _input in self._transaction["inputs"]:
|
||||
_inputs.append((self._transaction["id"],
|
||||
_input["fulfillment"],
|
||||
_input["owners_before"],
|
||||
_input["fulfills"]["transaction_id"] 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
|
||||
|
||||
def __prepare_outputs(self):
|
||||
_outputs = []
|
||||
_keys = []
|
||||
output_index = 0
|
||||
for _output in self._transaction["outputs"]:
|
||||
output_id = self.__create_hash(7)
|
||||
if _output["condition"]["details"].get("subconditions") is None:
|
||||
@ -1392,7 +1396,8 @@ class TransactionPrepare:
|
||||
_output["condition"]["details"]["public_key"],
|
||||
output_id,
|
||||
None,
|
||||
None
|
||||
None,
|
||||
output_index
|
||||
))
|
||||
else:
|
||||
_outputs.append((self._transaction["id"],
|
||||
@ -1402,8 +1407,10 @@ class TransactionPrepare:
|
||||
None,
|
||||
output_id,
|
||||
_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"]:
|
||||
key_id = self.__create_hash(7)
|
||||
_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)
|
||||
|
||||
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
|
||||
outputs that the given ``transaction`` creates.
|
||||
|
||||
Args:
|
||||
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.
|
||||
"""
|
||||
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)],
|
||||
asset_id=tx_create.id)
|
||||
tx_transfer_signed = tx_transfer.sign([user_sk, user_sk])
|
||||
|
||||
print("TX " + str(tx_transfer.to_dict()))
|
||||
b.store_bulk_transactions([tx_create_signed])
|
||||
|
||||
assert tx_transfer_signed.validate(b) == tx_transfer_signed
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
|
||||
from planetmint.config import Config
|
||||
|
||||
|
||||
def test_init_database_is_graceful_if_db_exists():
|
||||
import planetmint
|
||||
from planetmint import backend
|
||||
|
||||
@ -472,7 +472,7 @@ def test_get_spent_key_order(b, user_pk, user_sk, user2_pk, user2_sk):
|
||||
asset=None)\
|
||||
.sign([user_sk])
|
||||
b.store_bulk_transactions([tx1])
|
||||
|
||||
assert tx1.validate(b)
|
||||
inputs = tx1.to_inputs()
|
||||
tx2 = Transaction.transfer([inputs[1]], [([user2_pk], 2)], tx1.id).sign([user_sk])
|
||||
assert tx2.validate(b)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user