예제 #1
0
 def __init__(
     self,
     app_log=None,
     main_module="__init__",
     crystal_folder="",
     verbose=True,
     init=False,
 ):
     if app_log:
         self.app_log = app_log
     else:
         logging.basicConfig(level=logging.DEBUG)
         self.app_log = logging
     if crystal_folder == "":
         crystal_folder = path.join(helpers.base_path(), "crystals")
     self.crystal_folder = crystal_folder
     self.main_module = main_module
     self.verbose = verbose
     self.available_crystals = self.get_available_crystals()
     if self.verbose:
         self.app_log.info("Available crystals: {}".format(", ".join(
             self.available_crystals.keys())))
     self.loaded_crystals = collections.OrderedDict({})
     if init:
         self.init()
예제 #2
0
    def get_handlers(self):
        handlers = []
        for key, crystal_info in self.loaded_crystals.items():
            try:
                module = crystal_info["module"]
                name = key.split("_")[1]
                hook_func_name = "{}Handler".format(name.capitalize())
                print(key, "hook_func_name", hook_func_name)
                if hasattr(module, hook_func_name):
                    hook_class = getattr(module, hook_func_name)
                    # Add a static handler if there is a static method
                    if hasattr(hook_class, "static"):
                        static_path = path.join(
                            base_path(), "crystals/{}/static/".format(key))
                        # print('need static', static_path)
                        handlers.append((
                            r"/crystal/{}/static/(.*)".format(name),
                            StaticFileHandler,
                            dict(path=static_path),
                        ))
                    handlers.append(
                        (r"/crystal/{}/(.*)".format(name), hook_class))

            except Exception as e:
                self.app_log.warning(
                    "Crystal '{}' exception '{}' on get_handlers".format(
                        key, e))
        return handlers
예제 #3
0
    def __init__(self):
        # wallet_servers = bismuthapi.get_wallet_servers_legacy()
        servers = None
        if options.server:
            servers = [options.server]
        bismuth_client = bismuthclient.BismuthClient(verbose=options.verbose,
                                                     servers_list=servers)
        wallet_dir = helpers.get_private_dir()
        print("Please store your wallets under '{}'".format(wallet_dir))
        bismuth_client.get_server()
        # Convert relative to absolute
        options.theme = os.path.join(helpers.base_path(), options.theme)
        static_path = os.path.join(options.theme, 'static')
        self.default_handlers = [(r"/", HomeHandler),
                                 (r"/transactions/(.*)", TransactionsHandler),
                                 (r"/json/(.*)", JsonHandler),
                                 (r"/address/(.*)", AddressHandler),
                                 (r"/messages/(.*)", AddressHandler),
                                 (r"/wallet/(.*)", WalletHandler),
                                 (r"/about/(.*)", AboutHandler),
                                 (r"/tokens/(.*)", TokensHandler),
                                 (r"/search/(.*)", SearchHandler),
                                 (r"/crystals/(.*)", CrystalsHandler),
                                 (r"/(apple-touch-icon\.png)",
                                  tornado.web.StaticFileHandler,
                                  dict(path=static_path))]
        # Parse crystals dir, import and plug handlers.
        self.crystals_manager = CrystalManager(init=options.crystals)
        handlers = self.default_handlers.copy()
        handlers.extend(self.crystals_manager.get_handlers())
        # print("handlers", handlers)
        self.crystals_manager.execute_action_hook('init')

        settings = dict(
            app_title=u"Tornado Bismuth Wallet",
            # template_loader = CrystalLoader(options.theme),
            template_path=os.path.join(os.path.dirname(__file__),
                                       options.theme),
            static_path=os.path.join(os.path.dirname(__file__), static_path),
            ui_modules={"Transaction": TxModule},
            xsrf_cookies=True,
            cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
            login_url="/auth/login",
            compress_response=True,
            debug=options.debug,  # Also activates auto reload
            serve_traceback=options.debug,
            # wallet_servers = wallet_servers
            bismuth_client=bismuth_client,
            bismuth_vars={'wallet_version': __version__},
            bismuth_crystals={})
        super(Application, self).__init__(handlers, **settings)
