mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-25 15:05:49 +00:00
Merge branch 'fixed_config' of github.com:liviu-lesan/planetmint into fixed_config
This commit is contained in:
commit
cb5973e421
@ -76,11 +76,11 @@ def store_transactions(connection, signed_transactions: list):
|
||||
for _key in txtuples["keys"]:
|
||||
keysxspace.insert(_key)
|
||||
|
||||
if len(txtuples["metadata"]) > 0:
|
||||
if txtuples["metadata"] is not None:
|
||||
metadatasxspace.insert(txtuples["metadata"])
|
||||
|
||||
if txtuples["is_data"]:
|
||||
assetsxspace.insert(txtuples["asset_data"])
|
||||
if txtuples["asset"] is not None:
|
||||
assetsxspace.insert(txtuples["asset"])
|
||||
|
||||
|
||||
@register_query(TarantoolDB)
|
||||
@ -115,11 +115,11 @@ def get_metadata(connection, transaction_ids: list):
|
||||
@register_query(TarantoolDB)
|
||||
# asset: {"id": "asset_id"}
|
||||
# asset: {"data": any} -> insert (tx_id, asset["data"]).
|
||||
def store_asset(connection, asset: dict, tx_id=None, is_data=False): # TODO convert to str all asset["id"]
|
||||
def store_asset(connection, asset: dict, tx_id=None): # TODO convert to str all asset["id"]
|
||||
space = connection.space("assets")
|
||||
try:
|
||||
if is_data and tx_id is not None:
|
||||
space.insert((tx_id, asset))
|
||||
if tx_id is not None:
|
||||
space.insert((asset, tx_id))
|
||||
else:
|
||||
space.insert((str(asset["id"]), asset))
|
||||
except: # TODO Add Raise For Duplicate
|
||||
@ -131,7 +131,7 @@ def store_assets(connection, assets: list):
|
||||
space = connection.space("assets")
|
||||
for asset in assets:
|
||||
try:
|
||||
space.insert((asset["id"], asset))
|
||||
space.insert((asset, asset["id"]))
|
||||
except: # TODO Raise ERROR for Duplicate
|
||||
pass
|
||||
|
||||
@ -149,10 +149,11 @@ def get_assets(connection, assets_ids: list) -> list:
|
||||
_returned_data = []
|
||||
space = connection.space("assets")
|
||||
for _id in list(set(assets_ids)):
|
||||
asset = space.select(str(_id), index="assetid_search")
|
||||
asset = space.select(str(_id), index="txid_search")
|
||||
asset = asset.data[0]
|
||||
_returned_data.append(asset[1])
|
||||
return sorted(_returned_data, key=lambda k: k["id"], reverse=False)
|
||||
_returned_data.append(asset[0])
|
||||
# return sorted(_returned_data, key=lambda k: k["id"], reverse=False)
|
||||
return _returned_data
|
||||
|
||||
|
||||
@register_query(TarantoolDB)
|
||||
|
||||
@ -31,15 +31,13 @@ class TransactionDecompose:
|
||||
"inputs": [],
|
||||
"outputs": [],
|
||||
"keys": [],
|
||||
"metadata": (),
|
||||
"asset": "",
|
||||
"asset_data": (),
|
||||
"is_data": False
|
||||
"metadata": None,
|
||||
"asset": None
|
||||
}
|
||||
print(f"Transaction ::::: { self._transaction}")
|
||||
self.if_key = lambda dct, key: False if not key in dct.keys() else dct[key]
|
||||
print(f"Transaction ::::: {self._transaction}")
|
||||
|
||||
def get_map(self, dictionary: dict = None):
|
||||
|
||||
return _save_keys_order(dictionary=dictionary) if dictionary is not None else _save_keys_order(
|
||||
dictionary=self._transaction)
|
||||
|
||||
@ -48,26 +46,17 @@ class TransactionDecompose:
|
||||
|
||||
def _metadata_check(self):
|
||||
metadata = self._transaction.get("metadata")
|
||||
self._tuple_transaction["metadata"] = (self._transaction["id"], metadata) if metadata is not None else ()
|
||||
if metadata is None:
|
||||
return
|
||||
|
||||
def __asset_check(self): # ASSET CAN BE VERIFIED BY OPERATION TYPE CREATE OR TRANSFER
|
||||
self._tuple_transaction["metadata"] = (self._transaction["id"], metadata)
|
||||
|
||||
def __asset_check(self):
|
||||
_asset = self._transaction.get("asset")
|
||||
print( f"decompose asset : {_asset }")
|
||||
if _asset is None:
|
||||
self._tuple_transaction["asset"] = ""
|
||||
print( f"decompose asset :1 {_asset}")
|
||||
return
|
||||
|
||||
_id = self.if_key(dct=_asset, key="id")
|
||||
if _id is not False:
|
||||
print( f"decompose asset :2 {_asset}")
|
||||
self._tuple_transaction["asset"] = _id
|
||||
return
|
||||
|
||||
self._tuple_transaction["is_data"] = True
|
||||
self._tuple_transaction["asset_data"] = (self._transaction["id"], _asset)
|
||||
self._tuple_transaction["asset"] = ""
|
||||
print( f"decompose asset :3 {_asset}")
|
||||
self._tuple_transaction["asset"] = (_asset, self._transaction["id"])
|
||||
|
||||
def __prepare_inputs(self):
|
||||
_inputs = []
|
||||
@ -121,7 +110,6 @@ class TransactionDecompose:
|
||||
return (self._transaction["id"],
|
||||
self._transaction["operation"],
|
||||
self._transaction["version"],
|
||||
self._tuple_transaction["asset"],
|
||||
self.get_map())
|
||||
|
||||
def convert_to_tuple(self):
|
||||
@ -151,18 +139,7 @@ class TransactionCompose:
|
||||
return self.db_results["transaction"][0]
|
||||
|
||||
def _get_asset(self):
|
||||
# if self._get_transaction_operation() == 'CREATE':
|
||||
# return None
|
||||
if len(self.db_results["transaction"][3]) > 0:
|
||||
print("get_asse 1")
|
||||
return {
|
||||
"id": self.db_results["transaction"][3]
|
||||
}
|
||||
elif len(self.db_results["asset"]) > 0:
|
||||
print("get_asse 2")
|
||||
return self.db_results["asset"][0][1]
|
||||
else:
|
||||
return {'data': None}
|
||||
return None
|
||||
|
||||
def _get_metadata(self):
|
||||
return self.db_results["metadata"][0][1] if len(self.db_results["metadata"]) == 1 else None
|
||||
@ -206,5 +183,5 @@ class TransactionCompose:
|
||||
transaction["inputs"] = self._get_inputs()
|
||||
transaction["outputs"] = self._get_outputs()
|
||||
test = transaction["asset"]
|
||||
print( f"compose asset : { test }")
|
||||
print(f"compose asset : {test}")
|
||||
return transaction
|
||||
|
||||
@ -24,7 +24,9 @@ def test_get_txids_filtered(signed_create_tx, signed_transfer_tx, db_conn):
|
||||
# transfer transaction
|
||||
create_tx_dict = signed_create_tx.to_dict()
|
||||
transfer_tx_dict = signed_transfer_tx.to_dict()
|
||||
|
||||
print(create_tx_dict)
|
||||
print(" ")
|
||||
print(transfer_tx_dict)
|
||||
query.store_transactions(signed_transactions=[create_tx_dict], connection=conn)
|
||||
query.store_transactions(signed_transactions=[transfer_tx_dict], connection=conn)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user