mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-25 15:05:49 +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
|
||||
|
||||
|
||||
def get_items(_list):
|
||||
for item in _list:
|
||||
if type(item) is dict:
|
||||
yield item
|
||||
|
||||
|
||||
def _save_keys_order(dictionary):
|
||||
filter_keys = ["asset", "metadata"]
|
||||
if type(dictionary) is dict or type(dictionary) is HDict:
|
||||
@ -13,14 +19,14 @@ def _save_keys_order(dictionary):
|
||||
|
||||
return _map
|
||||
elif type(dictionary) is list:
|
||||
dictionary = next(iter(dictionary), None)
|
||||
if dictionary is not None and type(dictionary) is dict:
|
||||
_maps = []
|
||||
for _item in get_items(_list=dictionary):
|
||||
_map = {}
|
||||
keys = list(dictionary.keys())
|
||||
keys = list(_item.keys())
|
||||
for key in keys:
|
||||
_map[key] = _save_keys_order(dictionary=dictionary[key]) if key not in filter_keys else None
|
||||
|
||||
return _map
|
||||
_map[key] = _save_keys_order(dictionary=_item[key]) if key not in filter_keys else None
|
||||
_maps.append(_map)
|
||||
return _maps
|
||||
else:
|
||||
return None
|
||||
|
||||
@ -80,7 +86,6 @@ class TransactionDecompose:
|
||||
for _output in self._transaction["outputs"]:
|
||||
# print(f"\noutput: {_output}")
|
||||
output_id = self.__create_hash(7)
|
||||
tmp_output = None
|
||||
if _output["condition"]["details"].get("subconditions") is None:
|
||||
tmp_output = (self._transaction["id"],
|
||||
_output["amount"],
|
||||
@ -104,7 +109,6 @@ class TransactionDecompose:
|
||||
output_index
|
||||
)
|
||||
|
||||
# print(f"\noutput: {tmp_output}")
|
||||
_outputs.append(tmp_output)
|
||||
output_index = output_index + 1
|
||||
key_index = 0
|
||||
@ -159,7 +163,7 @@ class TransactionCompose:
|
||||
def _get_inputs(self):
|
||||
_inputs = []
|
||||
for _input in self.db_results["inputs"]:
|
||||
_in = copy.deepcopy( self._map["inputs"] )
|
||||
_in = copy.deepcopy(self._map["inputs"])
|
||||
_in["fulfillment"] = _input[1]
|
||||
if _in["fulfills"] is not None:
|
||||
_in["fulfills"]["transaction_id"] = _input[3]
|
||||
@ -172,10 +176,10 @@ class TransactionCompose:
|
||||
_outputs = []
|
||||
for _output in self.db_results["outputs"]:
|
||||
# print (f"\noutput : {_output}")
|
||||
_out = copy.deepcopy( self._map["outputs"] )
|
||||
_out = copy.deepcopy(self._map["outputs"])
|
||||
_out["amount"] = _output[1]
|
||||
_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["condition"]["uri"] = _output[2]
|
||||
|
||||
@ -1308,7 +1308,7 @@ class Transaction(object):
|
||||
for input_ in self.inputs:
|
||||
input_txid = input_.fulfills.txid
|
||||
input_tx = planet.get_transaction(input_txid)
|
||||
|
||||
print(f"\ninput_tx ------ {input_tx.to_dict()} -------")
|
||||
if input_tx is None:
|
||||
for ctxn in current_transactions:
|
||||
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.validation import BaseValidationRules
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -140,7 +139,7 @@ class Planetmint(object):
|
||||
asset_id = transaction['id']
|
||||
if transaction['operation'] != t.CREATE:
|
||||
asset_id = asset['id']
|
||||
assets.append( (asset,
|
||||
assets.append((asset,
|
||||
transaction['id'],
|
||||
asset_id))
|
||||
|
||||
@ -246,20 +245,20 @@ class Planetmint(object):
|
||||
|
||||
def get_transaction(self, transaction_id):
|
||||
transaction = backend.query.get_transaction(self.connection, transaction_id)
|
||||
|
||||
#if transaction:
|
||||
print(f"transaction_from_db ::::::: {transaction} :::::::::")
|
||||
# if transaction:
|
||||
# asset = backend.query.get_asset(self.connection, transaction_id)
|
||||
# metadata = backend.query.get_metadata(self.connection, [transaction_id])
|
||||
# if asset:
|
||||
# transaction['asset'] = asset
|
||||
#
|
||||
#
|
||||
# if 'metadata' not in transaction:
|
||||
# metadata = metadata[0] if metadata else None
|
||||
# if metadata:
|
||||
# metadata = metadata.get('metadata')
|
||||
#
|
||||
#
|
||||
# transaction.update({'metadata': metadata})
|
||||
#
|
||||
#
|
||||
# transaction = Transaction.from_dict(transaction)
|
||||
transaction = Transaction.from_dict(transaction)
|
||||
|
||||
@ -310,8 +309,8 @@ class Planetmint(object):
|
||||
current_spent_transactions = []
|
||||
for ctxn in current_transactions:
|
||||
for ctxn_input in ctxn.inputs:
|
||||
if ctxn_input.fulfills and\
|
||||
ctxn_input.fulfills.txid == txid and\
|
||||
if ctxn_input.fulfills and \
|
||||
ctxn_input.fulfills.txid == txid and \
|
||||
ctxn_input.fulfills.output == output:
|
||||
current_spent_transactions.append(ctxn)
|
||||
|
||||
|
||||
@ -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)],
|
||||
asset={'name': random.random()})
|
||||
tx_create_signed = tx_create.sign([alice.private_key])
|
||||
|
||||
print(f"\ninit_tx_create ======= {tx_create_signed.to_dict()} ========")
|
||||
# TRANSFER
|
||||
tx_transfer = Transaction.transfer(tx_create.to_inputs(),
|
||||
[([alice.public_key], 50), ([alice.public_key, user_pk], 50)],
|
||||
asset_id=tx_create.id)
|
||||
tx_transfer_signed = tx_transfer.sign([alice.private_key, user_sk])
|
||||
|
||||
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 len(tx_transfer_signed.outputs) == 2
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user