예제 #4
0
"""
Dragginator Crystal for Tornado wallet
"""

from os import path, listdir

from modules.basehandlers import CrystalHandler
from modules.helpers import base_path, get_api_10
from tornado.template import Template

DEFAULT_THEME_PATH = path.join(base_path(),
                               'crystals/100_bismuthprice/themes/default')

MODULES = {}

__version__ = '0.2'


class BismuthpriceHandler(CrystalHandler):
    async def about(self, params=None):
        self.render("about.html",
                    bismuth=self.bismuth_vars,
                    version=__version__)

    async def get(self, command=''):
        command, *params = command.split('/')
        if not command:
            command = 'about'
        await getattr(self, command)(params)

    def get_template_path(self):
예제 #5
0
    tornado.options.parse_command_line()
    app = Application()
    app.listen(options.port, options.listen)
    # In this demo the server will simply run until interrupted
    # with Ctrl-C, but if you want to shut down more gracefully,
    # call shutdown_event.set().
    shutdown_event = tornado.locks.Event()
    if not options.debug:
        # In debug mode, any code change will restart the server and launch another tab.
        # This goes in the way, so we deactivate in debug.
        open_url("http://127.0.0.1:{}".format(options.port))
    await shutdown_event.wait()


def port_in_use(port):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.settimeout(1)
    result = sock.connect_ex(("127.0.0.1", port))
    return result == 0


if __name__ == "__main__":
    if port_in_use(options.port):
        print("Port {} is in use, opening url".format(options.port))
        open_url("http://127.0.0.1:{}".format(options.port))
    else:
        # See http://www.lexev.org/en/2015/tornado-internationalization-and-localization/
        locale_path = os.path.join(helpers.base_path(), "locale")
        tornado.locale.load_gettext_translations(locale_path, "messages")
        tornado.ioloop.IOLoop.current().run_sync(main)
예제 #6
0
"""
Dragginator Crystal for Tornado wallet
"""
from os import path, listdir
import json

from modules.basehandlers import CrystalHandler
from modules.helpers import base_path, get_api_10, graph_colors_rgba
from tornado.template import Template


__version__ = "0.1c"


DEFAULT_THEME_PATH = path.join(base_path(), "crystals/210_eggpool/themes/default")
MODULES = {}

ACTIVE = False


class EggpoolHandler(CrystalHandler):
    async def about(self, params=None):
        _ = self.locale.translate
        # print("address", self.bismuth_vars["address"])
        if len(self.bismuth_vars["address"]) > 4:
            url = "https://eggpool.net/index.php?action=api&miner={}&type=detail".format(
                self.bismuth_vars["address"]
            )
            # TODO: rewrite as async with parametrized cache ttl, see dragginator crystal
            api = get_api_10(url, is_json=True)  # gets as dict, and cache for 10 min
            print("eggpool, api", api)
예제 #7
0
"""
Bismuth Tokens Crystal for Tornado wallet
"""

from os import path
from time import time

from modules.basehandlers import CrystalHandler
from modules.i18n import get_dt_language
from modules.helpers import base_path, get_private_dir, async_get_with_http_fallback

DEFAULT_THEME_PATH = path.join(base_path(), "crystals/030_bismuthtokens/themes/default")

MODULES = {}

CACHED_DATA = {}
CACHED_ALL = {}

__version__ = "0.2"


