Exemple #1
0
class LBRYumWallet(object):
    def __init__(self, lbryum_path):
        self.config = SimpleConfig()
        self.config.set_key('chain', 'lbrycrd_main')
        self.storage = WalletStorage(lbryum_path)
        self.wallet = Wallet(self.storage)
        self.cmd_runner = Commands(self.config, self.wallet, None)
        if not self.wallet.has_seed():
            seed = self.wallet.make_seed()
            self.wallet.add_seed(seed, "derp")
            self.wallet.create_master_keys("derp")
            self.wallet.create_main_account()
            self.wallet.update_password("derp", "")
        self.network = Network(self.config)
        self.blockchain = get_blockchain(self.config, self.network)
        print self.config.get('chain'), self.blockchain
        self.wallet.storage.write()

    def command(self, command_name, *args, **kwargs):
        cmd_runner = Commands(self.config, self.wallet, None)
        cmd = known_commands[command_name]
        func = getattr(cmd_runner, cmd.name)
        return func(*args, **kwargs)

    def generate_address(self):
        address = self.wallet.create_new_address()
        self.wallet.storage.write()
        return address
Exemple #2
0
    def load_wallet(self, path, get_wizard=None):
        if path in self.wallets:
            wallet = self.wallets[path]
        else:
            storage = WalletStorage(path)
            if get_wizard:
                if storage.file_exists:
                    wallet = Wallet(storage)
                    action = wallet.get_action()
                else:
                    action = 'new'
                if action:
                    wizard = get_wizard()
                    wallet = wizard.run(self.network, storage)
                else:
                    wallet.start_threads(self.network)
            else:
                wallet = Wallet(storage)
                # automatically generate wallet for lbrynet
                if not storage.file_exists:
                    seed = wallet.make_seed()
                    wallet.add_seed(seed, None)
                    wallet.create_master_keys(None)
                    wallet.create_main_account()
                    wallet.synchronize()

                wallet.start_threads(self.network)
            if wallet:
                self.wallets[path] = wallet
        return wallet
Exemple #3
0
 def get_wallet():
     path = self.config.get_wallet_path()
     storage = WalletStorage(path)
     wallet = Wallet(storage)
     if not storage.file_exists:
         self.first_run = True
         seed = wallet.make_seed()
         wallet.add_seed(seed, None)
         wallet.create_master_keys(None)
         wallet.create_main_account()
         wallet.synchronize()
     self.wallet = wallet
Exemple #4
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)
Exemple #5
0
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)