mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-25 06:55:45 +00:00
tx fixes
This commit is contained in:
parent
f98eb7d463
commit
cd7cd7703c
@ -76,11 +76,11 @@ def store_transactions(connection, signed_transactions: list):
|
|||||||
for _key in txtuples["keys"]:
|
for _key in txtuples["keys"]:
|
||||||
keysxspace.insert(_key)
|
keysxspace.insert(_key)
|
||||||
|
|
||||||
if len(txtuples["metadata"]) > 0:
|
if txtuples["metadata"] is not None:
|
||||||
metadatasxspace.insert(txtuples["metadata"])
|
metadatasxspace.insert(txtuples["metadata"])
|
||||||
|
|
||||||
if txtuples["is_data"]:
|
if txtuples["asset"] is not None:
|
||||||
assetsxspace.insert(txtuples["asset_data"])
|
assetsxspace.insert(txtuples["asset"])
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDB)
|
@register_query(TarantoolDB)
|
||||||
@ -115,11 +115,11 @@ def get_metadata(connection, transaction_ids: list):
|
|||||||
@register_query(TarantoolDB)
|
@register_query(TarantoolDB)
|
||||||
# asset: {"id": "asset_id"}
|
# asset: {"id": "asset_id"}
|
||||||
# asset: {"data": any} -> insert (tx_id, asset["data"]).
|
# 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")
|
space = connection.space("assets")
|
||||||
try:
|
try:
|
||||||
if is_data and tx_id is not None:
|
if tx_id is not None:
|
||||||
space.insert((tx_id, asset))
|
space.insert((asset, tx_id))
|
||||||
else:
|
else:
|
||||||
space.insert((str(asset["id"]), asset))
|
space.insert((str(asset["id"]), asset))
|
||||||
except: # TODO Add Raise For Duplicate
|
except: # TODO Add Raise For Duplicate
|
||||||
@ -131,7 +131,7 @@ def store_assets(connection, assets: list):
|
|||||||
space = connection.space("assets")
|
space = connection.space("assets")
|
||||||
for asset in assets:
|
for asset in assets:
|
||||||
try:
|
try:
|
||||||
space.insert((asset["id"], asset))
|
space.insert((asset, asset["id"]))
|
||||||
except: # TODO Raise ERROR for Duplicate
|
except: # TODO Raise ERROR for Duplicate
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -149,10 +149,11 @@ def get_assets(connection, assets_ids: list) -> list:
|
|||||||
_returned_data = []
|
_returned_data = []
|
||||||
space = connection.space("assets")
|
space = connection.space("assets")
|
||||||
for _id in list(set(assets_ids)):
|
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]
|
asset = asset.data[0]
|
||||||
_returned_data.append(asset[1])
|
_returned_data.append(asset[0])
|
||||||
return sorted(_returned_data, key=lambda k: k["id"], reverse=False)
|
# return sorted(_returned_data, key=lambda k: k["id"], reverse=False)
|
||||||
|
return _returned_data
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDB)
|
@register_query(TarantoolDB)
|
||||||
|
|||||||
@ -31,12 +31,10 @@ class TransactionDecompose:
|
|||||||
"inputs": [],
|
"inputs": [],
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"keys": [],
|
"keys": [],
|
||||||
"metadata": (),
|
"metadata": None,
|
||||||
"asset": "",
|
"asset": None
|
||||||
"asset_data": (),
|
|
||||||
}
|
}
|
||||||
print(f"Transaction ::::: {self._transaction}")
|
print(f"Transaction ::::: {self._transaction}")
|
||||||
self.if_key = lambda dct, key: False if not key in dct.keys() else dct[key]
|
|
||||||
|
|
||||||
def get_map(self, dictionary: dict = None):
|
def get_map(self, dictionary: dict = None):
|
||||||
|
|
||||||
@ -48,23 +46,17 @@ class TransactionDecompose:
|
|||||||
|
|
||||||
def _metadata_check(self):
|
def _metadata_check(self):
|
||||||
metadata = self._transaction.get("metadata")
|
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)
|
||||||
_operation = self._transaction["operation"]
|
|
||||||
|
def __asset_check(self):
|
||||||
_asset = self._transaction.get("asset")
|
_asset = self._transaction.get("asset")
|
||||||
|
|
||||||
if _asset is None:
|
if _asset is None:
|
||||||
self._tuple_transaction["asset"] = ""
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if _operation == "CREATE":
|
self._tuple_transaction["asset"] = (_asset, self._transaction["id"])
|
||||||
self._tuple_transaction["asset_data"] = (self._transaction["id"], _asset, self._transaction["id"])
|
|
||||||
self._tuple_transaction["asset"] = self._transaction["id"]
|
|
||||||
return
|
|
||||||
elif _operation == "TRANSFER":
|
|
||||||
self._tuple_transaction["asset"] = _asset["id"]
|
|
||||||
return
|
|
||||||
|
|
||||||
def __prepare_inputs(self):
|
def __prepare_inputs(self):
|
||||||
_inputs = []
|
_inputs = []
|
||||||
@ -118,7 +110,6 @@ class TransactionDecompose:
|
|||||||
return (self._transaction["id"],
|
return (self._transaction["id"],
|
||||||
self._transaction["operation"],
|
self._transaction["operation"],
|
||||||
self._transaction["version"],
|
self._transaction["version"],
|
||||||
self._tuple_transaction["asset"],
|
|
||||||
self.get_map())
|
self.get_map())
|
||||||
|
|
||||||
def convert_to_tuple(self):
|
def convert_to_tuple(self):
|
||||||
@ -148,18 +139,7 @@ class TransactionCompose:
|
|||||||
return self.db_results["transaction"][0]
|
return self.db_results["transaction"][0]
|
||||||
|
|
||||||
def _get_asset(self):
|
def _get_asset(self):
|
||||||
# if self._get_transaction_operation() == 'CREATE':
|
return None
|
||||||
# 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}
|
|
||||||
|
|
||||||
def _get_metadata(self):
|
def _get_metadata(self):
|
||||||
return self.db_results["metadata"][0][1] if len(self.db_results["metadata"]) == 1 else None
|
return self.db_results["metadata"][0][1] if len(self.db_results["metadata"]) == 1 else None
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user