fixed usage of from_db part 1

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2022-04-14 09:45:48 +02:00
parent 6189100d52
commit 8ea911ba64
2 changed files with 13 additions and 6 deletions

View File

@ -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 = []

View File

@ -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]