Beispiel #1
0
def info(ctx):
    """Print version and more info"""
    if ctx.obj['json']:
        print(
            json.dumps({
                "version":
                __version__,
                "private_dir":
                get_private_dir(),
                "public_address":
                ByteUtil.bytes_as_string_with_dashes(
                    config.PUBLIC_KEY.to_bytes()),
                "client":
                ctx.obj['client'],
                "port":
                ctx.obj['port'],
            }))
    else:
        print(f"Nyzocli version {__version__}")
        print(f"Your private dir is {get_private_dir()}")
        print(
            f"Your public address is {ByteUtil.bytes_as_string_with_dashes(config.PUBLIC_KEY.to_bytes())}"
        )
        print(f"Default verifier is {ctx.obj['verifier_ip']}")
        print(f"Client is {ctx.obj['client']} on port {ctx.obj['port']}")
Beispiel #2
0
 async def create(self, params=None, post: bool = False):
     # self.write(json.dumps(self.request))
     # TODO: DEPRECATED
     _, param = self.request.uri.split("?")
     _ = self.locale.translate
     wallet = param.replace("wallet=", "")
     wallet = wallet.replace(".der", "")  # just in case the user added .der
     wallet_dir = helpers.get_private_dir()
     file_name = os.path.join(wallet_dir, "{}.der".format(wallet))
     if os.path.isfile(file_name):
         self.render(
             "message.html",
             type="warning",
             title=_("Error"),
             message=_("This file already exists: {}.der").format(wallet),
             bismuth=self.bismuth_vars,
         )
     else:
         # create one
         if self.bismuth.new_wallet(file_name):
             # load the new wallet
             self.bismuth.load_wallet(file_name)
             self.set_cookie("wallet", file_name)
             self.redirect("/wallet/info")
         else:
             self.render(
                 "message.html",
                 type="warning",
                 title=_("Error"),
                 message=_("Error creating {}.der").format(wallet),
                 bismuth=self.bismuth_vars,
             )
 def _save_active(self):
     """Saves active state in the json dict for next run"""
     state_filename = path.join(helpers.get_private_dir(), "crystals.json")
     states = {
         name: name in self.loaded_crystals
         for name in self.available_crystals.keys()
     }
     try:
         with open(state_filename, "w") as f:
             json.dump(states, f)
     except:
         pass
 def get_active(self):
     """Returns a dict of crystalname, active state"""
     state_filename = path.join(helpers.get_private_dir(), "crystals.json")
     states = {}
     if not path.isfile(state_filename):
         return states
     try:
         with open(state_filename, "r") as f:
             states = json.load(f)
     except:
         pass
     return states
    async def load(self, params=None, post=False):
        _ = self.locale.translate
        if self.bismuth._wallet._locked:
            self.render(
                "message.html",
                type="warning",
                title=_("Error"),
                message=_("You have to unlock your wallet first"),
                bismuth=self.bismuth_vars,
            )
        global_balance = _("Click")
        if "global" in params:
            # Ask the global balance
            try:
                global_balance = self.bismuth.global_balance(for_display=True)
            except Exception as e:
                self.app_log.warning("Exception {} global balance".format(e))
                self.render(
                    "message.html",
                    type="warning",
                    title=_("Error"),
                    message=_("Time out, please try reloading").format(e),
                    bismuth=self.bismuth_vars,
                )
                return

        wallet_dir = helpers.get_private_dir()
        # This lists the old style wallets
        wallets = self.bismuth.list_wallets(wallet_dir)
        # TODO: fix private access
        addresses = self.bismuth._wallet._addresses
        if "detail" in params:
            # get balance of every address
            balances = self.bismuth.all_balances(for_display=True)
            self.render(
                "wallet_load_detail.html",
                wallets=wallets,
                bismuth=self.bismuth_vars,
                wallet_dir=wallet_dir,
                global_balance=global_balance,
                balances=balances,
                addresses=addresses,
            )
        else:
            self.render(
                "wallet_load.html",
                wallets=wallets,
                bismuth=self.bismuth_vars,
                wallet_dir=wallet_dir,
                global_balance=global_balance,
                addresses=addresses,
            )
    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)
 async def load(self, params=None):
     if not params:
         wallet_dir = helpers.get_private_dir()
         wallets = self.bismuth.list_wallets(wallet_dir)
         self.render("wallet_load.html",
                     wallets=wallets,
                     bismuth=self.bismuth_vars,
                     wallet_dir=wallet_dir)
     else:
         # load a wallet
         file_name = '/'.join(params)
         self.bismuth.load_wallet(file_name)
         # TODO: store as cookie
         self.set_cookie('wallet', file_name)
         self.redirect("/wallet/info")
Beispiel #8
0
def action_init(params=None):
    """Load and compiles module templates"""
    """
    modules_dir = path.join(DEFAULT_THEME_PATH, "modules")
    for module in listdir(modules_dir):
        module_name = module.split(".")[0]
        file_name = path.join(modules_dir, module)
        with open(file_name, "rb") as f:
            MODULES[module_name] = Template(f.read().decode("utf-8"))            
    """
    global MASTER_KEY
    global KEYFILE
    KEYFILE = path.join(get_private_dir(), "votingkey.json")
    if path.isfile(KEYFILE):
        with open(KEYFILE) as fp:
            MASTER_KEY = fp.readline()
Beispiel #9
0
def info(ctx):
    """Print version"""
    if ctx.obj['json']:
        print(
            json.dumps({
                "private_dir":
                get_private_dir(),
                "public_address":
                ByteUtil.bytes_as_string_with_dashes(
                    config.PUBLIC_KEY.to_bytes()),
                "default_host":
                ctx.obj['host'],
                "default_port":
                ctx.obj['port'],
            }))
    else:
        print(f"Your private dir is {get_private_dir()}")
        print(
            f"Your public address is {ByteUtil.bytes_as_string_with_dashes(config.PUBLIC_KEY.to_bytes())}"
        )
        print(f"Default host is {ctx.obj['host']} on port {ctx.obj['port']}")
Beispiel #10
0
    res = get(url).text
    if VERBOSE:
        print(res)
    if "Error:" in res:
        print("E", res)
    else:
        # Assemble, sign and forward if ok
        client = NyzoClient(ctx.obj['client'])
        res = client.send(recipient, fees, data, key_)
        print(res)


if __name__ == '__main__':
    logger = logging.getLogger('push')

    app_log = logging.getLogger()
    app_log.setLevel(logging.INFO)

    ch = logging.StreamHandler(sys.stdout)
    ch.setLevel(logging.DEBUG)
    formatter = logging.Formatter('%(asctime)s [%(levelname)-5s] %(message)s')
    ch.setFormatter(formatter)
    app_log.addHandler(ch)

    # Use user private dir
    private_dir = get_private_dir()
    config.NYZO_SEED = private_dir + '/private_seed'
    config.load(private_dir)

    cli(obj={})
    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)