Skip to content

Commit

Permalink
[FIX] Listing bitcoin account when default is other network
Browse files Browse the repository at this point in the history
  • Loading branch information
mccwdev committed Nov 7, 2023
1 parent c22f96f commit 84b3e23
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions bitcoinlib/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions tests/test_wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 84b3e23

Please sign in to comment.