monero-ecosystem / monero-python

A comprehensive Python module for handling Monero cryptocurrency
BSD 3-Clause "New" or "Revised" License
244 stars 80 forks source link

new_address() fails for OfflineWallet #95

Closed mrx23dot closed 3 years ago

mrx23dot commented 3 years ago

Why can't I generate random new_address() subaddresses for OfflineWallet? For random address generation collision is less likely.

    return self._backend.new_address(account=self.index, label=label)
  File "C:\Python36\lib\site-packages\monero\backends\offline.py", line 49, in new_address
    raise WalletIsOffline()
monero.backends.offline.WalletIsOffline

Currently it requires open wallet file in RPC. Offline example uses get_address(major, minor) https://monero-python.readthedocs.io/en/latest/backends.html

emesik commented 3 years ago

First of all, new_address() is not a random but sequential address generator. It appends a new address to the list of already generated ones in the wallet, increasing the minor index. Since the OfflineWallet doesn't connect to any real wallet, there's no such list.

Please keep in mind that every wallet software checks for payments only those addresses that have been generated already (and sometimes a handful of future ones, in sequential order).

You may, of course, implement your own backend that manages the list of subaddresses and implements new_address(). Remember to keep the list in persistent storage, or every time you restart the program, it would generate addresses starting again from minor=1.

mrx23dot commented 3 years ago

Thank you!