mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-25 06:55:45 +00:00
_save_keys_order, changes behaviour
This commit is contained in:
parent
cead415f01
commit
72157f1607
@ -3,6 +3,12 @@ import copy
|
|||||||
from planetmint.common.memoize import HDict
|
from planetmint.common.memoize import HDict
|
||||||
|
|
||||||
|
|
||||||
|
def get_items(_list):
|
||||||
|
for item in _list:
|
||||||
|
if type(item) is dict:
|
||||||
|
yield item
|
||||||
|
|
||||||
|
|
||||||
def _save_keys_order(dictionary):
|
def _save_keys_order(dictionary):
|
||||||
filter_keys = ["asset", "metadata"]
|
filter_keys = ["asset", "metadata"]
|
||||||
if type(dictionary) is dict or type(dictionary) is HDict:
|
if type(dictionary) is dict or type(dictionary) is HDict:
|
||||||
@ -13,14 +19,14 @@ def _save_keys_order(dictionary):
|
|||||||
|
|
||||||
return _map
|
return _map
|
||||||
elif type(dictionary) is list:
|
elif type(dictionary) is list:
|
||||||
dictionary = next(iter(dictionary), None)
|
_maps = []
|
||||||
if dictionary is not None and type(dictionary) is dict:
|
for _item in get_items(_list=dictionary):
|
||||||
_map = {}
|
_map = {}
|
||||||
keys = list(dictionary.keys())
|
keys = list(_item.keys())
|
||||||
for key in keys:
|
for key in keys:
|
||||||
_map[key] = _save_keys_order(dictionary=dictionary[key]) if key not in filter_keys else None
|
_map[key] = _save_keys_order(dictionary=_item[key]) if key not in filter_keys else None
|
||||||
|
_maps.append(_map)
|
||||||
return _map
|
return _maps
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -80,7 +86,6 @@ class TransactionDecompose:
|
|||||||
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
|
|
||||||
if _output["condition"]["details"].get("subconditions") is None:
|
if _output["condition"]["details"].get("subconditions") is None:
|
||||||
tmp_output = (self._transaction["id"],
|
tmp_output = (self._transaction["id"],
|
||||||
_output["amount"],
|
_output["amount"],
|
||||||
@ -104,7 +109,6 @@ class TransactionDecompose:
|
|||||||
output_index
|
output_index
|
||||||
)
|
)
|
||||||
|
|
||||||
# print(f"\noutput: {tmp_output}")
|
|
||||||
_outputs.append(tmp_output)
|
_outputs.append(tmp_output)
|
||||||
output_index = output_index + 1
|
output_index = output_index + 1
|
||||||
key_index = 0
|
key_index = 0
|
||||||
@ -159,7 +163,7 @@ class TransactionCompose:
|
|||||||
def _get_inputs(self):
|
def _get_inputs(self):
|
||||||
_inputs = []
|
_inputs = []
|
||||||
for _input in self.db_results["inputs"]:
|
for _input in self.db_results["inputs"]:
|
||||||
_in = copy.deepcopy( self._map["inputs"] )
|
_in = copy.deepcopy(self._map["inputs"])
|
||||||
_in["fulfillment"] = _input[1]
|
_in["fulfillment"] = _input[1]
|
||||||
if _in["fulfills"] is not None:
|
if _in["fulfills"] is not None:
|
||||||
_in["fulfills"]["transaction_id"] = _input[3]
|
_in["fulfills"]["transaction_id"] = _input[3]
|
||||||
@ -172,10 +176,10 @@ class TransactionCompose:
|
|||||||
_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 = copy.deepcopy( self._map["outputs"] )
|
_out = copy.deepcopy(self._map["outputs"])
|
||||||
_out["amount"] = _output[1]
|
_out["amount"] = _output[1]
|
||||||
_tmp_keys = [(_key[3], _key[4]) for _key in self.db_results["keys"] if _key[2] == _output[5]]
|
_tmp_keys = [(_key[3], _key[4]) for _key in self.db_results["keys"] if _key[2] == _output[5]]
|
||||||
_sorted_keys = sorted(_tmp_keys, key=lambda tup: (tup[1]) )
|
_sorted_keys = sorted(_tmp_keys, key=lambda tup: (tup[1]))
|
||||||
_out["public_keys"] = [_key[0] for _key in _sorted_keys]
|
_out["public_keys"] = [_key[0] for _key in _sorted_keys]
|
||||||
|
|
||||||
_out["condition"]["uri"] = _output[2]
|
_out["condition"]["uri"] = _output[2]
|
||||||
|
|||||||
@ -1308,7 +1308,7 @@ class Transaction(object):
|
|||||||
for input_ in self.inputs:
|
for input_ in self.inputs:
|
||||||
input_txid = input_.fulfills.txid
|
input_txid = input_.fulfills.txid
|
||||||
input_tx = planet.get_transaction(input_txid)
|
input_tx = planet.get_transaction(input_txid)
|
||||||
|
print(f"\ninput_tx ------ {input_tx.to_dict()} -------")
|
||||||
if input_tx is None:
|
if input_tx is None:
|
||||||
for ctxn in current_transactions:
|
for ctxn in current_transactions:
|
||||||
if ctxn.id == input_txid:
|
if ctxn.id == input_txid:
|
||||||
|
|||||||
@ -35,7 +35,6 @@ from planetmint.tendermint_utils import encode_transaction, merkleroot
|
|||||||
from planetmint import exceptions as core_exceptions
|
from planetmint import exceptions as core_exceptions
|
||||||
from planetmint.validation import BaseValidationRules
|
from planetmint.validation import BaseValidationRules
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -139,11 +138,11 @@ class Planetmint(object):
|
|||||||
asset = transaction.pop('asset')
|
asset = transaction.pop('asset')
|
||||||
asset_id = transaction['id']
|
asset_id = transaction['id']
|
||||||
if transaction['operation'] != t.CREATE:
|
if transaction['operation'] != t.CREATE:
|
||||||
asset_id = asset['id']
|
asset_id = asset['id']
|
||||||
assets.append( (asset,
|
assets.append((asset,
|
||||||
transaction['id'],
|
transaction['id'],
|
||||||
asset_id))
|
asset_id))
|
||||||
|
|
||||||
metadata = transaction.pop('metadata')
|
metadata = transaction.pop('metadata')
|
||||||
txn_metadatas.append({'id': transaction['id'],
|
txn_metadatas.append({'id': transaction['id'],
|
||||||
'metadata': metadata})
|
'metadata': metadata})
|
||||||
@ -184,7 +183,7 @@ class Planetmint(object):
|
|||||||
"""
|
"""
|
||||||
if unspent_outputs:
|
if unspent_outputs:
|
||||||
return backend.query.store_unspent_outputs(
|
return backend.query.store_unspent_outputs(
|
||||||
self.connection, *unspent_outputs)
|
self.connection, *unspent_outputs)
|
||||||
|
|
||||||
def get_utxoset_merkle_root(self):
|
def get_utxoset_merkle_root(self):
|
||||||
"""Returns the merkle root of the utxoset. This implies that
|
"""Returns the merkle root of the utxoset. This implies that
|
||||||
@ -238,7 +237,7 @@ class Planetmint(object):
|
|||||||
"""
|
"""
|
||||||
if unspent_outputs:
|
if unspent_outputs:
|
||||||
return backend.query.delete_unspent_outputs(
|
return backend.query.delete_unspent_outputs(
|
||||||
self.connection, *unspent_outputs)
|
self.connection, *unspent_outputs)
|
||||||
|
|
||||||
def is_committed(self, transaction_id):
|
def is_committed(self, transaction_id):
|
||||||
transaction = backend.query.get_transaction(self.connection, transaction_id)
|
transaction = backend.query.get_transaction(self.connection, transaction_id)
|
||||||
@ -246,20 +245,20 @@ class Planetmint(object):
|
|||||||
|
|
||||||
def get_transaction(self, transaction_id):
|
def get_transaction(self, transaction_id):
|
||||||
transaction = backend.query.get_transaction(self.connection, transaction_id)
|
transaction = backend.query.get_transaction(self.connection, transaction_id)
|
||||||
|
print(f"transaction_from_db ::::::: {transaction} :::::::::")
|
||||||
#if transaction:
|
# if transaction:
|
||||||
# asset = backend.query.get_asset(self.connection, transaction_id)
|
# asset = backend.query.get_asset(self.connection, transaction_id)
|
||||||
# metadata = backend.query.get_metadata(self.connection, [transaction_id])
|
# metadata = backend.query.get_metadata(self.connection, [transaction_id])
|
||||||
# if asset:
|
# if asset:
|
||||||
# transaction['asset'] = asset
|
# transaction['asset'] = asset
|
||||||
#
|
#
|
||||||
# if 'metadata' not in transaction:
|
# if 'metadata' not in transaction:
|
||||||
# metadata = metadata[0] if metadata else None
|
# metadata = metadata[0] if metadata else None
|
||||||
# if metadata:
|
# if metadata:
|
||||||
# metadata = metadata.get('metadata')
|
# metadata = metadata.get('metadata')
|
||||||
#
|
#
|
||||||
# transaction.update({'metadata': metadata})
|
# transaction.update({'metadata': metadata})
|
||||||
#
|
#
|
||||||
# transaction = Transaction.from_dict(transaction)
|
# transaction = Transaction.from_dict(transaction)
|
||||||
transaction = Transaction.from_dict(transaction)
|
transaction = Transaction.from_dict(transaction)
|
||||||
|
|
||||||
@ -310,9 +309,9 @@ class Planetmint(object):
|
|||||||
current_spent_transactions = []
|
current_spent_transactions = []
|
||||||
for ctxn in current_transactions:
|
for ctxn in current_transactions:
|
||||||
for ctxn_input in ctxn.inputs:
|
for ctxn_input in ctxn.inputs:
|
||||||
if ctxn_input.fulfills and\
|
if ctxn_input.fulfills and \
|
||||||
ctxn_input.fulfills.txid == txid and\
|
ctxn_input.fulfills.txid == txid and \
|
||||||
ctxn_input.fulfills.output == output:
|
ctxn_input.fulfills.output == output:
|
||||||
current_spent_transactions.append(ctxn)
|
current_spent_transactions.append(ctxn)
|
||||||
|
|
||||||
transaction = None
|
transaction = None
|
||||||
|
|||||||
@ -402,14 +402,14 @@ def test_muiltiple_in_mix_own_multiple_out_mix_own_transfer(alice, b, user_pk,
|
|||||||
tx_create = Transaction.create([alice.public_key], [([user_pk], 50), ([user_pk, alice.public_key], 50)],
|
tx_create = Transaction.create([alice.public_key], [([user_pk], 50), ([user_pk, alice.public_key], 50)],
|
||||||
asset={'name': random.random()})
|
asset={'name': random.random()})
|
||||||
tx_create_signed = tx_create.sign([alice.private_key])
|
tx_create_signed = tx_create.sign([alice.private_key])
|
||||||
|
print(f"\ninit_tx_create ======= {tx_create_signed.to_dict()} ========")
|
||||||
# TRANSFER
|
# TRANSFER
|
||||||
tx_transfer = Transaction.transfer(tx_create.to_inputs(),
|
tx_transfer = Transaction.transfer(tx_create.to_inputs(),
|
||||||
[([alice.public_key], 50), ([alice.public_key, user_pk], 50)],
|
[([alice.public_key], 50), ([alice.public_key, user_pk], 50)],
|
||||||
asset_id=tx_create.id)
|
asset_id=tx_create.id)
|
||||||
tx_transfer_signed = tx_transfer.sign([alice.private_key, user_sk])
|
tx_transfer_signed = tx_transfer.sign([alice.private_key, user_sk])
|
||||||
|
|
||||||
b.store_bulk_transactions([tx_create_signed])
|
b.store_bulk_transactions([tx_create_signed])
|
||||||
|
print(f"\ntx_transfer====== {tx_transfer_signed.to_dict()} ======")
|
||||||
|
|
||||||
assert tx_transfer_signed.validate(b) == tx_transfer_signed
|
assert tx_transfer_signed.validate(b) == tx_transfer_signed
|
||||||
assert len(tx_transfer_signed.outputs) == 2
|
assert len(tx_transfer_signed.outputs) == 2
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user