Since use of configuration files is both mmore secure and more
convenient and clap doesn't support config files, this switches to
configure_me, which supports config files, env vars and also generating
man pages.
Closes#151
ThemotivationbehindthisprojectistoenableausertorunhisownElectrumserver,withrequiredhardwareresourcesnotmuchbeyondthoseofafullnode.TheserverindexestheentireBitcoinblockchain,andtheresultingindexenablesfastqueriesforanygivenuserwallet,allowingtheusertokeepreal-timetrackofhisbalancesandhistransactionhistoryusingtheElectrumwallet.Sinceitrunsontheuser's own machine, there is no need for the wallet to communicate with external Electrum servers, thus preserving the privacy of the user'saddressesandbalances."""
[[switch]]
name="verbose"
abbr="v"
doc="Increase logging verbosity"
count=true
[[switch]]
name="timestamp"
doc="Prepend log lines with a timestamp"
[[param]]
name="db_dir"
type="std::path::PathBuf"
doc="Directory to store index database (default: ./db/)"
default="\"./db\".into()"
[[param]]
name="daemon_dir"
type="std::path::PathBuf"
doc="Data directory of Bitcoind (default: ~/.bitcoin/)"
default="crate::config::default_daemon_dir()"
[[param]]
name="cookie"
type="String"
doc="JSONRPC authentication cookie ('USER:PASSWORD', default: read from ~/.bitcoin/.cookie)"
# Force the user to use config file in order to avoid password leaks
doc="Select Bitcoin network type ('mainnet', 'testnet' or 'regtest')"
default="Default::default()"
[[param]]
name="electrum_rpc_addr"
type="crate::config::ResolvAddr"
convert_into="std::net::SocketAddr"
doc="Electrum server JSONRPC 'addr:port' to listen on (default: '127.0.0.1:50001' for mainnet, '127.0.0.1:60001' for testnet and '127.0.0.1:60401' for regtest)"
[[param]]
name="daemon_rpc_addr"
type="crate::config::ResolvAddr"
convert_into="std::net::SocketAddr"
doc="Bitcoin daemon JSONRPC 'addr:port' to connect (default: 127.0.0.1:8332 for mainnet, 127.0.0.1:18332 for testnet and 127.0.0.1:18443 for regtest)"
[[param]]
name="monitoring_addr"
type="crate::config::ResolvAddr"
convert_into="std::net::SocketAddr"
doc="Prometheus monitoring 'addr:port' to listen on (default: 127.0.0.1:4224 for mainnet, 127.0.0.1:14224 for testnet and 127.0.0.1:24224 for regtest)"
[[switch]]
name="jsonrpc_import"
doc="Use JSONRPC instead of directly importing blk*.dat files. Useful for remote full node or low memory system"
[[param]]
name="index_batch_size"
type="usize"
doc="Number of blocks to get in one JSONRPC request from bitcoind"
default="100"
[[param]]
name="bulk_index_threads"
type="usize"
doc="Number of threads used for bulk indexing (default: use the # of CPUs)"
default="0"
[[param]]
name="tx_cache_size"
type="usize"
doc="Number of transactions to keep in for query LRU cache"
default="10000"
[[param]]
name="blocktxids_cache_size"
type="usize"
doc="Number of blocks to cache transactions IDs in LRU cache"
default="100"
[[param]]
name="txid_limit"
type="usize"
doc="Number of transactions to lookup before returning an error, to prevent 'too popular' addresses from causing the RPC server to get stuck (0 - disable the limit)"
default="100"
[[param]]
name="server_banner"
type="String"
doc="The banner to be shown in the Electrum console"
default="concat!(\"Welcome to electrs \", env!(\"CARGO_PKG_VERSION\"), \" (Electrum Rust Server)!\").to_owned()"
.unwrap_or_else(|e|panic!("unable to resolve {} address: {}",what,e))
.next()
.unwrap_or_else(||panic!("no address found for {}",address))
fndefault_daemon_dir()-> PathBuf{
// TODO: would be better to avoid expect()
letmuthome=home_dir().expect("Unknown home directory");
home.push(".bitcoin");
home
}
implConfig{
pubfnfrom_args()-> Config{
letdefault_banner=format!(
"Welcome to electrs {} (Electrum Rust Server)!",
env!("CARGO_PKG_VERSION")
);
letm=App::new("Electrum Rust Server")
.version(crate_version!())
.arg(
Arg::with_name("verbosity")
.short("v")
.multiple(true)
.help("Increase logging verbosity"),
)
.arg(
Arg::with_name("timestamp")
.long("timestamp")
.help("Prepend log lines with a timestamp"),
)
.arg(
Arg::with_name("db_dir")
.long("db-dir")
.help("Directory to store index database (default: ./db/)")
.takes_value(true),
)
.arg(
Arg::with_name("daemon_dir")
.long("daemon-dir")
.help("Data directory of Bitcoind (default: ~/.bitcoin/)")
.takes_value(true),
)
.arg(
Arg::with_name("cookie")
.long("cookie")
.help("JSONRPC authentication cookie ('USER:PASSWORD', default: read from ~/.bitcoin/.cookie)")
.takes_value(true),
)
.arg(
Arg::with_name("network")
.long("network")
.help("Select Bitcoin network type ('mainnet', 'testnet' or 'regtest')")
.takes_value(true),
)
.arg(
Arg::with_name("electrum_rpc_addr")
.long("electrum-rpc-addr")
.help("Electrum server JSONRPC 'addr:port' to listen on (default: '127.0.0.1:50001' for mainnet, '127.0.0.1:60001' for testnet and '127.0.0.1:60401' for regtest)")
.takes_value(true),
)
.arg(
Arg::with_name("daemon_rpc_addr")
.long("daemon-rpc-addr")
.help("Bitcoin daemon JSONRPC 'addr:port' to connect (default: 127.0.0.1:8332 for mainnet, 127.0.0.1:18332 for testnet and 127.0.0.1:18443 for regtest)")
.takes_value(true),
)
.arg(
Arg::with_name("monitoring_addr")
.long("monitoring-addr")
.help("Prometheus monitoring 'addr:port' to listen on (default: 127.0.0.1:4224 for mainnet, 127.0.0.1:14224 for testnet and 127.0.0.1:24224 for regtest)")
.takes_value(true),
)
.arg(
Arg::with_name("jsonrpc_import")
.long("jsonrpc-import")
.help("Use JSONRPC instead of directly importing blk*.dat files. Useful for remote full node or low memory system"),
)
.arg(
Arg::with_name("index_batch_size")
.long("index-batch-size")
.help("Number of blocks to get in one JSONRPC request from bitcoind")
.default_value("100"),
)
.arg(
Arg::with_name("bulk_index_threads")
.long("bulk-index-threads")
.help("Number of threads used for bulk indexing (default: use the # of CPUs)")
.default_value("0")
)
.arg(
Arg::with_name("tx_cache_size")
.long("tx-cache-size")
.help("Number of transactions to keep in for query LRU cache")
.default_value("10000")// should be enough for a small wallet.
)
.arg(
Arg::with_name("blocktxids_cache_size")
.long("blocktxids-cache-size")
.help("Number of blocks to cache transactions IDs in LRU cache")
.default_value("100"))// Needs ~0.305MB per per block at 10k txs each
.arg(
Arg::with_name("txid_limit")
.long("txid-limit")
.help("Number of transactions to lookup before returning an error, to prevent \"too popular\" addresses from causing the RPC server to get stuck (0 - disable the limit)")
.default_value("100")// should take a few seconds on a HDD
)
.arg(
Arg::with_name("server_banner")
.long("server-banner")
.help("The banner to be shown in the Electrum console")