async def get_data(address):
    """Query live api data or sends cached version"""
    if address in CACHED_DATA and CACHED_DATA[address][1] > time():
        # cached version still is valid
        return CACHED_DATA[address][0]
    all = await async_get_with_http_fallback("https://bismuth.today/api/tokens/")
    """
    'all': [
      ['ekn', '7bdc435229fb95321f74ead695bef31b05db0e71c4be605dc1bfc915', 21000000, 1554574309.19, 1], 
      ['ico', '7ef68a880a86ae48e077f43c509b1f959f1dd399cb8e3766e229876e', 50000, 1541578009.48, 2], 
예제 #8
0
"""
Dragginator Crystal for Tornado wallet
"""
from os import path, listdir
import sys

from modules.basehandlers import CrystalHandler
from modules.i18n import get_dt_language
from modules.helpers import base_path, async_get_with_http_fallback
from tornado.template import Template


DEFAULT_THEME_PATH = path.join(base_path(), 'crystals/200_dragginator/themes/default')

MODULES = {}


class DragginatorHandler(CrystalHandler):

    """
    def initialize(self):
        super().initialize()
        self.bismuth_vars['extra'] = {"header":'<!-- DRAGGINATOR HEADER -->', "footer": '<!-- DRAGGINATOR FOOTER -->'}
    """

    async def about(self, params=None):
        eggdrop = False
        if len(self.bismuth_vars['address']) > 4:
            data = await async_get_with_http_fallback("https://dragginator.com/api/info.php?address={}&type=list"
                                                      .format(self.bismuth_vars['address']))
            if len(data) == 0:
예제 #9
0
"""
BSC Bridge Crystal for Tornado wallet
"""

from os import path
from modules.helpers import async_get_with_http_fallback
from modules.basehandlers import CrystalHandler
from modules.helpers import base_path
from hashlib import sha256
from decimal import Decimal, getcontext, ROUND_HALF_EVEN

DEFAULT_THEME_PATH = path.join(base_path(), "crystals/061_bscbridge/themes/default")

MODULES = {}

__version__ = "1.0.4"


ETH_BRIDGE_ADDRESS = "Bis1FWBNBbrYZkQmCYQf8FQWTUCFEreUeT71K"  # Prod
ETH_ORACLE_ADDRESS = "Bis1XBNBY66wngPLVwbRbnSs4ScVBwE3iM7kL"  # Prod

ETH_SC_ADDRESS = "0x56672ecb506301b1E32ED28552797037c54D36A9"  # Mainnet

ETH_wBIS_URL = "https://raw.githubusercontent.com/bismuthfoundation/MEDIA-KIT/master/Logo_v2/wbis500x500.png"
# ETH_EXPLORER = "https://goerli.etherscan.io"  # test
ETH_EXPLORER = "https://bscscan.com"  # mainnet

OPERATION_PREFIX = "bscbridge"

BIS_FIXED_FEES_FLOAT = 5.0
BIS_FIXED_FEES_INT = 500000000
예제 #10
0
    def __init__(self):
        # wallet_servers = bismuthapi.get_wallet_servers_legacy()
        servers = None
        if options.server:
            servers = [options.server]
        bismuth_client = bismuthclient.BismuthClient(verbose=options.verbose,
                                                     servers_list=servers)
        wallet_dir = helpers.get_private_dir()
        self.wallet_settings = None
        print("Please store your wallets under '{}'".format(wallet_dir))
        if options.romode:
            print("Read only mode")
        # self.load_user_data("{}/options.json".format(wallet_dir))
        if options.nowallet:
            print("No Wallet mode")
            bismuth_client.wallet_file = None
            bismuth_client.address = 'FakeAddressMode'
        else:
            bismuth_client.load_multi_wallet(
                "{}/wallet.json".format(wallet_dir))
        bismuth_client.set_alias_cache_file(
            "{}/alias_cache.json".format(wallet_dir))
        bismuth_client.get_server()
        # Convert relative to absolute
        options.theme = os.path.join(helpers.base_path(), options.theme)
        static_path = os.path.join(options.theme, "static")
        common_path = os.path.join(helpers.base_path(), "themes/common")
        self.default_handlers = [
            (r"/", HomeHandler),
            (r"/transactions/(.*)", TransactionsHandler),
            (r"/json/(.*)", JsonHandler),
            (r"/address/(.*)", AddressHandler),
            (r"/messages/(.*)", MessagesHandler),
            (r"/wallet/(.*)", WalletHandler),
            (r"/about/(.*)", AboutHandler),
            (r"/tokens/(.*)", TokensHandler),
            (r"/search/(.*)", SearchHandler),
            (r"/crystals/(.*)", CrystalsHandler),
            (r"/tools/(.*)", ToolsHandler),
            (
                r"/(apple-touch-icon\.png)",
                tornado.web.StaticFileHandler,
                dict(path=static_path),
            ),
            (r'/common/(.*)', tornado.web.StaticFileHandler, {
                'path': common_path
            }),
        ]
        # Parse crystals dir, import and plug handlers.
        self.crystals_manager = CrystalManager(init=options.crystals)
        handlers = self.default_handlers.copy()
        handlers.extend(self.crystals_manager.get_handlers())
        # print("handlers", handlers)
        self.crystals_manager.execute_action_hook("init")

        settings = dict(
            app_title=options.app_title,
            # template_loader = CrystalLoader(options.theme),
            template_path=os.path.join(os.path.dirname(__file__),
                                       options.theme),
            static_path=os.path.join(os.path.dirname(__file__), static_path),
            ui_modules={"Transaction": TxModule},
            xsrf_cookies=True,
            cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
            login_url="/auth/login",
            compress_response=True,
            debug=options.debug,  # Also activates auto reload
            serve_traceback=options.debug,
            max_addresses=options.maxa,
            lang=options.lang,
            ro_mode=options.romode,
            # wallet_servers = wallet_servers
            bismuth_client=bismuth_client,
            bismuth_vars={
                "wallet_version": __version__,
                "bismuthclient_version": bismuthclient.__version__,
            },
            bismuth_crystals={},
        )
        super(Application, self).__init__(handlers, **settings)
예제 #11
0
async def main():
    tornado.options.parse_command_line()
    app = Application()
    app.listen(options.port, options.listen)
    # In this demo the server will simply run until interrupted
    # with Ctrl-C, but if you want to shut down more gracefully,
    # call shutdown_event.set().
    shutdown_event = tornado.locks.Event()
    if not options.debug:
        # In debug mode, any code change will restart the server and launch another tab.
        # This goes in the way, so we deactivate in debug.
        open_url("http://127.0.0.1:{}".format(options.port))
    await shutdown_event.wait()


def port_in_use(port):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.settimeout(1)
    result = sock.connect_ex(('127.0.0.1', port))
    return result == 0


if __name__ == "__main__":
    if port_in_use(options.port):
        open_url("http://127.0.0.1:{}".format(options.port))
    else:
        # See http://www.lexev.org/en/2015/tornado-internationalization-and-localization/
        locale_path = os.path.join(helpers.base_path(), 'locale')
        tornado.locale.load_gettext_translations(locale_path, 'messages')
        tornado.ioloop.IOLoop.current().run_sync(main)
예제 #12
0
"""
Dragginator Crystal for Tornado wallet
"""
from os import path, listdir
import sys

from modules.basehandlers import CrystalHandler
from modules.i18n import get_dt_language
from modules.helpers import base_path, async_get_with_http_fallback
from tornado.template import Template

__version__ = '0.2b'

DEFAULT_THEME_PATH = path.join(base_path(), 'crystals/250_autogame/themes/default')

MODULES = {}


class AutogameHandler(CrystalHandler):

    """
    def initialize(self):
        super().initialize()
        self.bismuth_vars['extra'] = {"header":'<!-- Autogame HEADER -->', "footer": '<!-- Autogame FOOTER -->'}
    """

    async def about(self, params=None):
        games_detail = {}
        if len(self.bismuth_vars['address']) == 56:
            # self.bismuth_vars['address'] = 'fefb575972cd8fdb086e2300b51f727bb0cbfc33282f1542e19a8f1d'  # debug
            url = "http://autogame.bismuth.live:6060/api/seed/{}".format(self.bismuth_vars['address'])