|
@ -95,21 +95,30 @@ def command(s): |
|
|
name = func.__name__ |
|
|
name = func.__name__ |
|
|
known_commands[name] = Command(func, s) |
|
|
known_commands[name] = Command(func, s) |
|
|
@wraps(func) |
|
|
@wraps(func) |
|
|
def func_wrapper(*args, **kwargs): |
|
|
async def func_wrapper(*args, **kwargs): |
|
|
c = known_commands[func.__name__] |
|
|
cmd_runner = args[0] |
|
|
|
|
|
cmd = known_commands[func.__name__] |
|
|
password = kwargs.get('password') |
|
|
password = kwargs.get('password') |
|
|
wallet = kwargs.get('wallet') # wallet is passed here if we are offline |
|
|
daemon = cmd_runner.daemon |
|
|
if c.requires_wallet and wallet is None: |
|
|
if daemon: |
|
|
cmd_runner = args[0] |
|
|
if (cmd.requires_wallet or 'wallet_path' in cmd.options) and kwargs.get('wallet_path') is None: |
|
|
path = cmd_runner.config.get_wallet_path() |
|
|
kwargs['wallet_path'] = daemon.config.get_wallet_path() |
|
|
path = standardize_path(path) |
|
|
if cmd.requires_wallet: |
|
|
wallet = cmd_runner.daemon.wallets.get(path) |
|
|
wallet_path = kwargs.pop('wallet_path') |
|
|
if wallet is None: |
|
|
wallet = daemon.wallets.get(wallet_path) |
|
|
raise Exception("wallet not loaded. Use 'electrum load_wallet'") |
|
|
if wallet is None: |
|
|
kwargs['wallet'] = wallet |
|
|
return {'error': "Wallet not loaded. try 'electrum load_wallet'" } |
|
|
if c.requires_password and password is None and wallet.has_password(): |
|
|
kwargs['wallet'] = wallet |
|
|
|
|
|
else: |
|
|
|
|
|
# we are offline. the wallet must have been passed |
|
|
|
|
|
pass |
|
|
|
|
|
if cmd.requires_password and password is None and wallet.has_password(): |
|
|
return {'error': 'Password required' } |
|
|
return {'error': 'Password required' } |
|
|
return func(*args, **kwargs) |
|
|
try: |
|
|
|
|
|
return await func(*args, **kwargs) |
|
|
|
|
|
except Exception as e: |
|
|
|
|
|
#traceback.print_exc(sys.stderr) |
|
|
|
|
|
return {'error':str(e)} |
|
|
return func_wrapper |
|
|
return func_wrapper |
|
|
return decorator |
|
|
return decorator |
|
|
|
|
|
|
|
@ -182,27 +191,25 @@ class Commands: |
|
|
return [{'path':k, 'synchronized':w.is_up_to_date()} for k, w in self.daemon.wallets.items()] |
|
|
return [{'path':k, 'synchronized':w.is_up_to_date()} for k, w in self.daemon.wallets.items()] |
|
|
|
|
|
|
|
|
@command('n') |
|
|
@command('n') |
|
|
async def load_wallet(self): |
|
|
async def load_wallet(self, wallet_path=None): |
|
|
"""Open wallet in daemon""" |
|
|
"""Open wallet in daemon""" |
|
|
path = self.config.get_wallet_path() |
|
|
wallet = self.daemon.load_wallet(wallet_path, self.config.get('password')) |
|
|
wallet = self.daemon.load_wallet(path, self.config.get('password')) |
|
|
|
|
|
if wallet is not None: |
|
|
if wallet is not None: |
|
|
run_hook('load_wallet', wallet, None) |
|
|
run_hook('load_wallet', wallet, None) |
|
|
response = wallet is not None |
|
|
response = wallet is not None |
|
|
return response |
|
|
return response |
|
|
|
|
|
|
|
|
@command('n') |
|
|
@command('n') |
|
|
async def close_wallet(self): |
|
|
async def close_wallet(self, wallet_path=None): |
|
|
"""Close wallet""" |
|
|
"""Close wallet""" |
|
|
path = self.config.get_wallet_path() |
|
|
return self.daemon.stop_wallet(wallet_path) |
|
|
return self.daemon.stop_wallet(path) |
|
|
|
|
|
|
|
|
|
|
|
@command('') |
|
|
@command('') |
|
|
async def create(self, passphrase=None, password=None, encrypt_file=True, seed_type=None): |
|
|
async def create(self, passphrase=None, password=None, encrypt_file=True, seed_type=None, wallet_path=None): |
|
|
"""Create a new wallet. |
|
|
"""Create a new wallet. |
|
|
If you want to be prompted for an argument, type '?' or ':' (concealed) |
|
|
If you want to be prompted for an argument, type '?' or ':' (concealed) |
|
|
""" |
|
|
""" |
|
|
d = create_new_wallet(path=self.config.get_wallet_path(), |
|
|
d = create_new_wallet(path=wallet_path, |
|
|
passphrase=passphrase, |
|
|
passphrase=passphrase, |
|
|
password=password, |
|
|
password=password, |
|
|
encrypt_file=encrypt_file, |
|
|
encrypt_file=encrypt_file, |
|
@ -214,7 +221,7 @@ class Commands: |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@command('') |
|
|
@command('') |
|
|
async def restore(self, text, passphrase=None, password=None, encrypt_file=True): |
|
|
async def restore(self, text, passphrase=None, password=None, encrypt_file=True, wallet_path=None): |
|
|
"""Restore a wallet from text. Text can be a seed phrase, a master |
|
|
"""Restore a wallet from text. Text can be a seed phrase, a master |
|
|
public key, a master private key, a list of bitcoin addresses |
|
|
public key, a master private key, a list of bitcoin addresses |
|
|
or bitcoin private keys. |
|
|
or bitcoin private keys. |
|
@ -222,7 +229,7 @@ class Commands: |
|
|
""" |
|
|
""" |
|
|
# TODO create a separate command that blocks until wallet is synced |
|
|
# TODO create a separate command that blocks until wallet is synced |
|
|
d = restore_wallet_from_text(text, |
|
|
d = restore_wallet_from_text(text, |
|
|
path=self.config.get_wallet_path(), |
|
|
path=wallet_path, |
|
|
passphrase=passphrase, |
|
|
passphrase=passphrase, |
|
|
password=password, |
|
|
password=password, |
|
|
encrypt_file=encrypt_file) |
|
|
encrypt_file=encrypt_file) |
|
@ -1148,7 +1155,7 @@ def get_parser(): |
|
|
p = subparsers.add_parser(cmdname, help=cmd.help, description=cmd.description) |
|
|
p = subparsers.add_parser(cmdname, help=cmd.help, description=cmd.description) |
|
|
add_global_options(p) |
|
|
add_global_options(p) |
|
|
for optname, default in zip(cmd.options, cmd.defaults): |
|
|
for optname, default in zip(cmd.options, cmd.defaults): |
|
|
if optname == 'wallet': |
|
|
if optname in ['wallet_path', 'wallet']: |
|
|
continue |
|
|
continue |
|
|
a, help = command_options[optname] |
|
|
a, help = command_options[optname] |
|
|
b = '--' + optname |
|
|
b = '--' + optname |
|
@ -1161,7 +1168,7 @@ def get_parser(): |
|
|
p.add_argument(*args, dest=optname, action=action, default=default, help=help) |
|
|
p.add_argument(*args, dest=optname, action=action, default=default, help=help) |
|
|
|
|
|
|
|
|
for param in cmd.params: |
|
|
for param in cmd.params: |
|
|
if param == 'wallet': |
|
|
if param in ['wallet_path', 'wallet']: |
|
|
continue |
|
|
continue |
|
|
h = param_descriptions.get(param, '') |
|
|
h = param_descriptions.get(param, '') |
|
|
_type = arg_types.get(param, str) |
|
|
_type = arg_types.get(param, str) |
|
|