-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cbfc32
commit 6ddd83b
Showing
1 changed file
with
33 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,53 @@ | ||
from keygen.crypto_coin_service import CoinService | ||
from keygen.currencies.btc_crypto_coin_service import BtcCoinService | ||
from keygen.currencies.bch_crypto_coin_service import BchCoinService | ||
from keygen.currencies.ltc_crypto_coin_service import LtcCoinService | ||
from keygen.currencies.eth_crypto_coin_service import EthCoinService | ||
from keygen.currencies.doge_crypto_coin_service import DogeCoinService | ||
|
||
import inspect | ||
|
||
|
||
class CoinFactory: | ||
def __init__(self): | ||
pass | ||
self.coin_services_classes = self.__get_coin_service_classes() | ||
|
||
def get_available_currencies(self): | ||
return CoinFactory.get_default_available_currencies() | ||
|
||
@staticmethod | ||
def get_default_available_currencies(): | ||
return ['BTC', 'BCH', 'LTC', 'DOGE', 'ETH'] | ||
return self.__get_default_available_currencies() | ||
|
||
# @staticmethod | ||
# def get_default_available_currencies(): | ||
# return [ 'DASH', 'BSV', 'XRP', 'XMR', 'BNB', 'EOS', 'POTE', 'ADA'] # For the next release. | ||
def __get_default_available_currencies(self): | ||
return ['BTC', 'BCH', 'LTC', 'DOGE', 'ETH'] + \ | ||
[coin_services_class.get_currency_name() for coin_services_class in self.coin_services_classes] | ||
|
||
def get_coin_service(self, currency): | ||
if currency == "BTC": | ||
return BtcCoinService() | ||
if currency == "BCH": | ||
elif currency == "BCH": | ||
return BchCoinService() | ||
if currency == "LTC": | ||
elif currency == "LTC": | ||
return LtcCoinService() | ||
if currency == "ETH": | ||
elif currency == "ETH": | ||
return EthCoinService() | ||
if currency == "DOGE": | ||
elif currency == "DOGE": | ||
return DogeCoinService() | ||
raise Exception("Coin not supported") | ||
else: | ||
return self.__get_discovered_coin_service(currency) | ||
|
||
def __get_discovered_coin_service(self, currency): | ||
coin_services_dictionary = dict( | ||
(service.get_currency_name(), service) for service in self.coin_services_classes) | ||
if currency in coin_services_dictionary: | ||
return coin_services_dictionary.get(currency)() | ||
else: | ||
raise Exception("Coin not supported") | ||
|
||
@staticmethod | ||
def __get_coin_service_classes(): | ||
try: | ||
plugins_module = __import__("plugins") | ||
classes_member_list = [member for member in dir(plugins_module) | ||
if inspect.isclass(getattr(plugins_module, member))] | ||
classes_list = [getattr(plugins_module, class_member) for class_member in classes_member_list] | ||
return [clazz for clazz in classes_list if issubclass(clazz, CoinService) and clazz != CoinService] | ||
except ModuleNotFoundError: | ||
return [] |