whitespace, imports
This commit is contained in:
@@ -33,8 +33,7 @@ import base64
|
|||||||
import asyncio
|
import asyncio
|
||||||
import inspect
|
import inspect
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from functools import wraps, partial
|
from functools import wraps
|
||||||
from itertools import repeat
|
|
||||||
from decimal import Decimal, InvalidOperation
|
from decimal import Decimal, InvalidOperation
|
||||||
from typing import Optional, TYPE_CHECKING, Dict, List
|
from typing import Optional, TYPE_CHECKING, Dict, List
|
||||||
import os
|
import os
|
||||||
@@ -46,27 +45,31 @@ from . import util
|
|||||||
from .lnmsg import OnionWireSerializer
|
from .lnmsg import OnionWireSerializer
|
||||||
from .logging import Logger
|
from .logging import Logger
|
||||||
from .onion_message import create_blinded_path, send_onion_message_to
|
from .onion_message import create_blinded_path, send_onion_message_to
|
||||||
from .util import (bfh, json_decode, json_normalize, is_hash256_str, is_hex_str, to_bytes,
|
from .util import (
|
||||||
parse_max_spend, to_decimal, UserFacingException, InvalidPassword)
|
bfh, json_decode, json_normalize, is_hash256_str, is_hex_str, to_bytes, parse_max_spend, to_decimal,
|
||||||
|
UserFacingException, InvalidPassword
|
||||||
|
)
|
||||||
from . import bitcoin
|
from . import bitcoin
|
||||||
from .bitcoin import is_address, hash_160, COIN
|
from .bitcoin import is_address, hash_160, COIN
|
||||||
from .bip32 import BIP32Node
|
from .bip32 import BIP32Node
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
from .transaction import (Transaction, multisig_script, TxOutput, PartialTransaction, PartialTxOutput,
|
from .transaction import (
|
||||||
tx_from_any, PartialTxInput, TxOutpoint)
|
Transaction, multisig_script, PartialTransaction, PartialTxOutput, tx_from_any, PartialTxInput, TxOutpoint,
|
||||||
|
convert_raw_tx_to_hex
|
||||||
|
)
|
||||||
from . import transaction
|
from . import transaction
|
||||||
from .invoices import PR_PAID, PR_UNPAID, PR_UNKNOWN, PR_EXPIRED
|
from .invoices import Invoice, PR_PAID, PR_UNPAID, PR_EXPIRED
|
||||||
from .synchronizer import Notifier
|
from .synchronizer import Notifier
|
||||||
from .wallet import Abstract_Wallet, create_new_wallet, restore_wallet_from_text, Deterministic_Wallet, BumpFeeStrategy, Imported_Wallet
|
from .wallet import (
|
||||||
|
Abstract_Wallet, create_new_wallet, restore_wallet_from_text, Deterministic_Wallet, BumpFeeStrategy,
|
||||||
|
Imported_Wallet
|
||||||
|
)
|
||||||
from .address_synchronizer import TX_HEIGHT_LOCAL
|
from .address_synchronizer import TX_HEIGHT_LOCAL
|
||||||
from .mnemonic import Mnemonic
|
from .mnemonic import Mnemonic
|
||||||
from .lntransport import extract_nodeid
|
from .lnutil import channel_id_from_funding_tx, LnFeatures, SENT, MIN_FINAL_CLTV_DELTA_FOR_INVOICE
|
||||||
from .lnutil import channel_id_from_funding_tx, LnFeatures, SENT, RECEIVED, MIN_FINAL_CLTV_DELTA_FOR_INVOICE
|
|
||||||
from .plugin import run_hook, DeviceMgr, Plugins
|
from .plugin import run_hook, DeviceMgr, Plugins
|
||||||
from .version import ELECTRUM_VERSION
|
from .version import ELECTRUM_VERSION
|
||||||
from .simple_config import SimpleConfig
|
from .simple_config import SimpleConfig
|
||||||
from .invoices import Invoice
|
|
||||||
from .fee_policy import FeePolicy
|
from .fee_policy import FeePolicy
|
||||||
from . import GuiImportError
|
from . import GuiImportError
|
||||||
from . import crypto
|
from . import crypto
|
||||||
@@ -348,7 +351,7 @@ class Commands(Logger):
|
|||||||
encrypt_file = wallet.storage.is_encrypted()
|
encrypt_file = wallet.storage.is_encrypted()
|
||||||
wallet.update_password(password, new_password, encrypt_storage=encrypt_file)
|
wallet.update_password(password, new_password, encrypt_storage=encrypt_file)
|
||||||
wallet.save_db()
|
wallet.save_db()
|
||||||
return {'password':wallet.has_password()}
|
return {'password': wallet.has_password()}
|
||||||
|
|
||||||
@command('w')
|
@command('w')
|
||||||
async def get(self, key, wallet: Abstract_Wallet = None):
|
async def get(self, key, wallet: Abstract_Wallet = None):
|
||||||
@@ -1365,7 +1368,7 @@ class Commands(Logger):
|
|||||||
expiry: int = 3600,
|
expiry: int = 3600,
|
||||||
min_final_cltv_expiry_delta: int = MIN_FINAL_CLTV_DELTA_FOR_INVOICE * 2,
|
min_final_cltv_expiry_delta: int = MIN_FINAL_CLTV_DELTA_FOR_INVOICE * 2,
|
||||||
wallet: Abstract_Wallet = None
|
wallet: Abstract_Wallet = None
|
||||||
) -> dict:
|
) -> dict:
|
||||||
"""
|
"""
|
||||||
Create a lightning hold invoice for the given preimage. Hold invoices have to get settled manually later.
|
Create a lightning hold invoice for the given preimage. Hold invoices have to get settled manually later.
|
||||||
HTLCs will get failed automatically if block_height + 144 > htlc.cltv_abs.
|
HTLCs will get failed automatically if block_height + 144 > htlc.cltv_abs.
|
||||||
@@ -1650,9 +1653,9 @@ class Commands(Logger):
|
|||||||
"""
|
"""
|
||||||
lnworker = self.network.lngossip if gossip else wallet.lnworker
|
lnworker = self.network.lngossip if gossip else wallet.lnworker
|
||||||
return [{
|
return [{
|
||||||
'node_id':p.pubkey.hex(),
|
'node_id': p.pubkey.hex(),
|
||||||
'address':p.transport.name(),
|
'address': p.transport.name(),
|
||||||
'initialized':p.is_initialized(),
|
'initialized': p.is_initialized(),
|
||||||
'features': str(LnFeatures(p.features)),
|
'features': str(LnFeatures(p.features)),
|
||||||
'channels': [c.funding_outpoint.to_str() for c in p.channels.values()],
|
'channels': [c.funding_outpoint.to_str() for c in p.channels.values()],
|
||||||
} for p in lnworker.peers.values()]
|
} for p in lnworker.peers.values()]
|
||||||
@@ -1738,7 +1741,7 @@ class Commands(Logger):
|
|||||||
'remote_balance': chan.balance(REMOTE)//1000,
|
'remote_balance': chan.balance(REMOTE)//1000,
|
||||||
'local_ctn': chan.get_latest_ctn(LOCAL),
|
'local_ctn': chan.get_latest_ctn(LOCAL),
|
||||||
'remote_ctn': chan.get_latest_ctn(REMOTE),
|
'remote_ctn': chan.get_latest_ctn(REMOTE),
|
||||||
'local_reserve': chan.config[REMOTE].reserve_sat, # their config has our reserve
|
'local_reserve': chan.config[REMOTE].reserve_sat, # their config has our reserve
|
||||||
'remote_reserve': chan.config[LOCAL].reserve_sat,
|
'remote_reserve': chan.config[LOCAL].reserve_sat,
|
||||||
'local_unsettled_sent': chan.balance_tied_up_in_htlcs_by_direction(LOCAL, direction=SENT) // 1000,
|
'local_unsettled_sent': chan.balance_tied_up_in_htlcs_by_direction(LOCAL, direction=SENT) // 1000,
|
||||||
'remote_unsettled_sent': chan.balance_tied_up_in_htlcs_by_direction(REMOTE, direction=SENT) // 1000,
|
'remote_unsettled_sent': chan.balance_tied_up_in_htlcs_by_direction(REMOTE, direction=SENT) // 1000,
|
||||||
@@ -2055,6 +2058,7 @@ class Commands(Logger):
|
|||||||
|
|
||||||
return encoded_blinded_path.hex()
|
return encoded_blinded_path.hex()
|
||||||
|
|
||||||
|
|
||||||
def plugin_command(s, plugin_name):
|
def plugin_command(s, plugin_name):
|
||||||
"""Decorator to register a cli command inside a plugin. To be used within a commands.py file
|
"""Decorator to register a cli command inside a plugin. To be used within a commands.py file
|
||||||
in the plugins root."""
|
in the plugins root."""
|
||||||
@@ -2065,6 +2069,7 @@ def plugin_command(s, plugin_name):
|
|||||||
if name in known_commands or hasattr(Commands, name):
|
if name in known_commands or hasattr(Commands, name):
|
||||||
raise Exception(f"Command name {name} already exists. Plugin commands should not overwrite other commands.")
|
raise Exception(f"Command name {name} already exists. Plugin commands should not overwrite other commands.")
|
||||||
assert asyncio.iscoroutinefunction(func), f"Plugin commands must be a coroutine: {name}"
|
assert asyncio.iscoroutinefunction(func), f"Plugin commands must be a coroutine: {name}"
|
||||||
|
|
||||||
@command(s)
|
@command(s)
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
async def func_wrapper(*args, **kwargs):
|
async def func_wrapper(*args, **kwargs):
|
||||||
@@ -2072,6 +2077,7 @@ def plugin_command(s, plugin_name):
|
|||||||
daemon = cmd_runner.daemon
|
daemon = cmd_runner.daemon
|
||||||
kwargs['plugin'] = daemon._plugins.get_plugin(plugin_name)
|
kwargs['plugin'] = daemon._plugins.get_plugin(plugin_name)
|
||||||
return await func(*args, **kwargs)
|
return await func(*args, **kwargs)
|
||||||
|
|
||||||
setattr(Commands, name, func_wrapper)
|
setattr(Commands, name, func_wrapper)
|
||||||
return func_wrapper
|
return func_wrapper
|
||||||
return decorator
|
return decorator
|
||||||
@@ -2086,15 +2092,16 @@ def eval_bool(x: str) -> bool:
|
|||||||
return bool(ast.literal_eval(x))
|
return bool(ast.literal_eval(x))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# don't use floats because of rounding errors
|
# don't use floats because of rounding errors
|
||||||
from .transaction import convert_raw_tx_to_hex
|
|
||||||
json_loads = lambda x: json.loads(x, parse_float=lambda x: str(to_decimal(x)))
|
json_loads = lambda x: json.loads(x, parse_float=lambda x: str(to_decimal(x)))
|
||||||
|
|
||||||
|
|
||||||
def check_txid(txid):
|
def check_txid(txid):
|
||||||
if not is_hash256_str(txid):
|
if not is_hash256_str(txid):
|
||||||
raise UserFacingException(f"{repr(txid)} is not a txid")
|
raise UserFacingException(f"{repr(txid)} is not a txid")
|
||||||
return txid
|
return txid
|
||||||
|
|
||||||
|
|
||||||
arg_types = {
|
arg_types = {
|
||||||
'int': int,
|
'int': int,
|
||||||
'bool': eval_bool,
|
'bool': eval_bool,
|
||||||
@@ -2113,7 +2120,7 @@ config_variables = {
|
|||||||
'ssl_chain': 'Chain of SSL certificates, needed for signed requests. Put your certificate at the top and the root CA at the end',
|
'ssl_chain': 'Chain of SSL certificates, needed for signed requests. Put your certificate at the top and the root CA at the end',
|
||||||
'url_rewrite': 'Parameters passed to str.replace(), in order to create the r= part of bitcoin: URIs. Example: \"(\'file:///var/www/\',\'https://electrum.org/\')\"',
|
'url_rewrite': 'Parameters passed to str.replace(), in order to create the r= part of bitcoin: URIs. Example: \"(\'file:///var/www/\',\'https://electrum.org/\')\"',
|
||||||
},
|
},
|
||||||
'listrequests':{
|
'listrequests': {
|
||||||
'url_rewrite': 'Parameters passed to str.replace(), in order to create the r= part of bitcoin: URIs. Example: \"(\'file:///var/www/\',\'https://electrum.org/\')\"',
|
'url_rewrite': 'Parameters passed to str.replace(), in order to create the r= part of bitcoin: URIs. Example: \"(\'file:///var/www/\',\'https://electrum.org/\')\"',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2234,18 +2241,19 @@ def add_global_options(parser, suppress=False):
|
|||||||
help=argparse.SUPPRESS if suppress else "Forget config on exit")
|
help=argparse.SUPPRESS if suppress else "Forget config on exit")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_simple_parser():
|
def get_simple_parser():
|
||||||
""" simple parser that figures out the path of the config file and ignore unknown args """
|
""" simple parser that figures out the path of the config file and ignore unknown args """
|
||||||
from optparse import OptionParser, BadOptionError, AmbiguousOptionError
|
from optparse import OptionParser, BadOptionError, AmbiguousOptionError
|
||||||
|
|
||||||
class PassThroughOptionParser(OptionParser):
|
class PassThroughOptionParser(OptionParser):
|
||||||
# see https://stackoverflow.com/questions/1885161/how-can-i-get-optparses-optionparser-to-ignore-invalid-options
|
# see https://stackoverflow.com/questions/1885161/how-can-i-get-optparses-optionparser-to-ignore-invalid-options
|
||||||
def _process_args(self, largs, rargs, values):
|
def _process_args(self, largs, rargs, values):
|
||||||
while rargs:
|
while rargs:
|
||||||
try:
|
try:
|
||||||
OptionParser._process_args(self,largs,rargs,values)
|
OptionParser._process_args(self, largs, rargs, values)
|
||||||
except (BadOptionError,AmbiguousOptionError) as e:
|
except (BadOptionError, AmbiguousOptionError) as e:
|
||||||
largs.append(e.opt_str)
|
largs.append(e.opt_str)
|
||||||
|
|
||||||
parser = PassThroughOptionParser()
|
parser = PassThroughOptionParser()
|
||||||
parser.add_option("-D", "--dir", dest="electrum_path", help="electrum directory")
|
parser.add_option("-D", "--dir", dest="electrum_path", help="electrum directory")
|
||||||
parser.add_option("-P", "--portable", action="store_true", dest="portable", default=False, help="Use local 'electrum_data' directory")
|
parser.add_option("-P", "--portable", action="store_true", dest="portable", default=False, help="Use local 'electrum_data' directory")
|
||||||
|
|||||||
@@ -95,7 +95,6 @@ sys._ELECTRUM_RUNNING_VIA_RUNELECTRUM = True # used by logging.py
|
|||||||
from electrum.logging import get_logger, configure_logging # import logging submodule first
|
from electrum.logging import get_logger, configure_logging # import logging submodule first
|
||||||
from electrum import util
|
from electrum import util
|
||||||
from electrum.payment_identifier import PaymentIdentifier
|
from electrum.payment_identifier import PaymentIdentifier
|
||||||
from electrum import constants
|
|
||||||
from electrum import SimpleConfig
|
from electrum import SimpleConfig
|
||||||
from electrum.wallet_db import WalletDB
|
from electrum.wallet_db import WalletDB
|
||||||
from electrum.wallet import Wallet
|
from electrum.wallet import Wallet
|
||||||
@@ -105,7 +104,6 @@ from electrum.util import InvalidPassword
|
|||||||
from electrum.plugin import Plugins
|
from electrum.plugin import Plugins
|
||||||
from electrum.commands import get_parser, get_simple_parser, known_commands, Commands, config_variables
|
from electrum.commands import get_parser, get_simple_parser, known_commands, Commands, config_variables
|
||||||
from electrum import daemon
|
from electrum import daemon
|
||||||
from electrum import keystore
|
|
||||||
from electrum.util import create_and_start_event_loop, UserFacingException, JsonRPCError
|
from electrum.util import create_and_start_event_loop, UserFacingException, JsonRPCError
|
||||||
from electrum.i18n import set_language
|
from electrum.i18n import set_language
|
||||||
|
|
||||||
@@ -268,6 +266,7 @@ loop = None # type: Optional[asyncio.AbstractEventLoop]
|
|||||||
stop_loop = None # type: Optional[asyncio.Future]
|
stop_loop = None # type: Optional[asyncio.Future]
|
||||||
loop_thread = None # type: Optional[threading.Thread]
|
loop_thread = None # type: Optional[threading.Thread]
|
||||||
|
|
||||||
|
|
||||||
def sys_exit(i):
|
def sys_exit(i):
|
||||||
# stop event loop and exit
|
# stop event loop and exit
|
||||||
if loop:
|
if loop:
|
||||||
@@ -275,6 +274,7 @@ def sys_exit(i):
|
|||||||
loop_thread.join(timeout=1)
|
loop_thread.join(timeout=1)
|
||||||
sys.exit(i)
|
sys.exit(i)
|
||||||
|
|
||||||
|
|
||||||
def read_config(config_options: dict) -> SimpleConfig:
|
def read_config(config_options: dict) -> SimpleConfig:
|
||||||
"""
|
"""
|
||||||
Reads the config file and returns SimpleConfig, on failure it will potentially
|
Reads the config file and returns SimpleConfig, on failure it will potentially
|
||||||
@@ -294,6 +294,7 @@ def read_config(config_options: dict) -> SimpleConfig:
|
|||||||
print_stderr(f"Error showing standalone gui dialog: {e}")
|
print_stderr(f"Error showing standalone gui dialog: {e}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def parse_command_line(simple_parser=False) -> Dict:
|
def parse_command_line(simple_parser=False) -> Dict:
|
||||||
# parse command line from sys.argv
|
# parse command line from sys.argv
|
||||||
if simple_parser:
|
if simple_parser:
|
||||||
@@ -334,6 +335,7 @@ def parse_command_line(simple_parser=False) -> Dict:
|
|||||||
warnings.simplefilter('ignore', DeprecationWarning)
|
warnings.simplefilter('ignore', DeprecationWarning)
|
||||||
return config_options
|
return config_options
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global loop, stop_loop, loop_thread
|
global loop, stop_loop, loop_thread
|
||||||
# The hook will only be used in the Qt GUI right now
|
# The hook will only be used in the Qt GUI right now
|
||||||
|
|||||||
Reference in New Issue
Block a user