示例#1
0
 def set_enabled():
     wizard.next_button.setEnabled(Wallet.is_xprv(clean_text(text)))
示例#2
0
def run_non_RPC(config):
    cmdname = config.get('cmd')

    storage = WalletStorage(config.get_wallet_path())
    if storage.file_exists:
        sys.exit("Error: Remove the existing wallet first!")

    def password_dialog():
        return prompt_password(
            "Password (hit return if you do not wish to encrypt your wallet):")

    if cmdname == 'restore':
        text = config.get('text')
        password = password_dialog() if Wallet.is_seed(text) or Wallet.is_xprv(
            text) or Wallet.is_private_key(text) else None
        try:
            wallet = Wallet.from_text(text, password, storage)
        except BaseException as e:
            sys.exit(str(e))
        if not config.get('offline'):
            network = Network(config)
            network.start()
            wallet.start_threads(network)
            log.info("Recovering wallet...")
            wallet.synchronize()
            wallet.wait_until_synchronized()
            msg = "Recovery successful" if wallet.is_found(
            ) else "Found no history for this wallet"
        else:
            msg = "This wallet was restored offline. It may contain more addresses than displayed."
        log.info(msg)
    elif cmdname == 'create':
        password = password_dialog()
        wallet = Wallet(storage)
        seed = wallet.make_seed()
        wallet.add_seed(seed, password)
        wallet.create_master_keys(password)
        wallet.create_main_account()
        wallet.synchronize()
        print "Your wallet generation seed is:\n\"%s\"" % seed
        print "Please keep it in a safe place; if you lose it, you will not be able to restore " \
              "your wallet."
    elif cmdname == 'deseed':
        wallet = Wallet(storage)
        if not wallet.seed:
            log.info("Error: This wallet has no seed")
        else:
            ns = wallet.storage.path + '.seedless'
            print "Warning: you are going to create a seedless wallet'\n" \
                  "It will be saved in '%s'" % ns
            if raw_input("Are you sure you want to continue? (y/n) ") in [
                    'y', 'Y', 'yes'
            ]:
                wallet.storage.path = ns
                wallet.seed = ''
                wallet.storage.put('seed', '')
                wallet.use_encryption = False
                wallet.storage.put('use_encryption', wallet.use_encryption)
                for k in wallet.imported_keys.keys():
                    wallet.imported_keys[k] = ''
                wallet.storage.put('imported_keys', wallet.imported_keys)
                print "Done."
            else:
                print "Action canceled."
        wallet.storage.write()
    else:
        raise Exception("Unknown command %s" % cmdname)
    wallet.storage.write()
    log.info("Wallet saved in '%s'", wallet.storage.path)
示例#3
0
文件: main.py 项目: lbryio/lbryum
def run_non_RPC(config):
    _ = get_blockchain(config, None)
    cmdname = config.get('cmd')

    storage = WalletStorage(config.get_wallet_path())
    if storage.file_exists:
        sys.exit("Error: Remove the existing wallet first!")

    def password_dialog():
        return prompt_password("Password (hit return if you do not wish to encrypt your wallet):")

    if cmdname == 'restore':
        text = config.get('text')
        no_password = config.get('no_password')
        password = None
        if not no_password and (Wallet.is_seed(text) or Wallet.is_xprv(text) or Wallet.is_private_key(text)):
            password = password_dialog()
        try:
            wallet = Wallet.from_text(text, password, storage)
            wallet.create_main_account()
        except BaseException as e:
            sys.exit(str(e))
        if not config.get('offline'):
            network = Network(config)
            network.start()
            wallet.start_threads(network)
            log.info("Recovering wallet...")
            wallet.synchronize()
            wallet.wait_until_synchronized()
            print "Recovery successful" if wallet.is_found() else "Found no history for this wallet"
        else:
            print "This wallet was restored offline. It may contain more addresses than displayed."
    elif cmdname == 'create':
        password = password_dialog()
        wallet = Wallet(storage)
        seed = wallet.make_seed()
        wallet.add_seed(seed, password)
        wallet.create_master_keys(password)
        wallet.create_main_account()
        wallet.synchronize()
        print "Your wallet generation seed is:\n\"%s\"" % seed
        print "Please keep it in a safe place; if you lose it, you will not be able to restore " \
              "your wallet."
    elif cmdname == 'deseed':
        wallet = Wallet(storage)
        if not wallet.seed:
            log.info("Error: This wallet has no seed")
        else:
            ns = wallet.storage.path + '.seedless'
            print "Warning: you are going to create a seedless wallet'\n" \
                  "It will be saved in '%s'" % ns
            if raw_input("Are you sure you want to continue? (y/n) ") in ['y', 'Y', 'yes']:
                wallet.storage.path = ns
                wallet.seed = ''
                wallet.storage.put('seed', '')
                wallet.use_encryption = False
                wallet.storage.put('use_encryption', wallet.use_encryption)
                for k in wallet.imported_keys.keys():
                    wallet.imported_keys[k] = ''
                wallet.storage.put('imported_keys', wallet.imported_keys)
                print "Done."
            else:
                print "Action canceled."
        wallet.storage.write()
    else:
        raise Exception("Unknown command %s" % cmdname)
    wallet.storage.write()
    log.info("Wallet saved in '%s'", wallet.storage.path)