Пример #1
0
def run_offline_command(config, config_options):
    cmdname = config.get('cmd')
    cmd = known_commands[cmdname]
    storage = WalletStorage(config.get_wallet_path())
    wallet = Wallet(storage) if cmd.requires_wallet else None
    # check password
    if cmd.requires_password and storage.get('use_encryption'):
        password = config_options.get('password')
        try:
            seed = wallet.check_password(password)
        except InvalidPassword:
            print "Error: This password does not decode this wallet."
            sys.exit(1)
    if cmd.requires_network:
        print "Warning: running command offline"
    # arguments passed to function
    args = map(lambda x: config.get(x), cmd.params)
    # decode json arguments
    args = map(json_decode, args)
    # options
    args += map(lambda x: config.get(x), cmd.options)
    cmd_runner = Commands(config,
                          wallet,
                          None,
                          password=config_options.get('password'),
                          new_password=config_options.get('new_password'))
    func = getattr(cmd_runner, cmd.name)
    result = func(*args)
    # save wallet
    if wallet:
        wallet.storage.write()
    return result
Пример #2
0
def run_offline_command(config, config_options):
    _ = get_blockchain(config, None)
    cmdname = config.get('cmd')
    cmd = Commands.known_commands[cmdname]
    storage = WalletStorage(config.get_wallet_path())
    wallet = Wallet(storage) if cmd.requires_wallet else None
    # check password
    if cmd.requires_password and storage.get('use_encryption'):
        password = config_options.get('password')
        try:
            seed = wallet.check_password(password)
        except InvalidPassword:
            print "Error: This password does not decode this wallet."
            sys.exit(1)
    if cmd.requires_network:
        print "Warning: running command offline"
    # arguments passed to function
    args = map(lambda x: config.get(x), cmd.params)
    # decode json arguments
    args = map(json_decode, args)
    # options
    args += map(lambda x: config.get(x), cmd.options)
    cmd_runner = Commands(config, wallet, None,
                          password=config_options.get('password'),
                          new_password=config_options.get('new_password'))
    func = getattr(cmd_runner, cmd.name)
    result = func(*args)
    # save wallet
    if wallet:
        wallet.storage.write()
    return result
Пример #3
0
    def test_read_dictionary_from_file(self):
        some_dict = {"a": "b", "c": "d"}
        contents = repr(some_dict)
        with open(self.wallet_path, "w") as f:
            contents = f.write(contents)

        storage = WalletStorage(self.wallet_path)
        self.assertEqual("b", storage.get("a"))
        self.assertEqual("d", storage.get("c"))
Пример #4
0
    def test_read_dictionnary_from_file(self):
        some_dict = {"a": "b", "c": "d"}
        contents = repr(some_dict)
        with open(self.wallet_path, "w") as f:
            contents = f.write(contents)

        storage = WalletStorage(self.wallet_path)
        self.assertEqual("b", storage.get("a"))
        self.assertEqual("d", storage.get("c"))
Пример #5
0
def init_cmdline(config_options):
    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

    if cmdname in ['createrawtx'] and config.get('unsigned'):
        cmd.requires_password = False
        cmd.requires_wallet = False

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

    if cmd.requires_wallet and not storage.file_exists:
        log.error("Error: Wallet file not found.")
        print "Type 'lbryum 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 "WARNING: ALL your private keys are secret."
        print "Exposing a single private key can compromise your entire wallet!"
        print "In particular, DO NOT use 'redeem private key' services proposed by third parties."

    # commands needing password
    if cmd.requires_password and storage.get('use_encryption'):
        if config.get('password'):
            password = config.get('password')
        else:
            password = prompt_password('Password:'******'password'] = password

    if cmd.name == 'password':
        new_password = prompt_password('New password:'******'new_password'] = new_password

    return cmd, password
Пример #6
0
def init_cmdline(config_options):
    config = SimpleConfig(config_options)
    cmdname = config.get('cmd')
    cmd = Commands.known_commands[cmdname]

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

    if cmd.requires_wallet and not storage.file_exists:
        log.error("Error: Wallet file not found.")
        print "Type 'lbryum 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 "WARNING: ALL your private keys are secret."
        print "Exposing a single private key can compromise your entire wallet!"
        print "In particular, DO NOT use 'redeem private key' services proposed by third parties."

    # commands needing password
    if cmd.requires_password and storage.get('use_encryption'):
        if config.get('password'):
            password = config.get('password')
        else:
            password = prompt_password('Password:'******'password'] = password

    if cmd.name == 'password':
        new_password = prompt_password('New password:'******'password'] = password
        config_options['new_password'] = new_password

    return cmd, password