A new config API is introduced, and ~all of the codebase is adapted to it.
The old API is kept but mainly only for dynamic usage where its extra flexibility is needed.
Using examples, the old config API looked this:
```
>>> config.get("request_expiry", 86400)
604800
>>> config.set_key("request_expiry", 86400)
>>>
```
The new config API instead:
```
>>> config.WALLET_PAYREQ_EXPIRY_SECONDS
604800
>>> config.WALLET_PAYREQ_EXPIRY_SECONDS = 86400
>>>
```
The old API operated on arbitrary string keys, the new one uses
a static ~enum-like list of variables.
With the new API:
- there is a single centralised list of config variables, as opposed to
these being scattered all over
- no more duplication of default values (in the getters)
- there is now some (minimal for now) type-validation/conversion for
the config values
closes https://github.com/spesmilo/electrum/pull/5640
closes https://github.com/spesmilo/electrum/pull/5649
Note: there is yet a third API added here, for certain niche/abstract use-cases,
where we need a reference to the config variable itself.
It should only be used when needed:
```
>>> var = config.cv.WALLET_PAYREQ_EXPIRY_SECONDS
>>> var
<ConfigVarWithConfig key='request_expiry'>
>>> var.get()
604800
>>> var.set(3600)
>>> var.get_default_value()
86400
>>> var.is_set()
True
>>> var.is_modifiable()
True
```
parser.add_argument("-f","--serverfingerprint",dest="serverfingerprint",default=None,help="only allow connecting to servers with a matching SSL certificate SHA256 fingerprint."+""+
help="only allow connecting to servers with a matching SSL certificate SHA256 fingerprint. "+
"To calculate this yourself: '$ openssl x509 -noout -fingerprint -sha256 -inform pem -in mycertfile.crt'. Enter as 64 hex chars.")
parser.add_argument("-1","--oneserver",action="store_true",dest="oneserver",default=None,help="connect to one server only")
parser.add_argument("-s","--server",dest="server",default=None,help="set server host:port:protocol, where protocol is either t (tcp) or s (ssl)")
parser.add_argument("-p","--proxy",dest="proxy",default=None,help="set proxy [type:]host[:port] (or 'none' to disable proxy), where type is socks4,socks5 or http")
parser.add_argument("--noonion",action="store_true",dest="noonion",default=None,help="do not try to connect to onion servers")
parser.add_argument("--skipmerklecheck",action="store_true",dest="skipmerklecheck",default=None,help="Tolerate invalid merkle proofs from server")
parser.add_argument("-1","--oneserver",action="store_true",dest=SimpleConfig.NETWORK_ONESERVER.key(),default=None,help="connect to one server only")
parser.add_argument("-s","--server",dest=SimpleConfig.NETWORK_SERVER.key(),default=None,help="set server host:port:protocol, where protocol is either t (tcp) or s (ssl)")
parser.add_argument("-p","--proxy",dest=SimpleConfig.NETWORK_PROXY.key(),default=None,help="set proxy [type:]host[:port] (or 'none' to disable proxy), where type is socks4,socks5 or http")
parser.add_argument("--noonion",action="store_true",dest=SimpleConfig.NETWORK_NOONION.key(),default=None,help="do not try to connect to onion servers")
parser.add_argument("--skipmerklecheck",action="store_true",dest=SimpleConfig.NETWORK_SKIPMERKLECHECK.key(),default=None,help="Tolerate invalid merkle proofs from server")
parser.add_argument("--forgetconfig",action="store_true",dest="forget_config",default=False,help="Forget config on exit")
parser.add_argument("--forgetconfig",action="store_true",dest=SimpleConfig.CONFIG_FORGET_CHANGES.key(),default=False,help="Forget config on exit")
defget_parser():
# create main parser
@ -1582,11 +1583,11 @@ def get_parser():
# gui
parser_gui=subparsers.add_parser('gui',description="Run Electrum's Graphical User Interface.",help="Run GUI (default)")
parser_gui.add_argument("url",nargs='?',default=None,help="bitcoin URI (or bip70 file)")
parser_gui.add_argument("-g","--gui",dest="gui",help="select graphical user interface",choices=['qt','kivy','text','stdio','qml'])
parser_gui.add_argument("-m",action="store_true",dest="hide_gui",default=False,help="hide GUI on startup")
parser_gui.add_argument("-L","--lang",dest="language",default=None,help="default language used in GUI")
parser_gui.add_argument("-g","--gui",dest=SimpleConfig.GUI_NAME.key(),help="select graphical user interface",choices=['qt','kivy','text','stdio','qml'])
parser_gui.add_argument("-m",action="store_true",dest=SimpleConfig.GUI_QT_HIDE_ON_STARTUP.key(),default=False,help="hide GUI on startup")
parser_gui.add_argument("-L","--lang",dest=SimpleConfig.LOCALIZATION_LANGUAGE.key(),default=None,help="default language used in GUI")
parser_gui.add_argument("--daemon",action="store_true",dest="daemon",default=False,help="keep daemon running after GUI is closed")
parser_gui.add_argument("--nosegwit",action="store_true",dest="nosegwit",default=False,help="Do not create segwit wallets")
parser_gui.add_argument("--nosegwit",action="store_true",dest=SimpleConfig.WIZARD_DONT_CREATE_SEGWIT.key(),default=False,help="Do not create segwit wallets")
add_wallet_option(parser_gui)
add_network_options(parser_gui)
add_global_options(parser_gui)
@ -1595,10 +1596,10 @@ def get_parser():
parser_daemon.add_argument("-d","--detached",action="store_true",dest="detach",default=False,help="run daemon in detached mode")
# FIXME: all these options are rpc-server-side. The CLI client-side cannot use e.g. --rpcport,
parser_daemon.add_argument("--rpcsock",dest=SimpleConfig.RPC_SOCKET_TYPE.key(),default=None,help="what socket type to which to bind RPC daemon",choices=['unix','tcp','auto'])
parser_daemon.add_argument("--rpcsockpath",dest=SimpleConfig.RPC_SOCKET_FILEPATH.key(),help="where to place RPC file socket")
self._toolbar_checkbox=menu.addToggle(_("Filter by Date"),lambda:self.toggle_toolbar())
self.menu_fiat=menu.addConfig(_('Show Fiat Values'),'history_rates',False,callback=self.main_window.app.update_fiat_signal.emit)
self.menu_capgains=menu.addConfig(_('Show Capital Gains'),'history_rates_capital_gains',False,callback=self.main_window.app.update_fiat_signal.emit)
self.menu_fiat=menu.addConfig(_('Show Fiat Values'),config.cv.FX_HISTORY_RATES,callback=self.main_window.app.update_fiat_signal.emit)
self.menu_capgains=menu.addConfig(_('Show Capital Gains'),config.cv.FX_HISTORY_RATES_CAPITAL_GAINS,callback=self.main_window.app.update_fiat_signal.emit)