logging: basics
This commit is contained in:
@@ -31,9 +31,10 @@ from collections import defaultdict
|
||||
from typing import Dict, Optional
|
||||
|
||||
from . import util, bitcoin
|
||||
from .util import PrintError, profiler, WalletFileException, multisig_type, TxMinedInfo
|
||||
from .util import profiler, WalletFileException, multisig_type, TxMinedInfo
|
||||
from .keystore import bip44_derivation
|
||||
from .transaction import Transaction
|
||||
from .logging import Logger
|
||||
|
||||
# seed_version is now used for the version of the wallet file
|
||||
|
||||
@@ -50,9 +51,10 @@ class JsonDBJsonEncoder(util.MyEncoder):
|
||||
return super().default(obj)
|
||||
|
||||
|
||||
class JsonDB(PrintError):
|
||||
class JsonDB(Logger):
|
||||
|
||||
def __init__(self, raw, *, manual_upgrades):
|
||||
Logger.__init__(self)
|
||||
self.lock = threading.RLock()
|
||||
self.data = {}
|
||||
self._modified = False
|
||||
@@ -98,7 +100,7 @@ class JsonDB(PrintError):
|
||||
json.dumps(key, cls=JsonDBJsonEncoder)
|
||||
json.dumps(value, cls=JsonDBJsonEncoder)
|
||||
except:
|
||||
self.print_error(f"json error: cannot save {repr(key)} ({repr(value)})")
|
||||
self.logger.info(f"json error: cannot save {repr(key)} ({repr(value)})")
|
||||
return False
|
||||
if value is not None:
|
||||
if self.data.get(key) != value:
|
||||
@@ -137,7 +139,7 @@ class JsonDB(PrintError):
|
||||
json.dumps(key)
|
||||
json.dumps(value)
|
||||
except:
|
||||
self.print_error('Failed to convert label to json format', key)
|
||||
self.logger.info(f'Failed to convert label to json format: {key}')
|
||||
continue
|
||||
self.data[key] = value
|
||||
if not isinstance(self.data, dict):
|
||||
@@ -198,7 +200,7 @@ class JsonDB(PrintError):
|
||||
|
||||
@profiler
|
||||
def upgrade(self):
|
||||
self.print_error('upgrading wallet format')
|
||||
self.logger.info('upgrading wallet format')
|
||||
self._convert_imported()
|
||||
self._convert_wallet_type()
|
||||
self._convert_account()
|
||||
@@ -755,14 +757,14 @@ class JsonDB(PrintError):
|
||||
# remove unreferenced tx
|
||||
for tx_hash in list(self.transactions.keys()):
|
||||
if not self.get_txi(tx_hash) and not self.get_txo(tx_hash):
|
||||
self.print_error("removing unreferenced tx", tx_hash)
|
||||
self.logger.info(f"removing unreferenced tx: {tx_hash}")
|
||||
self.transactions.pop(tx_hash)
|
||||
# remove unreferenced outpoints
|
||||
for prevout_hash in self.spent_outpoints.keys():
|
||||
d = self.spent_outpoints[prevout_hash]
|
||||
for prevout_n, spending_txid in list(d.items()):
|
||||
if spending_txid not in self.transactions:
|
||||
self.print_error("removing unreferenced spent outpoint")
|
||||
self.logger.info("removing unreferenced spent outpoint")
|
||||
d.pop(prevout_n)
|
||||
|
||||
@modifier
|
||||
|
||||
Reference in New Issue
Block a user