mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 14:35:45 +00:00
s
This commit is contained in:
parent
b7c4acd830
commit
0a8407e69e
@ -34,7 +34,7 @@ class TransactionDecompose:
|
|||||||
"metadata": None,
|
"metadata": None,
|
||||||
"asset": None
|
"asset": None
|
||||||
}
|
}
|
||||||
print(f"Transaction ::::: {self._transaction}")
|
# print(f"Transaction ::::: {self._transaction}")
|
||||||
|
|
||||||
def get_map(self, dictionary: dict = None):
|
def get_map(self, dictionary: dict = None):
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ class TransactionDecompose:
|
|||||||
_keys = []
|
_keys = []
|
||||||
output_index = 0
|
output_index = 0
|
||||||
for _output in self._transaction["outputs"]:
|
for _output in self._transaction["outputs"]:
|
||||||
print(f"\noutput: {_output}")
|
# print(f"\noutput: {_output}")
|
||||||
output_id = self.__create_hash(7)
|
output_id = self.__create_hash(7)
|
||||||
tmp_output = None
|
tmp_output = None
|
||||||
if _output["condition"]["details"].get("subconditions") is None:
|
if _output["condition"]["details"].get("subconditions") is None:
|
||||||
@ -103,7 +103,7 @@ class TransactionDecompose:
|
|||||||
output_index
|
output_index
|
||||||
)
|
)
|
||||||
|
|
||||||
print(f"\noutput: {tmp_output}")
|
# print(f"\noutput: {tmp_output}")
|
||||||
_outputs.append(tmp_output)
|
_outputs.append(tmp_output)
|
||||||
output_index = output_index + 1
|
output_index = output_index + 1
|
||||||
for _key in _output["public_keys"]:
|
for _key in _output["public_keys"]:
|
||||||
@ -144,7 +144,7 @@ class TransactionCompose:
|
|||||||
return self.db_results["transaction"][0]
|
return self.db_results["transaction"][0]
|
||||||
|
|
||||||
def _get_asset(self):
|
def _get_asset(self):
|
||||||
print( f" asset : {self.db_results}" )
|
# print( f" asset : {self.db_results}" )
|
||||||
_asset = iter(self.db_results["asset"])
|
_asset = iter(self.db_results["asset"])
|
||||||
#return _asset
|
#return _asset
|
||||||
return next(iter(next(_asset, iter([]))), None)
|
return next(iter(next(_asset, iter([]))), None)
|
||||||
@ -168,7 +168,7 @@ class TransactionCompose:
|
|||||||
def _get_outputs(self):
|
def _get_outputs(self):
|
||||||
_outputs = []
|
_outputs = []
|
||||||
for _output in self.db_results["outputs"]:
|
for _output in self.db_results["outputs"]:
|
||||||
print (f"\noutput : {_output}")
|
# print (f"\noutput : {_output}")
|
||||||
_out = self._map["outputs"].copy()
|
_out = self._map["outputs"].copy()
|
||||||
_out["amount"] = _output[1]
|
_out["amount"] = _output[1]
|
||||||
_out["public_keys"] = [_key[3] for _key in self.db_results["keys"] if _key[2] == _output[5]]
|
_out["public_keys"] = [_key[3] for _key in self.db_results["keys"] if _key[2] == _output[5]]
|
||||||
@ -180,7 +180,7 @@ class TransactionCompose:
|
|||||||
_out["condition"]["details"]["subconditions"] = _output[7]
|
_out["condition"]["details"]["subconditions"] = _output[7]
|
||||||
_out["condition"]["details"]["type"] = _output[3]
|
_out["condition"]["details"]["type"] = _output[3]
|
||||||
_out["condition"]["details"]["threshold"] = _output[6]
|
_out["condition"]["details"]["threshold"] = _output[6]
|
||||||
print (f"\noutput end : {_out}")
|
# print (f"\noutput end : {_out}")
|
||||||
_outputs.append(_out)
|
_outputs.append(_out)
|
||||||
return _outputs
|
return _outputs
|
||||||
|
|
||||||
@ -194,5 +194,5 @@ class TransactionCompose:
|
|||||||
transaction["inputs"] = self._get_inputs()
|
transaction["inputs"] = self._get_inputs()
|
||||||
transaction["outputs"] = self._get_outputs()
|
transaction["outputs"] = self._get_outputs()
|
||||||
test = transaction["asset"]
|
test = transaction["asset"]
|
||||||
print(f"compose asset : {test}")
|
# print(f"compose asset : {test}")
|
||||||
return transaction
|
return transaction
|
||||||
|
|||||||
@ -1171,7 +1171,7 @@ class Transaction(object):
|
|||||||
"""
|
"""
|
||||||
# NOTE: Remove reference to avoid side effects
|
# NOTE: Remove reference to avoid side effects
|
||||||
# tx_body = deepcopy(tx_body)
|
# tx_body = deepcopy(tx_body)
|
||||||
print( f"\n tx body 1: {tx_body}")
|
# print( f"\n tx body 1: {tx_body}")
|
||||||
tx_body = rapidjson.loads(rapidjson.dumps(tx_body))
|
tx_body = rapidjson.loads(rapidjson.dumps(tx_body))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -1181,13 +1181,13 @@ class Transaction(object):
|
|||||||
|
|
||||||
tx_body['id'] = None
|
tx_body['id'] = None
|
||||||
#tx_body = Transaction._remove_signatures(tx_body)
|
#tx_body = Transaction._remove_signatures(tx_body)
|
||||||
#print(f"\n\n tx_body3: {tx_body}")
|
## print(f"\n\n tx_body3: {tx_body}")
|
||||||
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)
|
||||||
print( f"\n valid TX : {valid_tx_id}")
|
# print( f"\n valid TX : {valid_tx_id}")
|
||||||
print( f"\n proposed TX id : {proposed_tx_id}")
|
# print( f"\n proposed TX id : {proposed_tx_id}")
|
||||||
print( f"\n tx body 2: {tx_body}")
|
# print( f"\n tx body 2: {tx_body}")
|
||||||
print( f"\n tx serialized : {tx_body_serialized}")
|
# print( f"\n tx serialized : {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.")
|
||||||
@ -1223,8 +1223,8 @@ class Transaction(object):
|
|||||||
'id': id
|
'id': id
|
||||||
}
|
}
|
||||||
|
|
||||||
print( f" Schema validation {tx}")
|
# print( f" Schema validation {tx}")
|
||||||
print( f" Schema validation {local_dict}")
|
# print( f" Schema validation {local_dict}")
|
||||||
if not skip_schema_validation:
|
if not skip_schema_validation:
|
||||||
cls.validate_id(local_dict)
|
cls.validate_id(local_dict)
|
||||||
cls.validate_schema(local_dict)
|
cls.validate_schema(local_dict)
|
||||||
@ -1271,7 +1271,7 @@ class Transaction(object):
|
|||||||
tx_ids = list(tx_map.keys())
|
tx_ids = list(tx_map.keys())
|
||||||
metadata_list = list(planet.get_metadata(tx_ids))
|
metadata_list = list(planet.get_metadata(tx_ids))
|
||||||
for metadata in metadata_list:
|
for metadata in metadata_list:
|
||||||
print (f"\n\nmetadata: { metadata}")
|
# print (f"\n\nmetadata: { metadata}")
|
||||||
if 'id' in metadata:
|
if 'id' in metadata:
|
||||||
tx = tx_map[metadata['id']]
|
tx = tx_map[metadata['id']]
|
||||||
tx.update({'metadata': metadata.get('metadata')})
|
tx.update({'metadata': metadata.get('metadata')})
|
||||||
|
|||||||
@ -134,7 +134,7 @@ class Planetmint(object):
|
|||||||
txn_metadatas = []
|
txn_metadatas = []
|
||||||
for t in transactions:
|
for t in transactions:
|
||||||
transaction = t.tx_dict if t.tx_dict else rapidjson.loads(rapidjson.dumps(t.to_dict()))
|
transaction = t.tx_dict if t.tx_dict else rapidjson.loads(rapidjson.dumps(t.to_dict()))
|
||||||
print(f"transaction {transaction}")
|
# print(f"transaction {transaction}")
|
||||||
|
|
||||||
asset = transaction.pop('asset')
|
asset = transaction.pop('asset')
|
||||||
asset_id = transaction['id']
|
asset_id = transaction['id']
|
||||||
@ -300,7 +300,7 @@ class Planetmint(object):
|
|||||||
def get_spent(self, txid, output, current_transactions=[]):
|
def get_spent(self, txid, output, current_transactions=[]):
|
||||||
transactions = backend.query.get_spent(self.connection, txid,
|
transactions = backend.query.get_spent(self.connection, txid,
|
||||||
output)
|
output)
|
||||||
print(f"spent TX: {transactions}")
|
# print(f"spent TX: {transactions}")
|
||||||
transactions = list(transactions) if transactions else []
|
transactions = list(transactions) if transactions else []
|
||||||
if len(transactions) > 1:
|
if len(transactions) > 1:
|
||||||
raise core_exceptions.CriticalDoubleSpend(
|
raise core_exceptions.CriticalDoubleSpend(
|
||||||
@ -319,9 +319,9 @@ class Planetmint(object):
|
|||||||
if len(transactions) + len(current_spent_transactions) > 1:
|
if len(transactions) + len(current_spent_transactions) > 1:
|
||||||
raise DoubleSpend('tx "{}" spends inputs twice'.format(txid))
|
raise DoubleSpend('tx "{}" spends inputs twice'.format(txid))
|
||||||
elif transactions:
|
elif transactions:
|
||||||
print( f"\n\nget tx from DB : {transactions[0]['id']} {transactions[0]}")
|
# print( f"\n\nget tx from DB : {transactions[0]['id']} {transactions[0]}")
|
||||||
transaction=backend.query.get_transactions(self.connection, [transactions[0]['id']])
|
transaction=backend.query.get_transactions(self.connection, [transactions[0]['id']])
|
||||||
print( f"\n\nget tx from DB result: {transaction}")
|
# print( f"\n\nget tx from DB result: {transaction}")
|
||||||
#transaction = Transaction.from_db(self, transactions[0])
|
#transaction = Transaction.from_db(self, transactions[0])
|
||||||
elif current_spent_transactions:
|
elif current_spent_transactions:
|
||||||
transaction = current_spent_transactions[0]
|
transaction = current_spent_transactions[0]
|
||||||
|
|||||||
@ -97,6 +97,8 @@ def test_get_spent_issue_1271(b, alice, bob, carol):
|
|||||||
([carol.public_key], 3)],
|
([carol.public_key], 3)],
|
||||||
asset_id=tx_1.id,
|
asset_id=tx_1.id,
|
||||||
).sign([carol.private_key])
|
).sign([carol.private_key])
|
||||||
|
print(f"TX 3 : {tx_3} ")
|
||||||
|
print(f"TX 3 ID : {tx_3.id} ")
|
||||||
assert tx_3.validate(b)
|
assert tx_3.validate(b)
|
||||||
b.store_bulk_transactions([tx_3])
|
b.store_bulk_transactions([tx_3])
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user