diff --git a/.github/workflows/unittests_windows.yaml b/.github/workflows/unittests_windows.yaml index 08800c2b..59c1d772 100644 --- a/.github/workflows/unittests_windows.yaml +++ b/.github/workflows/unittests_windows.yaml @@ -11,7 +11,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v3 with: - python-version: '3.9' + python-version: '3.11' architecture: 'x64' - name: Install dependencies run: | @@ -27,4 +27,5 @@ jobs: env: BCL_CONFIG_FILE: config.ini.unittest UNITTESTS_FULL_DATABASE_TEST: False + PYTHONUTF8: 1 run: coverage run --source=bitcoinlib -m unittest -v diff --git a/bitcoinlib/config/config.py b/bitcoinlib/config/config.py index b0284f50..95d5733d 100644 --- a/bitcoinlib/config/config.py +++ b/bitcoinlib/config/config.py @@ -120,11 +120,11 @@ 1000000000000000000000000: 'Y', } -if os.name == 'nt' and locale.getpreferredencoding() != 'UTF-8': - # TODO: Find a better windows hack +if os.name == 'nt' and locale.getpreferredencoding().lower() != 'utf-8': import _locale - _locale._getdefaultlocale = (lambda *args: ['en_US', 'utf8']) -elif locale.getpreferredencoding() != 'UTF-8': + _locale._gdl_bak = _locale._getdefaultlocale + _locale._getdefaultlocale = (lambda *args: (_locale._gdl_bak()[0], 'utf8')) +elif locale.getpreferredencoding().lower() != 'utf-8': raise EnvironmentError("Locale is currently set to '%s'. " "This library needs the locale set to UTF-8 to function properly" % locale.getpreferredencoding()) diff --git a/bitcoinlib/services/bitcoind.py b/bitcoinlib/services/bitcoind.py index 2e4eeaf6..f74001c8 100644 --- a/bitcoinlib/services/bitcoind.py +++ b/bitcoinlib/services/bitcoind.py @@ -53,7 +53,7 @@ class BitcoindClient(BaseClient): """ @staticmethod - def from_config(configfile=None, network='bitcoin'): + def from_config(configfile=None, network='bitcoin', **kwargs): """ Read settings from bitcoind config file @@ -113,9 +113,9 @@ def from_config(configfile=None, network='bitcoin'): server = _read_from_config(config, 'rpc', 'externalip', server) url = "http://%s:%s@%s:%s" % (config.get('rpc', 'rpcuser'), config.get('rpc', 'rpcpassword'), server, port) - return BitcoindClient(network, url) + return BitcoindClient(network, url, **kwargs) - def __init__(self, network='bitcoin', base_url='', denominator=100000000, *args): + def __init__(self, network='bitcoin', base_url='', denominator=100000000, **kwargs): """ Open connection to bitcoin node @@ -123,7 +123,7 @@ def __init__(self, network='bitcoin', base_url='', denominator=100000000, *args) :type: str :param base_url: Connection URL in format http(s)://user:password@host:port. :type: str - :param denominator: Denominator for this currency. Should be always 100000000 (satoshis) for bitcoin + :param denominator: Denominator for this currency. Should be always 100000000 (Satoshi's) for bitcoin :type: str """ if isinstance(network, Network): @@ -134,7 +134,7 @@ def __init__(self, network='bitcoin', base_url='', denominator=100000000, *args) network = bdc.network _logger.info("Connect to bitcoind") self.proxy = AuthServiceProxy(base_url) - super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, *args) + super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, **kwargs) def getbalance(self, addresslist): balance = 0 diff --git a/bitcoinlib/services/dashd.py b/bitcoinlib/services/dashd.py index de5aec20..1178d626 100644 --- a/bitcoinlib/services/dashd.py +++ b/bitcoinlib/services/dashd.py @@ -56,7 +56,7 @@ class DashdClient(BaseClient): """ @staticmethod - def from_config(configfile=None, network='dash'): + def from_config(configfile=None, network='dash', **kargs): """ Read settings from dashd config file @@ -104,9 +104,9 @@ def from_config(configfile=None, network='dash'): elif 'externalip' in config['rpc']: server = config.get('rpc', 'externalip') url = "http://%s:%s@%s:%s" % (config.get('rpc', 'rpcuser'), config.get('rpc', 'rpcpassword'), server, port) - return DashdClient(network, url) + return DashdClient(network, url, **kargs) - def __init__(self, network='dash', base_url='', denominator=100000000, *args): + def __init__(self, network='dash', base_url='', denominator=100000000, **kargs): """ Open connection to dashcore node @@ -123,7 +123,7 @@ def __init__(self, network='dash', base_url='', denominator=100000000, *args): network = bdc.network _logger.info("Connect to dashd") self.proxy = AuthServiceProxy(base_url) - super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, *args) + super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, **kargs) def _parse_transaction(self, tx, block_height=None, get_input_values=True): t = Transaction.parse_hex(tx['hex'], strict=self.strict, network=self.network) diff --git a/bitcoinlib/services/dogecoind.py b/bitcoinlib/services/dogecoind.py index 2efe737b..1a1ffc31 100644 --- a/bitcoinlib/services/dogecoind.py +++ b/bitcoinlib/services/dogecoind.py @@ -54,7 +54,7 @@ class DogecoindClient(BaseClient): """ @staticmethod - def from_config(configfile=None, network='dogecoin'): + def from_config(configfile=None, network='dogecoin', **kargs): """ Read settings from dogecoind config file @@ -113,9 +113,9 @@ def from_config(configfile=None, network='dogecoin'): server = _read_from_config(config, 'rpc', 'externalip', server) url = "http://%s:%s@%s:%s" % (config.get('rpc', 'rpcuser'), config.get('rpc', 'rpcpassword'), server, port) - return DogecoindClient(network, url) + return DogecoindClient(network, url, **kargs) - def __init__(self, network='dogecoin', base_url='', denominator=100000000, *args): + def __init__(self, network='dogecoin', base_url='', denominator=100000000, **kargs): """ Open connection to dogecoin node @@ -141,7 +141,7 @@ def __init__(self, network='dogecoin', base_url='', denominator=100000000, *args "Please replace default password and set url in providers.json or dogecoin.conf file") _logger.info("Connect to dogecoind") self.proxy = AuthServiceProxy(base_url) - super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, *args) + super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, **kargs) def getutxos(self, address, after_txid='', max_txs=MAX_TRANSACTIONS): txs = [] diff --git a/bitcoinlib/services/litecoind.py b/bitcoinlib/services/litecoind.py index 1f0c36ee..1f708117 100644 --- a/bitcoinlib/services/litecoind.py +++ b/bitcoinlib/services/litecoind.py @@ -53,7 +53,7 @@ class LitecoindClient(BaseClient): """ @staticmethod - def from_config(configfile=None, network='litecoin'): + def from_config(configfile=None, network='litecoin', **kargs): """ Read settings from litecoind config file @@ -112,9 +112,9 @@ def from_config(configfile=None, network='litecoin'): server = _read_from_config(config, 'rpc', 'bind', server) server = _read_from_config(config, 'rpc', 'externalip', server) url = "http://%s:%s@%s:%s" % (config.get('rpc', 'rpcuser'), config.get('rpc', 'rpcpassword'), server, port) - return LitecoindClient(network, url) + return LitecoindClient(network, url, **kargs) - def __init__(self, network='litecoin', base_url='', denominator=100000000, *args): + def __init__(self, network='litecoin', base_url='', denominator=100000000, **kargs): """ Open connection to litecoin node @@ -133,7 +133,7 @@ def __init__(self, network='litecoin', base_url='', denominator=100000000, *args network = bdc.network _logger.info("Connect to litecoind") self.proxy = AuthServiceProxy(base_url) - super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, *args) + super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, **kargs) def getbalance(self, addresslist): balance = 0 diff --git a/bitcoinlib/transactions.py b/bitcoinlib/transactions.py index b54166c1..6894e70f 100644 --- a/bitcoinlib/transactions.py +++ b/bitcoinlib/transactions.py @@ -1190,7 +1190,7 @@ def __init__(self, value, address='', public_hash=b'', public_key=b'', lock_scri self.encoding = 'bech32' self.public_hash = self.script.public_hash if self.script.keys: - self.public_key = self.script.keys[0].public_hex + self.public_key = self.script.keys[0].public_byte if self.script_type == 'p2tr': self.witver = self.script.commands[0] - 80 diff --git a/bitcoinlib/wallets.py b/bitcoinlib/wallets.py index bc94a02d..23c43ec6 100644 --- a/bitcoinlib/wallets.py +++ b/bitcoinlib/wallets.py @@ -2508,16 +2508,17 @@ def account(self, account_id): key_id = qr.id return self.key(key_id) - def accounts(self, network=DEFAULT_NETWORK): + def accounts(self, network=None): """ Get list of accounts for this wallet - :param network: Network name filter. Default filter is DEFAULT_NETWORK + :param network: Network name filter. Default filter is network of first main key :type network: str :return list of integers: List of accounts IDs """ + network, _, _ = self._get_account_defaults(network) if self.multisig and self.cosigner: if self.cosigner_id is None: raise WalletError("Missing Cosigner ID value for this wallet, cannot fetch account ID") diff --git a/docs/_static/manuals.install.rst b/docs/_static/manuals.install.rst index 89588c4e..e63a54f0 100644 --- a/docs/_static/manuals.install.rst +++ b/docs/_static/manuals.install.rst @@ -108,6 +108,10 @@ for steps you could take to install this library. If you have problems with installing this library on Windows you could try to use the pycryptodome library instead of scrypt. The pycryptodome library is pure Python so it doesn't need any C compilers installed. But this will run slower. +When using Python on Windows it needs to be set to UTF-8 mode. You can do this by adding the PYTHONUTF8=1 to the +environment variables or use the -X utf8 command line option. Please see +https://docs.python.org/3/using/windows.html#win-utf8-mode for more information. + Update Bitcoinlib ----------------- diff --git a/tests/test_wallets.py b/tests/test_wallets.py index f0833b28..dcc1fb5b 100644 --- a/tests/test_wallets.py +++ b/tests/test_wallets.py @@ -2617,6 +2617,13 @@ def test_wallet_normalize_path(self): self.assertRaisesRegexp(WalletError, 'Could not parse path. Index is empty.', normalize_path, "m/44h/0p/100H//1201") + def test_wallet_accounts(self): + w = Wallet.create('test_litecoin_accounts', network='litecoin', account_id=1111, db_uri=self.DATABASE_URI) + w.new_account(account_id=2222) + w.new_account(account_id=5555, network='testnet') + self.assertListEqual(w.accounts(), [1111, 2222]) + self.assertListEqual(w.accounts(network='testnet'), [5555]) + @parameterized_class(*params) class TestWalletReadonlyAddress(TestWalletMixin, unittest.TestCase):