Skip to content

Commit

Permalink
Version 1.10.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNaif2018 committed Nov 9, 2022
1 parent 1fd4ddf commit 45e59f0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Latest changes

## 1.10.5.0

Urgent fix: APIManager is not loading correct coin settings from anywhere when receiving events.

Classmethods `load_wallet` and `load_wallets` are now methods of APIManager objects.

A new parameter `custom_params` was added: a mapping between currency and it's custom settings dict.

## 1.10.4.1

Support python 3.11
Expand Down
13 changes: 6 additions & 7 deletions bitcart/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,23 @@


class APIManager(EventDelivery):
def __init__(self, wallets: Dict[str, Iterable[str]] = {}):
def __init__(self, wallets: Dict[str, Iterable[str]] = {}, custom_params: Dict[str, dict] = {}):
super().__init__()
self.custom_params = custom_params
self.wallets = ExtendedDefaultDict(
lambda: ExtendedDict(),
{currency: self.load_wallets(currency, wallets) for currency, wallets in wallets.items()},
)
self.event_handlers = {}

@classmethod
def load_wallets(cls, currency: str, wallets: Iterable[str]) -> ExtendedDict:
return ExtendedDict({wallet: cls.load_wallet(currency, wallet) for wallet in wallets})
def load_wallets(self, currency: str, wallets: Iterable[str]) -> ExtendedDict:
return ExtendedDict({wallet: self.load_wallet(currency, wallet) for wallet in wallets})

@classmethod
def load_wallet(cls, currency: str, wallet: Optional[str] = None) -> "Coin":
def load_wallet(self, currency: str, wallet: Optional[str] = None) -> "Coin":
currency = currency.upper()
if currency not in COINS:
raise CurrencyUnsupportedError()
return COINS[currency](xpub=wallet)
return COINS[currency](xpub=wallet, **self.custom_params.get(currency, {}))

def add_wallet(self, currency: str, wallet: str) -> None:
self.wallets[currency][wallet] = self.load_wallet(currency, wallet)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name="bitcart",
packages=find_packages(),
version="1.10.4.1",
version="1.10.5.0",
license="LGPLv3+",
description="BitcartCC coins support library",
long_description=open("README.md").read(),
Expand Down
11 changes: 6 additions & 5 deletions tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ async def test_manager_storage(manager, xpub):
assert manager.wallets.BTC == manager.wallets["BTC"] == manager.BTC == manager["BTC"]


async def test_manager_classmethods(xpub):
assert APIManager.load_wallet("BTC", xpub) == BTC(xpub=xpub)
assert APIManager.load_wallets("BTC", [xpub, xpub]) == {xpub: BTC(xpub=xpub)}
async def test_manager_methods(xpub):
manager = APIManager()
assert manager.load_wallet("BTC", xpub) == BTC(xpub=xpub)
assert manager.load_wallets("BTC", [xpub, xpub]) == {xpub: BTC(xpub=xpub)}
with pytest.raises(CurrencyUnsupportedError):
APIManager.load_wallet("test")
manager.load_wallet("test")
with pytest.raises(CurrencyUnsupportedError):
APIManager.load_wallets("test", [xpub])
manager.load_wallets("test", [xpub])


async def test_manager_add_wallets(manager, xpub):
Expand Down

0 comments on commit 45e59f0

Please sign in to comment.