mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-30 17:01:34 +00:00
read command line arguments from stdin if '-' is passed
This commit is contained in:
parent
5686499eae
commit
02e81a3655
2 changed files with 34 additions and 20 deletions
37
electrum
37
electrum
|
@ -80,14 +80,11 @@ from electrum.commands import get_parser, known_commands, Commands, config_varia
|
||||||
# get password routine
|
# get password routine
|
||||||
def prompt_password(prompt, confirm=True):
|
def prompt_password(prompt, confirm=True):
|
||||||
import getpass
|
import getpass
|
||||||
if sys.stdin.isatty():
|
password = getpass.getpass(prompt)
|
||||||
password = getpass.getpass(prompt)
|
if password and confirm:
|
||||||
if password and confirm:
|
password2 = getpass.getpass("Confirm: ")
|
||||||
password2 = getpass.getpass("Confirm: ")
|
if password != password2:
|
||||||
if password != password2:
|
sys.exit("Error: Passwords do not match.")
|
||||||
sys.exit("Error: Passwords do not match.")
|
|
||||||
else:
|
|
||||||
password = raw_input(prompt)
|
|
||||||
if not password:
|
if not password:
|
||||||
password = None
|
password = None
|
||||||
return password
|
return password
|
||||||
|
@ -204,6 +201,20 @@ def run_cmdline(config):
|
||||||
# options
|
# options
|
||||||
args += map(lambda x: config.get(x), cmd.options)
|
args += map(lambda x: config.get(x), cmd.options)
|
||||||
|
|
||||||
|
# pipe data
|
||||||
|
for i, arg in enumerate(args):
|
||||||
|
if arg == '-':
|
||||||
|
if not sys.stdin.isatty():
|
||||||
|
pipe_data = sys.stdin.read()
|
||||||
|
try:
|
||||||
|
pipe_data = json.loads(pipe_data)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
args[i] = pipe_data
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise BaseException('Cannot get argument from stdin')
|
||||||
|
|
||||||
# instanciate wallet for command-line
|
# instanciate wallet for command-line
|
||||||
storage = WalletStorage(config.get_wallet_path())
|
storage = WalletStorage(config.get_wallet_path())
|
||||||
|
|
||||||
|
@ -272,14 +283,16 @@ def run_cmdline(config):
|
||||||
always_hook('cmdline_load_wallet', wallet)
|
always_hook('cmdline_load_wallet', wallet)
|
||||||
|
|
||||||
# important warning
|
# important warning
|
||||||
if cmd.name in ['dumpprivkey', 'dumpprivkeys']:
|
if cmd.name in ['getprivatekeys', 'dumpprivkeys']:
|
||||||
print_stderr("WARNING: ALL your private keys are secret.")
|
print_stderr("WARNING: ALL your private keys are secret.")
|
||||||
print_stderr("Exposing a single private key can compromise your entire wallet!")
|
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.")
|
print_stderr("In particular, DO NOT use 'redeem private key' services proposed by third parties.")
|
||||||
|
|
||||||
# commands needing password
|
# commands needing password
|
||||||
if cmd.requires_password:
|
if cmd.requires_password and wallet.use_encryption:
|
||||||
if wallet.use_encryption:
|
if config.get('password'):
|
||||||
|
password = config.get('password')
|
||||||
|
else:
|
||||||
password = prompt_password('Password:', False)
|
password = prompt_password('Password:', False)
|
||||||
if not password:
|
if not password:
|
||||||
print_msg("Error: Password required")
|
print_msg("Error: Password required")
|
||||||
|
@ -290,8 +303,6 @@ def run_cmdline(config):
|
||||||
except InvalidPassword:
|
except InvalidPassword:
|
||||||
print_msg("Error: This password does not decode this wallet.")
|
print_msg("Error: This password does not decode this wallet.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
|
||||||
password = None
|
|
||||||
else:
|
else:
|
||||||
password = None
|
password = None
|
||||||
|
|
||||||
|
|
|
@ -239,8 +239,11 @@ class Commands:
|
||||||
|
|
||||||
@command('wp')
|
@command('wp')
|
||||||
def getprivatekeys(self, address):
|
def getprivatekeys(self, address):
|
||||||
"""Get the private keys of an address. Address must be in wallet."""
|
"""Get the private keys of a wallet address, or list of wallet addresses."""
|
||||||
return self.wallet.get_private_key(address, self.password)
|
is_list = type(address) is list
|
||||||
|
domain = address if is_list else [address]
|
||||||
|
out = [self.wallet.get_private_key(address, self.password) for address in domain]
|
||||||
|
return out if is_list else out[0]
|
||||||
|
|
||||||
@command('w')
|
@command('w')
|
||||||
def ismine(self, address):
|
def ismine(self, address):
|
||||||
|
@ -248,10 +251,9 @@ class Commands:
|
||||||
return self.wallet.is_mine(address)
|
return self.wallet.is_mine(address)
|
||||||
|
|
||||||
@command('wp')
|
@command('wp')
|
||||||
def dumpprivkeys(self, domain=None):
|
def dumpprivkeys(self):
|
||||||
"""Dump private keys from your wallet"""
|
"""Dump private keys from your wallet"""
|
||||||
if domain is None:
|
domain = self.wallet.addresses(True)
|
||||||
domain = self.wallet.addresses(True)
|
|
||||||
return [self.wallet.get_private_key(address, self.password) for address in domain]
|
return [self.wallet.get_private_key(address, self.password) for address in domain]
|
||||||
|
|
||||||
@command('')
|
@command('')
|
||||||
|
@ -353,15 +355,16 @@ class Commands:
|
||||||
|
|
||||||
@command('n')
|
@command('n')
|
||||||
def sweep(self, privkey, destination, tx_fee=None, nocheck=False):
|
def sweep(self, privkey, destination, tx_fee=None, nocheck=False):
|
||||||
"""Sweep private key. Returns a transaction that spends UTXOs from
|
"""Sweep private keys. Returns a transaction that spends UTXOs from
|
||||||
privkey to a destination address. The transaction is not
|
privkey to a destination address. The transaction is not
|
||||||
broadcasted."""
|
broadcasted."""
|
||||||
|
privkeys = privkey if type(privkey) is list else [privkey]
|
||||||
self.nocheck = nocheck
|
self.nocheck = nocheck
|
||||||
dest = self._resolver(destination)
|
dest = self._resolver(destination)
|
||||||
if tx_fee is None:
|
if tx_fee is None:
|
||||||
tx_fee = 0.0001
|
tx_fee = 0.0001
|
||||||
fee = int(Decimal(tx_fee)*COIN)
|
fee = int(Decimal(tx_fee)*COIN)
|
||||||
return Transaction.sweep([privkey], self.network, dest, fee)
|
return Transaction.sweep(privkeys, self.network, dest, fee)
|
||||||
|
|
||||||
@command('wp')
|
@command('wp')
|
||||||
def signmessage(self, address, message):
|
def signmessage(self, address, message):
|
||||||
|
|
Loading…
Add table
Reference in a new issue