1200wd / bitcoinlib

Bitcoin and other Cryptocurrencies Library for Python. Includes a fully functional wallet, Mnemonic key generation and management and connection with various service providers to receive and send blockchain and transaction information.
http://bitcoinlib.readthedocs.io/
GNU General Public License v3.0
596 stars 199 forks source link

Wallet.scan() datetime timezone issue while reading transactions from Cache #411

Closed uluwatu-xyz closed 1 month ago

uluwatu-xyz commented 1 month ago

I've upgraded to 0.7.0b1 to use the replace_by_fee functionality. While using this version I've observed an datetime / timezone comparison issue using a non clean ~/.bitcoinlib - when historic transactions are loaded from the cache (see below).

The SQL DATETIME type contains no TZ info and when we load the cached transactions from the database I don't see us setting it to UTC explicitly in gettransactions().

Pull Request https://github.com/1200wd/bitcoinlib/pull/412

In [3]: wallet.scan()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 wallet.scan()

File ~/scratch/bitcoinlib/bitcoinlib/wallets.py:2060, in Wallet.scan(self, scan_gap_limit, account_id, change, rescan_used, network, keys_ignore)
   2058 keys_ignore.append(key.key_id)
   2059 n_high_new = 0
-> 2060 if self.scan_key(key):
   2061     if not key.address_index:
   2062         key.address_index = 0

File ~/scratch/bitcoinlib/bitcoinlib/wallets.py:1979, in Wallet.scan_key(self, key)
   1977 should_be_finished_count = 0
   1978 while True:
-> 1979     n_new = self.transactions_update(key_id=key.key_id)
   1980     if n_new and n_new < MAX_TRANSACTIONS:
   1981         if should_be_finished_count:

File ~/scratch/bitcoinlib/bitcoinlib/wallets.py:3423, in Wallet.transactions_update(self, account_id, used, network, key_id, depth, change, limit)
   3421 txs += srv.gettransactions(address, limit=limit, after_txid=self.transaction_last(address))
   3422 if not srv.complete:
-> 3423     if txs and txs[-1].date and txs[-1].date < last_updated:
   3424         last_updated = txs[-1].date
   3425 if txs and txs[-1].confirmations:

TypeError: can't compare offset-naive and offset-aware datetimes
mccwdev commented 1 month ago

Good point, thanks for the fix See https://github.com/1200wd/bitcoinlib/pull/412