def options(func): """Having the common app options as a decorator facilitates reuse.""" # Until https://github.com/pallets/click/issues/926 is fixed the options need to be re-defined # for every use options_ = [ option( "--datadir", help="Directory for storing raiden data.", default=lambda: os.path.join(os.path.expanduser("~"), ".raiden"), type=click.Path( exists=False, dir_okay=True, file_okay=False, writable=True, resolve_path=True, allow_dash=False, ), show_default=True, ), option( "--config-file", help="Configuration file (TOML)", default=os.path.join("${datadir}", "config.toml"), type=PathRelativePath(file_okay=True, dir_okay=False, exists=False, readable=True, resolve_path=True), show_default=True, ), option( "--keystore-path", help= ("If you have a non-standard path for the ethereum keystore directory" " provide it using this argument."), default=None, type=click.Path(exists=True), show_default=True, ), option( "--address", help= ("The ethereum address you would like raiden to use and for which " "a keystore file exists in your local system."), default=None, type=ADDRESS_TYPE, show_default=True, ), option( "--password-file", help="Text file containing the password for the provided account", default=None, type=click.File(lazy=True), show_default=True, ), option( "--tokennetwork-registry-contract-address", help="hex encoded address of the Token Network Registry contract.", type=ADDRESS_TYPE, show_default=True, ), option( "--secret-registry-contract-address", help="hex encoded address of the Secret Registry contract.", type=ADDRESS_TYPE, show_default=True, ), option( "--service-registry-contract-address", help="hex encoded address of the Service Registry contract.", type=ADDRESS_TYPE, ), option( "--one-to-n-contract-address", help="hex encoded address of the OneToN contract.", type=ADDRESS_TYPE, ), option( "--endpoint-registry-contract-address", help="hex encoded address of the Endpoint Registry contract.", type=ADDRESS_TYPE, show_default=True, ), option( "--user-deposit-contract-address", help="hex encoded address of the User Deposit contract.", type=ADDRESS_TYPE, ), option("--console", help="Start the interactive raiden console", is_flag=True), option( "--transport", help="Transport system to use. UDP is not recommended", type=click.Choice(["udp", "matrix"]), default="matrix", show_default=True, ), option( "--network-id", help= ("Specify the network name/id of the Ethereum network to run Raiden on.\n" "Available networks:\n" '"mainnet" - network id: 1\n' '"ropsten" - network id: 3\n' '"rinkeby" - network id: 4\n' '"goerli" - network id: 5\n' '"kovan" - network id: 42\n' '"<NETWORK_ID>": use the given network id directly\n'), type=NetworkChoiceType([ "mainnet", "ropsten", "rinkeby", "goerli", "kovan", "<NETWORK_ID>" ]), default="mainnet", show_default=True, ), option( "--environment-type", help= ("Specify the environment (production or development).\n" 'The "production" setting adds some safety measures and is mainly intended ' "for running Raiden on the mainnet.\n"), type=EnumChoiceType(Environment), default=Environment.PRODUCTION.value, show_default=True, ), option( "--accept-disclaimer", help="Bypass the experimental software disclaimer prompt", is_flag=True, ), option( "--showconfig", help= "Show all configuration values used to control Raiden's behavior", is_flag=True, ), option_group( "Ethereum Node Options", option( "--sync-check/--no-sync-check", help= "Checks if the ethereum node is synchronized against etherscan.", default=True, show_default=True, ), option( "--gas-price", help= ("Set the gas price for ethereum transactions. If not provided " "the normal gas price startegy is used.\n" "Available options:\n" '"fast" - transactions are usually mined within 60 seconds\n' '"normal" - transactions are usually mined within 5 minutes\n' "<GAS_PRICE> - use given gas price\n"), type=GasPriceChoiceType(["normal", "fast"]), default="fast", show_default=True, ), option( "--eth-rpc-endpoint", help= ('"host:port" address of ethereum JSON-RPC server.\n' "Also accepts a protocol prefix (http:// or https://) with optional port" ), default="http://127.0.0.1:8545", # geth default jsonrpc port type=str, show_default=True, ), ), option_group( "Raiden Services Options", option( "--routing-mode", help=("Specify the routing mode to be used.\n" '"basic": use local routing\n' '"pfs": use the path finding service\n'), type=EnumChoiceType(RoutingMode), default=RoutingMode.BASIC.value, show_default=True, ), option( "--pathfinding-service-address", help= ("URL to the Raiden path finding service to request paths from.\n" "Example: https://pfs-ropsten.services-dev.raiden.network\n" 'Can also be given the "auto" value so that raiden chooses a ' "PFS randomly from the service registry contract"), default="auto", type=str, show_default=True, ), option( "--pathfinding-max-paths", help= "Set maximum number of paths to be requested from the path finding service.", default=DEFAULT_PATHFINDING_MAX_PATHS, type=int, show_default=True, ), option( "--pathfinding-max-fee", help= "Set max fee per request paid to the path finding service.", default=DEFAULT_PATHFINDING_MAX_FEE, type=int, show_default=True, ), option( "--pathfinding-iou-timeout", help= "Number of blocks before a new IOU to the path finding service expires.", default=DEFAULT_PATHFINDING_IOU_TIMEOUT, type=int, show_default=True, ), option( "--enable-monitoring", help= "Enable broadcasting of balance proofs to the monitoring services.", is_flag=True, ), ), option_group( "UDP Transport Options", option( "--listen-address", help='"host:port" for the raiden service to listen on.', default="0.0.0.0:{}".format(INITIAL_PORT), type=str, show_default=True, ), option( "--max-unresponsive-time", help= ("Max time in seconds for which an address can send no packets and " "still be considered healthy."), default=30, type=int, show_default=True, ), option( "--send-ping-time", help= ("Time in seconds after which if we have received no message from a " "node we have a connection with, we are going to send a PING message" ), default=60, type=int, show_default=True, ), option( "--nat", help= ("Manually specify method to use for determining public IP / NAT traversal.\n" "Available methods:\n" '"auto" - Try UPnP, then STUN, fallback to none\n' '"upnp" - Try UPnP, fallback to none\n' '"stun" - Try STUN, fallback to none\n' '"none" - Use the local interface address ' "(this will likely cause connectivity issues)\n" '"ext:<IP>[:<PORT>]" - manually specify the external IP (and optionally port ' "number)"), type=NATChoiceType( ["auto", "upnp", "stun", "none", "ext:<IP>[:<PORT>]"]), default="auto", show_default=True, option_group="udp_transport", ), ), option_group( "Matrix Transport Options", option( "--matrix-server", help=("Matrix homeserver to use for communication.\n" "Valid values:\n" '"auto" - automatically select a suitable homeserver\n' "A URL pointing to a Raiden matrix homeserver"), default="auto", type=MatrixServerType(["auto", "<url>"]), show_default=True, ), ), option_group( "Logging Options", option( "--log-config", help="Log level configuration.\n" "Format: [<logger-name-1>]:<level>[,<logger-name-2>:level][,...]", type=LOG_LEVEL_CONFIG_TYPE, default=":info", show_default=True, ), option( "--log-file", help="file path for logging to file", default=None, type=str, show_default=True, ), option("--log-json", help="Output log lines in JSON format", is_flag=True), option( "--disable-debug-logfile", help=( "Disable the debug logfile feature. This is independent of " "the normal logging setup"), is_flag=True, ), ), option_group( "RPC Options", option( "--rpc/--no-rpc", help="Start with or without the RPC server.", default=True, show_default=True, ), option( "--api-address", help='"host:port" for the RPC server to listen on.', default="127.0.0.1:5001", type=str, show_default=True, ), option( "--web-ui/--no-web-ui", help=( "Start with or without the web interface. Requires --rpc. " "It will be accessible at http://<api-address>. "), default=True, show_default=True, ), ), option_group( 'RNS options', option( '--rnsdomain', help='Node RNS domain name.', type=str, show_default=True, ), ), option_group( 'Lumino explorer options', option( '--discoverable', help= 'If specified then the node will be registered on Lumino Explorer.', is_flag=True, default=False, ), option( '--explorer-endpoint', help= 'The url to register node and indicate alive signal to the explorer api', type=str, default="https://api.lumino.rifos.org/lumino-explorer-1.0/", ), ), option_group( 'Debugging options', option( "--unrecoverable-error-should-crash", help= ("DO NOT use, unless you know what you are doing. If provided " "along with a production environment setting then all " "unrecoverable errors will lead to a crash and not simply get logged." ), is_flag=True, default=False, ), ), option_group( "Hash Resolver options", option( "--resolver-endpoint", help= ("URL of the resolver server that is used to resolve " "a payment hash to a secret. " "Accepts a protocol prefix (http:// or https://) with optional port" ), default=None, type=str, show_default=True, ), ), ] for option_ in reversed(options_): func = option_(func) return func
@run.command() @option("--short", is_flag=True, help="Only display Raiden version") def version(short): """Print version information and exit. """ if short: print(get_system_spec()["raiden"]) else: print(json.dumps(get_system_spec(), indent=2)) @run.command() @option("--debug", is_flag=True, help="Drop into pdb on errors.") @option( "--eth-client", type=EnumChoiceType(EthClient), default=EthClient.GETH.value, show_default=True, help="Which Ethereum client to run for the smoketests", ) @click.pass_context def smoketest(ctx, debug, eth_client): """ Test, that the raiden installation is sane. """ from raiden.tests.utils.smoketest import setup_testchain_and_raiden, run_smoketest from raiden.tests.utils.transport import make_requests_insecure, matrix_server_starter report_file = mktemp(suffix=".log") configure_logging( logger_level_config={"": "DEBUG"}, log_file=report_file, disable_debug_logfile=ctx.parent.params["disable_debug_logfile"],
def options(func: Callable) -> Callable: """Having the common app options as a decorator facilitates reuse.""" # Until https://github.com/pallets/click/issues/926 is fixed the options need to be re-defined # for every use options_ = [ option("--version", hidden=True, is_flag=True, allow_from_autoenv=False), option( "--datadir", help="Directory for storing raiden data.", default=lambda: os.path.join(os.path.expanduser("~"), ".raiden"), type=click.Path( exists=False, dir_okay=True, file_okay=False, writable=True, resolve_path=True, allow_dash=False, ), show_default=True, ), option( "--config-file", help="Configuration file (TOML)", default=os.path.join("${datadir}", "config.toml"), type=PathRelativePath( file_okay=True, dir_okay=False, exists=False, readable=True, resolve_path=True ), show_default=True, ), option( "--keystore-path", help=( "If you have a non-standard path for the ethereum keystore directory" " provide it using this argument." ), default=None, type=click.Path(exists=True), show_default=True, ), option( "--address", help=( "The ethereum address you would like raiden to use and for which " "a keystore file exists in your local system." ), default=None, type=ADDRESS_TYPE, show_default=True, ), option( "--password-file", help="Text file containing the password for the provided account", default=None, type=click.File(lazy=True), show_default=True, ), option( "--user-deposit-contract-address", help="hex encoded address of the User Deposit contract.", type=ADDRESS_TYPE, ), option("--console", help="Start the interactive raiden console", is_flag=True), option( "--transport", help="Transport system to use.", type=click.Choice(["matrix"]), default="matrix", show_default=True, hidden=True, ), option( ETH_NETWORKID_OPTION, help=( "Specify the network name/id of the Ethereum network to run Raiden on.\n" "Available networks:\n" '"mainnet" - network id: 1\n' '"ropsten" - network id: 3\n' '"rinkeby" - network id: 4\n' '"goerli" - network id: 5\n' '"kovan" - network id: 42\n' '"<NETWORK_ID>": use the given network id directly\n' ), type=NetworkChoiceType( ["mainnet", "ropsten", "rinkeby", "goerli", "kovan", "<NETWORK_ID>"] ), default="mainnet", show_default=True, ), option( "--environment-type", help=( "Specify the environment (production or development).\n" 'The "production" setting adds some safety measures and is mainly intended ' "for running Raiden on the mainnet.\n" ), type=EnumChoiceType(Environment), default=Environment.PRODUCTION.value, show_default=True, ), option( "--accept-disclaimer", help="Bypass the experimental software disclaimer prompt", is_flag=True, ), option( "--showconfig", help="Show all configuration values used to control Raiden's behavior", is_flag=True, ), option( "--blockchain-query-interval", help="Time interval after which to check for new blocks (in seconds)", default=DEFAULT_BLOCKCHAIN_QUERY_INTERVAL, show_default=True, type=click.FloatRange(min=0.1), ), option_group( "Channel-specific Options", option( "--default-reveal-timeout", help="Sets the default reveal timeout to be used to newly created channels", default=DEFAULT_REVEAL_TIMEOUT, show_default=True, type=click.IntRange(min=20), ), option( "--default-settle-timeout", help="Sets the default settle timeout to be used to newly created channels", default=DEFAULT_SETTLE_TIMEOUT, show_default=True, type=click.IntRange(min=20), ), ), option_group( "Ethereum Node Options", option( "--sync-check/--no-sync-check", help="Checks if the ethereum node is synchronized against etherscan.", default=True, show_default=True, ), option( "--gas-price", help=( "Set the gas price for ethereum transactions. If not provided " "the normal gas price startegy is used.\n" "Available options:\n" '"fast" - transactions are usually mined within 60 seconds\n' '"normal" - transactions are usually mined within 5 minutes\n' "<GAS_PRICE> - use given gas price\n" ), type=GasPriceChoiceType(["normal", "fast"]), default="fast", show_default=True, ), option( ETH_RPC_CONFIG_OPTION, help=( '"host:port" address of ethereum JSON-RPC server.\n' "Also accepts a protocol prefix (http:// or https://) with optional port" ), default="http://127.0.0.1:8545", # geth default jsonrpc port type=str, show_default=True, ), ), option_group( "Raiden Services Options", option( "--routing-mode", help=( "Specify the routing mode to be used.\n" '"pfs": use the path finding service\n' '"local": use local routing, but send updates to the PFS\n' '"private": use local routing and don\'t send updates to the PFS\n' ), type=EnumChoiceType(RoutingMode), default=RoutingMode.PFS.value, show_default=True, ), option( "--pathfinding-service-address", help=( "URL to the Raiden path finding service to request paths from.\n" "Example: https://pfs-ropsten.services-dev.raiden.network\n" 'Can also be given the "auto" value so that raiden chooses a ' "PFS randomly from the service registry contract" ), default="auto", type=str, show_default=True, ), option( "--pathfinding-max-paths", help="Set maximum number of paths to be requested from the path finding service.", default=DEFAULT_PATHFINDING_MAX_PATHS, type=int, show_default=True, ), option( "--pathfinding-max-fee", help="Set max fee per request paid to the path finding service.", default=DEFAULT_PATHFINDING_MAX_FEE, type=int, show_default=True, ), option( "--pathfinding-iou-timeout", help="Number of blocks before a new IOU to the path finding service expires.", default=DEFAULT_PATHFINDING_IOU_TIMEOUT, type=int, show_default=True, ), option( "--enable-monitoring", help="Enable broadcasting of balance proofs to the monitoring services.", default=False, is_flag=True, ), ), option_group( "Matrix Transport Options", option( "--matrix-server", help=( "Matrix homeserver to use for communication.\n" "Valid values:\n" '"auto" - automatically select a suitable homeserver\n' "A URL pointing to a Raiden matrix homeserver" ), default="auto", type=MatrixServerType(["auto", "<url>"]), show_default=True, ), ), option_group( "Logging Options", option( "--log-config", help="Log level configuration.\n" "Format: [<logger-name-1>]:<level>[,<logger-name-2>:level][,...]", type=LOG_LEVEL_CONFIG_TYPE, default=":info", show_default=True, ), option( "--log-file", help="file path for logging to file", default=None, type=click.Path(dir_okay=False, writable=True, resolve_path=True), show_default=True, ), option("--log-json", help="Output log lines in JSON format", is_flag=True), option( "--debug-logfile-path", help=( "The absolute path to the debug logfile. If not given defaults to:\n" " - OSX: ~/Library/Logs/Raiden/raiden_debug_XXX.log\n" " - Windows: ~/Appdata/Roaming/Raiden/raiden_debug_XXX.log\n" " - Linux: ~/.raiden/raiden_debug_XXX.log\n" "\nIf there is a problem with expanding home it is placed under /tmp" ), type=click.Path(dir_okay=False, writable=True, resolve_path=True), ), option( "--disable-debug-logfile", help=( "Disable the debug logfile feature. This is independent of " "the normal logging setup" ), is_flag=True, ), ), option_group( "RPC Options", option( "--rpc/--no-rpc", help="Start with or without the RPC server.", default=True, show_default=True, ), option( "--rpccorsdomain", help="Comma separated list of domains to accept cross origin requests.", default="http://localhost:*/*", type=str, show_default=True, ), option( "--api-address", help='"host:port" for the RPC server to listen on.', default=f"127.0.0.1:{DEFAULT_HTTP_SERVER_PORT}", type=str, show_default=True, ), option( "--web-ui/--no-web-ui", help=( "Start with or without the web interface. Requires --rpc. " "It will be accessible at http://<api-address>. " ), default=True, show_default=True, ), ), option_group( "Debugging options", option( "--flamegraph", help=("Directory to save stack data used to produce flame graphs."), type=click.Path( exists=False, dir_okay=True, file_okay=False, writable=True, resolve_path=True, allow_dash=False, ), default=None, ), option("--switch-tracing", help="Enable switch tracing", is_flag=True, default=False), option( "--unrecoverable-error-should-crash", help=( "DO NOT use, unless you know what you are doing. If provided " "along with a production environment setting then all " "unrecoverable errors will lead to a crash and not simply get logged." ), is_flag=True, default=False, ), option( "--log-memory-usage-interval", help="Log memory usage every X sec (fractions accepted). [default: disabled]", type=float, default=0, ), ), option_group( "Hash Resolver Options", option( "--resolver-endpoint", help=( "URL of the resolver server that is used to resolve " "a payment hash to a secret. " "Accepts a protocol prefix (http:// or https://) with optional port" ), default=None, type=str, show_default=True, ), ), option_group( "Mediation Fee Options", option( "--flat-fee", help=( "Sets the flat fee required for every mediation in wei of the " "mediated token for a certain token address. Must be bigger " f"or equal to {FLAT_MED_FEE_MIN}." ), type=(ADDRESS_TYPE, click.IntRange(min=FLAT_MED_FEE_MIN)), multiple=True, ), option( "--proportional-fee", help=( "Mediation fee as ratio of mediated amount in parts-per-million " "(10^-6) for a certain token address. " f"Must be in [{PROPORTIONAL_MED_FEE_MIN}, {PROPORTIONAL_MED_FEE_MAX}]." ), type=( ADDRESS_TYPE, click.IntRange(min=PROPORTIONAL_MED_FEE_MIN, max=PROPORTIONAL_MED_FEE_MAX), ), multiple=True, ), option( "--proportional-imbalance-fee", help=( "Set the worst-case imbalance fee relative to the channels capacity " "in parts-per-million (10^-6) for a certain token address. " f"Must be in [{IMBALANCE_MED_FEE_MIN}, {IMBALANCE_MED_FEE_MAX}]." ), type=( ADDRESS_TYPE, click.IntRange(min=IMBALANCE_MED_FEE_MIN, max=IMBALANCE_MED_FEE_MAX), ), multiple=True, ), option( "--cap-mediation-fees/--no-cap-mediation-fees", help="Cap the mediation fees to never get negative.", default=True, show_default=True, ), ), ] for option_ in reversed(options_): func = option_(func) return func
if ctx.invoked_subcommand: ctx.obj = dict(chain_rpc_urls=chain_rpc_urls, data_path=Path(data_path)) @main.command(name="run") @click.argument("scenario-file", type=click.File(), required=False) @click.option("--keystore-file", required=True, type=click.Path(exists=True, dir_okay=False)) @click.password_option("--password", envvar="ACCOUNT_PASSWORD", required=True) @click.option("--auth", default="") @click.option("--mailgun-api-key") @click.option( "--notify-tasks", type=EnumChoiceType(TaskNotifyType), default=TaskNotifyType.NONE.value, help="Notify of task status via chosen method.", ) @click.option( "--ui/--no-ui", "enable_ui", default=sys.stdout.isatty(), help="En-/disable console UI. [default: auto-detect]", ) @click.pass_context def run(ctx, mailgun_api_key, auth, password, keystore_file, scenario_file, notify_tasks, enable_ui): scenario_file = Path(scenario_file.name).absolute() data_path = ctx.obj["data_path"] chain_rpc_urls = ctx.obj["chain_rpc_urls"]
def options(func): """Having the common app options as a decorator facilitates reuse.""" # Until https://github.com/pallets/click/issues/926 is fixed the options need to be re-defined # for every use options_ = [ option( '--datadir', help='Directory for storing raiden data.', default=lambda: os.path.join(os.path.expanduser('~'), '.raiden'), type=click.Path( exists=False, dir_okay=True, file_okay=False, writable=True, resolve_path=True, allow_dash=False, ), show_default=True, ), option( '--config-file', help='Configuration file (TOML)', default=os.path.join('${datadir}', 'config.toml'), type=PathRelativePath( file_okay=True, dir_okay=False, exists=False, readable=True, resolve_path=True, ), show_default=True, ), option( '--keystore-path', help= ('If you have a non-standard path for the ethereum keystore directory' ' provide it using this argument.'), default=None, type=click.Path(exists=True), show_default=True, ), option( '--address', help= ('The ethereum address you would like raiden to use and for which ' 'a keystore file exists in your local system.'), default=None, type=ADDRESS_TYPE, show_default=True, ), option( '--password-file', help='Text file containing the password for the provided account', default=None, type=click.File(lazy=True), show_default=True, ), option( '--tokennetwork-registry-contract-address', help='hex encoded address of the Token Network Registry contract.', type=ADDRESS_TYPE, show_default=True, ), option( '--secret-registry-contract-address', help='hex encoded address of the Secret Registry contract.', type=ADDRESS_TYPE, show_default=True, ), option( '--service-registry-contract-address', help='hex encoded address of the Service Registry contract.', type=ADDRESS_TYPE, ), option( '--endpoint-registry-contract-address', help='hex encoded address of the Endpoint Registry contract.', type=ADDRESS_TYPE, show_default=True, ), option( '--user-deposit-contract-address', help='hex encoded address of the User Deposit contract.', type=ADDRESS_TYPE, ), option( '--console', help='Start the interactive raiden console', is_flag=True, ), option( '--transport', help='Transport system to use. UDP is not recommended', type=click.Choice(['udp', 'matrix']), default='matrix', show_default=True, ), option( '--network-id', help= ('Specify the network name/id of the Ethereum network to run Raiden on.\n' 'Available networks:\n' '"mainnet" - network id: 1\n' '"ropsten" - network id: 3\n' '"rinkeby" - network id: 4\n' '"goerli" - network id: 5\n' '"kovan" - network id: 42\n' '"<NETWORK_ID>": use the given network id directly\n'), type=NetworkChoiceType([ 'mainnet', 'ropsten', 'rinkeby', 'goerli', 'kovan', '<NETWORK_ID>', ]), default='mainnet', show_default=True, ), option( '--environment-type', help= ('Specify the environment (production or development).\n' 'The "production" setting adds some safety measures and is mainly intended ' 'for running Raiden on the mainnet.\n'), type=EnumChoiceType(Environment), default=Environment.PRODUCTION.value, show_default=True, ), option( '--accept-disclaimer', help='Bypass the experimental software disclaimer prompt', is_flag=True, ), option( '--showconfig', help= 'Show all configuration values used to control Raiden\'s behavior', is_flag=True, ), option_group( 'Ethereum Node Options', option( '--sync-check/--no-sync-check', help= 'Checks if the ethereum node is synchronized against etherscan.', default=True, show_default=True, ), option( '--gas-price', help= ('Set the gas price for ethereum transactions. If not provided ' 'the normal gas price startegy is used.\n' 'Available options:\n' '"fast" - transactions are usually mined within 60 seconds\n' '"normal" - transactions are usually mined within 5 minutes\n' '<GAS_PRICE> - use given gas price\n'), type=GasPriceChoiceType(['normal', 'fast']), default='fast', show_default=True, ), option( '--eth-rpc-endpoint', help= ('"host:port" address of ethereum JSON-RPC server.\n' 'Also accepts a protocol prefix (http:// or https://) with optional port' ), default='http://127.0.0.1:8545', # geth default jsonrpc port type=str, show_default=True, ), ), option_group( 'Raiden Services Options', option( '--routing-mode', help=('Specify the routing mode to be used.\n' '"basic": use local routing\n' '"pfs": use the path finding service\n'), type=EnumChoiceType(RoutingMode), default=RoutingMode.BASIC.value, show_default=True, ), option( '--pathfinding-service-address', help= ('URL to the Raiden path finding service to request paths from.\n' 'Example: https://pfs-ropsten.services-dev.raiden.network\n' 'Can also be given the "auto" value so that raiden chooses a ' 'PFS randomly from the service registry contract'), default='auto', type=str, show_default=True, ), option( '--pathfinding-eth-address', help= ('Ethereum address to which to pay the fees of the path finding service.\n' 'If the path finding service is chosen from the service registry contract, ' 'this option will be ignored. If the path finding service is configured ' 'manually, i. e. "--pathfinding-service-address" set to a value other than ' '"auto", this argument must be set to a valid EIP55 address.' ), type=str, ), option( '--pathfinding-max-paths', help= 'Set maximum number of paths to be requested from the path finding service.', default=DEFAULT_PATHFINDING_MAX_PATHS, type=int, show_default=True, ), option( '--pathfinding-max-fee', help= 'Set max fee per request paid to the path finding service.', default=DEFAULT_PATHFINDING_MAX_FEE, type=int, show_default=True, ), option( '--pathfinding-iou-timeout', help= 'Number of blocks before a new IOU to the path finding service expires.', default=DEFAULT_PATHFINDING_IOU_TIMEOUT, type=int, show_default=True, ), option( '--enable-monitoring', help= 'Enable broadcasting of balance proofs to the monitoring services.', is_flag=True, ), ), option_group( 'UDP Transport Options', option( '--listen-address', help='"host:port" for the raiden service to listen on.', default='0.0.0.0:{}'.format(INITIAL_PORT), type=str, show_default=True, ), option( '--max-unresponsive-time', help= ('Max time in seconds for which an address can send no packets and ' 'still be considered healthy.'), default=30, type=int, show_default=True, ), option( '--send-ping-time', help= ('Time in seconds after which if we have received no message from a ' 'node we have a connection with, we are going to send a PING message' ), default=60, type=int, show_default=True, ), option( '--nat', help= ('Manually specify method to use for determining public IP / NAT traversal.\n' 'Available methods:\n' '"auto" - Try UPnP, then STUN, fallback to none\n' '"upnp" - Try UPnP, fallback to none\n' '"stun" - Try STUN, fallback to none\n' '"none" - Use the local interface address ' '(this will likely cause connectivity issues)\n' '"ext:<IP>[:<PORT>]" - manually specify the external IP (and optionally port ' 'number)'), type=NATChoiceType( ['auto', 'upnp', 'stun', 'none', 'ext:<IP>[:<PORT>]']), default='auto', show_default=True, option_group='udp_transport', ), ), option_group( 'Matrix Transport Options', option( '--matrix-server', help=('Matrix homeserver to use for communication.\n' 'Valid values:\n' '"auto" - automatically select a suitable homeserver\n' 'A URL pointing to a Raiden matrix homeserver'), default='auto', type=MatrixServerType(['auto', '<url>']), show_default=True, ), ), option_group( 'Logging Options', option( '--log-config', help='Log level configuration.\n' 'Format: [<logger-name-1>]:<level>[,<logger-name-2>:level][,...]', type=LOG_LEVEL_CONFIG_TYPE, default=':info', show_default=True, ), option( '--log-file', help='file path for logging to file', default=None, type=str, show_default=True, ), option( '--log-json', help='Output log lines in JSON format', is_flag=True, ), option( '--disable-debug-logfile', help=( 'Disable the debug logfile feature. This is independent of ' 'the normal logging setup'), is_flag=True, ), ), option_group( 'RPC Options', option( '--rpc/--no-rpc', help='Start with or without the RPC server.', default=True, show_default=True, ), option( '--rpccorsdomain', help= 'Comma separated list of domains to accept cross origin requests.', default='http://localhost:*/*', type=str, show_default=True, ), option( '--api-address', help='"host:port" for the RPC server to listen on.', default='127.0.0.1:5001', type=str, show_default=True, ), option( '--web-ui/--no-web-ui', help=( 'Start with or without the web interface. Requires --rpc. ' 'It will be accessible at http://<api-address>. '), default=True, show_default=True, ), ), option_group( 'Debugging options', option( '--unrecoverable-error-should-crash', help= ('DO NOT use, unless you know what you are doing. If provided ' 'along with a production environment setting then all ' 'unrecoverable errors will lead to a crash and not simply get logged.' ), is_flag=True, default=False, ), ), ] for option_ in reversed(options_): func = option_(func) return func
def blockchain_options(contracts: List[str]) -> Callable: """A decorator providing blockchain related params to a command""" options = [ click.Option(["--eth-rpc"], default="http://localhost:8545", type=str, help="Ethereum node RPC URI"), click.Option( ["--gas-price"], help=( "Set the gas price for ethereum transactions. If not provided " "the 'normal' gas price startegy is used.\n" "Available options:\n" '"fast" - transactions are usually mined within 60 seconds\n' '"normal" - transactions are usually mined within 5 minutes\n' "<GAS_PRICE> - use given gas price\n"), type=GasPriceChoiceType(["normal", "fast"]), default="fast", show_default=True, ), click.Option( ["--development-environment"], help= ("Choose which set of services and transport servers should be used. " "Change this only when you are developing Raiden itself."), type=EnumChoiceType(ContractDevEnvironment), default=ContractDevEnvironment.DEMO.value, ), ] arg_for_contract = { CONTRACT_TOKEN_NETWORK_REGISTRY: "token-network-registry-contract", CONTRACT_USER_DEPOSIT: "user-deposit-contract", CONTRACT_MONITORING_SERVICE: "monitor-contract", CONTRACT_ONE_TO_N: "one-to-n-contract", CONTRACT_SERVICE_REGISTRY: "service-registry-contract", CONTRACT_DEPOSIT: "service-deposit-contract", } address_required = {CONTRACT_DEPOSIT} param_for_contract: Dict[str, str] = {} for con in contracts: option = click.Option( ["--{}-address".format(arg_for_contract[con])], type=str, help=f"Address of the {con} contract", callback=validate_address, required=con in address_required, ) options.append(option) param_for_contract[con] = option.human_readable_name def decorator(command: click.Command) -> click.Command: assert command.callback callback = command.callback command.params += options def call_with_blockchain_info(**params: Any) -> Callable: address_overwrites = { contract: value for contract, value in ( (contract, params.pop(param)) for contract, param in param_for_contract.items()) if value is not None } params["web3"], params["contracts"], params[ "start_block"] = connect_to_blockchain( eth_rpc=params.pop("eth_rpc"), gas_price_strategy=params.pop("gas_price"), used_contracts=contracts, address_overwrites=address_overwrites, development_environment=params.pop( "development_environment"), ) return callback(**params) command.callback = call_with_blockchain_info return command return decorator