コード例 #1
0
    def initialize_storage(self, wallet_dir, wallet_file):
        """
        This will initialize the storage for the BTC wallet.
        """
        self.wallet_dir = wallet_dir
        self.wallet_file = wallet_file

        config = SimpleConfig(options={'cwd': self.wallet_dir, 'wallet_path': self.wallet_file})
        self.storage = WalletStorage(config.get_wallet_path())
        if os.path.exists(config.get_wallet_path()):
            self.created = True
コード例 #2
0
ファイル: btc_wallet.py プロジェクト: wesavetheworld/tribler
    def load_wallet(self, wallet_dir, wallet_file):
        self.wallet_dir = wallet_dir
        self.wallet_file = wallet_file

        config = SimpleConfig(options={'cwd': self.wallet_dir, 'wallet_path': self.wallet_file})
        self.storage = WalletStorage(config.get_wallet_path())
        if self.storage.is_encrypted():
            self.storage.decrypt(self.wallet_password)

        if os.path.exists(config.get_wallet_path()):
            self.wallet = ElectrumWallet(self.storage)
            self.created = True
            self.start_daemon()
            self.open_wallet()
コード例 #3
0
    def unlock_wallet(self):
        """
        Attempt to unlock the BTC wallet with the password in the keychain.
        """
        if not self.created or self.unlocked:
            # Wallet has not been created or unlocked already, do nothing.
            return False

        if self.storage.is_encrypted():
            try:
                keychain_pw = self.get_wallet_password()
                self.wallet_password = keychain_pw if keychain_pw else None  # Convert empty passwords to None
                self.storage.decrypt(self.wallet_password)
                self.unlocked = True
            except InvalidPassword:
                self._logger.error("Invalid BTC wallet password, unable to unlock the wallet!")
            except InitError:
                self._logger.error("Cannot initialize the keychain, unable to unlock the wallet!")
        else:
            # No need to unlock the wallet
            self.unlocked = True

        if self.unlocked:
            config = SimpleConfig(options={'cwd': self.wallet_dir, 'wallet_path': self.wallet_file})
            if os.path.exists(config.get_wallet_path()):
                self.wallet = ElectrumWallet(self.storage)

            self.start_daemon()
            self.open_wallet()
            return True

        return False
コード例 #4
0
def init_cmdline(config_options, server):
    config = SimpleConfig(config_options)
    cmdname = config.get('cmd')
    cmd = known_commands[cmdname]

    if cmdname == 'signtransaction' and config.get('privkey'):
        cmd.requires_wallet = False
        cmd.requires_password = False

    if cmdname in ['payto', 'paytomany'] and config.get('unsigned'):
        cmd.requires_password = False

    if cmdname in ['payto', 'paytomany'] and config.get('broadcast'):
        cmd.requires_network = True

    # instantiate wallet for command-line
    storage = WalletStorage(config.get_wallet_path())

    if cmd.requires_wallet and not storage.file_exists():
        print_msg("Error: Wallet file not found.")
        print_msg(
            "Type 'electrum create' to create a new wallet, or provide a path to a wallet with the -w option"
        )
        sys.exit(0)

    # important warning
    if cmd.name in ['getprivatekeys']:
        print_stderr("WARNING: ALL your private keys are secret.")
        print_stderr(
            "Exposing a single private key can compromise your entire wallet!")
        print_stderr(
            "In particular, DO NOT use 'redeem private key' services proposed by third parties."
        )

    # commands needing password
    if (cmd.requires_wallet and storage.is_encrypted() and server is None)\
       or (cmd.requires_password and (storage.get('use_encryption') or storage.is_encrypted())):
        if storage.is_encrypted_with_hw_device():
            # this case is handled later in the control flow
            password = None
        elif config.get('password'):
            password = config.get('password')
        else:
            password = prompt_password('Password:'******'password'] = config_options.get('password') or password

    if cmd.name == 'password':
        new_password = prompt_password('New password:'******'new_password'] = new_password
コード例 #5
0
ファイル: wallet.py プロジェクト: devfans/electrum-scripting
def init_daemon(config_options):
    config = SimpleConfig(config_options)
    storage = WalletStorage(config.get_wallet_path())
    if not storage.file_exists():
        print_msg("Error: Wallet file not found.")
        print_msg("Type 'electrum create' to create a new wallet, or provide a path to a wallet with the -w option")
        sys.exit(0)
    if storage.is_encrypted():
        if storage.is_encrypted_with_hw_device():
            plugins = init_plugins(config, 'cmdline')
            password = get_password_for_hw_device_encrypted_storage(plugins)
        elif config.get('password'):
            password = config.get('password')
        else:
            password = prompt_password('Password:'******'password'] = password