logging: basics
This commit is contained in:
@@ -33,6 +33,7 @@ from .transaction import Transaction
|
||||
from .util import bh2u, make_aiohttp_session, NetworkJobOnDefaultServer
|
||||
from .bitcoin import address_to_scripthash, is_address
|
||||
from .network import UntrustedServerReturnedError
|
||||
from .logging import Logger
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .network import Network
|
||||
@@ -148,7 +149,7 @@ class Synchronizer(SynchronizerBase):
|
||||
self.requested_histories[addr] = status
|
||||
h = address_to_scripthash(addr)
|
||||
result = await self.network.get_history_for_scripthash(h)
|
||||
self.print_error("receiving history", addr, len(result))
|
||||
self.logger.info(f"receiving history {addr} {len(result)}")
|
||||
hashes = set(map(lambda item: item['tx_hash'], result))
|
||||
hist = list(map(lambda item: (item['tx_hash'], item['height']), result))
|
||||
# tx_fees
|
||||
@@ -156,10 +157,10 @@ class Synchronizer(SynchronizerBase):
|
||||
tx_fees = dict(filter(lambda x:x[1] is not None, tx_fees))
|
||||
# Check that txids are unique
|
||||
if len(hashes) != len(result):
|
||||
self.print_error("error: server history has non-unique txids: %s"% addr)
|
||||
self.logger.info(f"error: server history has non-unique txids: {addr}")
|
||||
# Check that the status corresponds to what was announced
|
||||
elif history_status(hist) != status:
|
||||
self.print_error("error: status mismatch: %s" % addr)
|
||||
self.logger.info(f"error: status mismatch: {addr}")
|
||||
else:
|
||||
# Store received history
|
||||
self.wallet.receive_history_callback(addr, hist, tx_fees)
|
||||
@@ -209,7 +210,7 @@ class Synchronizer(SynchronizerBase):
|
||||
raise SynchronizerFailure(f"received tx does not match expected txid ({tx_hash} != {tx.txid()})")
|
||||
tx_height = self.requested_tx.pop(tx_hash)
|
||||
self.wallet.receive_tx_callback(tx_hash, tx, tx_height)
|
||||
self.print_error(f"received tx {tx_hash} height: {tx_height} bytes: {len(tx.raw)}")
|
||||
self.logger.info(f"received tx {tx_hash} height: {tx_height} bytes: {len(tx.raw)}")
|
||||
# callbacks
|
||||
self.wallet.network.trigger_callback('new_transaction', self.wallet, tx)
|
||||
|
||||
@@ -257,7 +258,7 @@ class Notifier(SynchronizerBase):
|
||||
await self._add_address(addr)
|
||||
|
||||
async def _on_address_status(self, addr, status):
|
||||
self.print_error('new status for addr {}'.format(addr))
|
||||
self.logger.info(f'new status for addr {addr}')
|
||||
headers = {'content-type': 'application/json'}
|
||||
data = {'address': addr, 'status': status}
|
||||
for url in self.watched_addresses[addr]:
|
||||
@@ -266,6 +267,6 @@ class Notifier(SynchronizerBase):
|
||||
async with session.post(url, json=data, headers=headers) as resp:
|
||||
await resp.text()
|
||||
except Exception as e:
|
||||
self.print_error(str(e))
|
||||
self.logger.info(str(e))
|
||||
else:
|
||||
self.print_error('Got Response for {}'.format(addr))
|
||||
self.logger.info(f'Got Response for {addr}')
|
||||
|
||||
Reference in New Issue
Block a user