From 8ea911ba64508ec8ad204772cbfa85ed2b4e9ccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Eckel?= Date: Thu, 14 Apr 2022 09:45:48 +0200 Subject: [PATCH] fixed usage of from_db part 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jürgen Eckel --- planetmint/common/transaction.py | 13 ++++++++----- planetmint/lib.py | 6 +++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/planetmint/common/transaction.py b/planetmint/common/transaction.py index 837efad..07c7857 100644 --- a/planetmint/common/transaction.py +++ b/planetmint/common/transaction.py @@ -1171,6 +1171,7 @@ class Transaction(object): """ # NOTE: Remove reference to avoid side effects # tx_body = deepcopy(tx_body) + print( f"\n tx body 1: {tx_body}") tx_body = rapidjson.loads(rapidjson.dumps(tx_body)) try: @@ -1185,7 +1186,7 @@ class Transaction(object): valid_tx_id = Transaction._to_hash(tx_body_serialized) print( f"\n valid TX : {valid_tx_id}") print( f"\n proposed TX id : {proposed_tx_id}") - print( f"\n tx body : {tx_body}") + print( f"\n tx body 2: {tx_body}") print( f"\n tx serialized : {tx_body_serialized}") if proposed_tx_id != valid_tx_id: err_msg= ("The transaction's id '{}' isn't equal to " @@ -1211,13 +1212,13 @@ class Transaction(object): id = tx['id'] except KeyError: id = None - + #tx['asset'] = tx['asset'][0] if isinstance( tx['asset'], list) or isinstance( tx['asset'], tuple) else tx['asset'], local_dict= { 'inputs': tx['inputs'], 'outputs': tx['outputs'], 'operation': operation, 'metadata': tx['metadata'], - 'asset': tx['asset'], + 'asset': tx['asset'],#[0] if isinstance( tx['asset'], list) or isinstance( tx['asset'], tuple) else tx['asset'], 'version': tx['version'], 'id': id } @@ -1270,8 +1271,10 @@ class Transaction(object): tx_ids = list(tx_map.keys()) metadata_list = list(planet.get_metadata(tx_ids)) for metadata in metadata_list: - tx = tx_map[metadata['id']] - tx.update({'metadata': metadata.get('metadata')}) + print (f"\n\nmetadata: { metadata}") + if 'id' in metadata: + tx = tx_map[metadata['id']] + tx.update({'metadata': metadata.get('metadata')}) if return_list: tx_list = [] diff --git a/planetmint/lib.py b/planetmint/lib.py index b0e9a7a..2733ade 100644 --- a/planetmint/lib.py +++ b/planetmint/lib.py @@ -300,6 +300,7 @@ class Planetmint(object): def get_spent(self, txid, output, current_transactions=[]): transactions = backend.query.get_spent(self.connection, txid, output) + print(f"spent TX: {transactions}") transactions = list(transactions) if transactions else [] if len(transactions) > 1: raise core_exceptions.CriticalDoubleSpend( @@ -318,7 +319,10 @@ class Planetmint(object): if len(transactions) + len(current_spent_transactions) > 1: raise DoubleSpend('tx "{}" spends inputs twice'.format(txid)) elif transactions: - transaction = Transaction.from_db(self, transactions[0]) + print( f"\n\nget tx from DB : {transactions[0]['id']} {transactions[0]}") + transaction=backend.query.get_transactions(self.connection, [transactions[0]['id']]) + print( f"\n\nget tx from DB result: {transaction}") + #transaction = Transaction.from_db(self, transactions[0]) elif current_spent_transactions: transaction = current_spent_transactions[0]