From 9aa4136ebc2f545b9314b414eb32c447249b4344 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Tue, 17 Aug 2021 21:17:23 +0300 Subject: [PATCH] DEX-1344 Prepare release 2.3.5 - CLI fixes (#620) --- dex/src/main/resources/application.conf | 8 +- .../wavesplatform/dex/cli/WavesDexCli.scala | 76 +++++++++++-------- .../dex/settings/CliSettings.scala | 39 ++++------ 3 files changed, 62 insertions(+), 61 deletions(-) diff --git a/dex/src/main/resources/application.conf b/dex/src/main/resources/application.conf index 242b1c3976..700fa8b22e 100644 --- a/dex/src/main/resources/application.conf +++ b/dex/src/main/resources/application.conf @@ -20,7 +20,7 @@ waves.dex { # An account storage account-storage { - type = "not-specified" # "in-mem" or "encrypted-file" + type = "in-mem" # "in-mem" or "encrypted-file" in-mem.seed-in-base-64 = "" encrypted-file { @@ -740,11 +740,11 @@ waves.dex.cli { "events-queue.kafka.group" ] - args-overrides { + default-args { address-scheme-byte = ${waves.dex.address-scheme-character} dex-rest-api = ${waves.dex.rest-api.address}":"${waves.dex.rest-api.port} - node-rest-api = "" - auth-service-rest-api = "" + node-rest-api = null // string + auth-service-rest-api = null // string timeout = 30 seconds } } diff --git a/dex/src/main/scala/com/wavesplatform/dex/cli/WavesDexCli.scala b/dex/src/main/scala/com/wavesplatform/dex/cli/WavesDexCli.scala index 2db825bdf2..88fee9ef03 100644 --- a/dex/src/main/scala/com/wavesplatform/dex/cli/WavesDexCli.scala +++ b/dex/src/main/scala/com/wavesplatform/dex/cli/WavesDexCli.scala @@ -4,12 +4,12 @@ import cats.Id import cats.instances.either._ import cats.syntax.either._ import cats.syntax.option._ -import com.typesafe.config.Config import com.typesafe.config.ConfigFactory.parseFile +import com.typesafe.config.{Config, ConfigFactory} import com.wavesplatform.dex._ import com.wavesplatform.dex.app.{forceStopApplication, MatcherStateCheckingFailedError} -import com.wavesplatform.dex.db.leveldb.{openDb, LevelDb} import com.wavesplatform.dex.db._ +import com.wavesplatform.dex.db.leveldb.{openDb, LevelDb} import com.wavesplatform.dex.doc.MatcherErrorDoc import com.wavesplatform.dex.domain.account.{AddressScheme, KeyPair} import com.wavesplatform.dex.domain.asset.Asset.IssuedAsset @@ -434,6 +434,11 @@ object WavesDexCli extends ScoptImplicits { .text("The network byte as char. By default it is the testnet: 'T'") .valueName("") .action((x, s) => s.copy(addressSchemeByte = x.some)), + opt[String]("dex-config") + .abbr("dc") + .text("DEX config path") + .valueName("") + .action((x, s) => s.copy(configPath = x)), cmd(Command.GenerateAccountSeed.name) .action((_, s) => s.copy(command = Command.GenerateAccountSeed.some)) .text("Generates an account seed from base seed and nonce") @@ -714,35 +719,44 @@ object WavesDexCli extends ScoptImplicits { }.fold(error => throw new RuntimeException(error), identity) // noinspection ScalaStyle - OParser.parse(parser, rawArgs, Args()).foreach { args => - lazy val (config, matcherSettings) = loadAllConfigsUnsafe(args.configPath) - val argsOverrides = matcherSettings.cli.argsOverrides - val updatedArgs = argsOverrides.updateArgs(args) - updatedArgs.command match { - case None => println(OParser.usage(parser, RenderingMode.TwoColumns)) - case Some(command) => - println(s"Running '${command.name}' command") - AddressScheme.current = new AddressScheme { override val chainId: Byte = updatedArgs.addressSchemeByte.getOrElse('T').toByte } - command match { - case Command.GenerateAccountSeed => generateAccountSeed(updatedArgs) - case Command.CreateAccountStorage => createAccountStorage(updatedArgs) - case Command.CreateDocumentation => createDocumentation(updatedArgs) - case Command.CreateApiKey => createApiKey(updatedArgs) - case Command.CheckServer => checkServer(updatedArgs, config, matcherSettings) - case Command.RunComparison => runComparison(updatedArgs) - case Command.MakeOrderbookSnapshots => makeSnapshots(updatedArgs) - case Command.CheckConfigFile => checkConfig(updatedArgs) - case Command.CleanAssets => cleanAssets(updatedArgs, matcherSettings) - case Command.InspectAsset => inspectAsset(updatedArgs, matcherSettings) - case Command.SetAsset => setAsset(updatedArgs, matcherSettings) - case Command.ListAssetPairs => listAssetPairs(updatedArgs, matcherSettings) - case Command.InspectOrderBook => inspectOrderBook(updatedArgs, matcherSettings) - case Command.DeleteOrderBook => deleteOrderBook(updatedArgs, matcherSettings) - case Command.InspectOrder => inspectOrder(updatedArgs, matcherSettings) - } - println("Done") + OParser.parse(parser, rawArgs, Args()) + .map { args => + args.configPath match { + case "" => (args, ConfigFactory.empty(), none[MatcherSettings]) + case configPath => + lazy val (config, matcherSettings) = loadAllConfigsUnsafe(configPath) + val updatedArgs = matcherSettings.cli.defaultArgs.coverEmptyValues(args) + (updatedArgs, config, matcherSettings.some) + } + } + .foreach { case (args, config, mayBeMatcherSettings) => + lazy val matcherSettings = mayBeMatcherSettings.getOrElse(throw new RuntimeException("config-path is required")) + args.command match { + case None => println(OParser.usage(parser, RenderingMode.TwoColumns)) + case Some(command) => + println(s"Running '${command.name}' command") + AddressScheme.current = new AddressScheme { override val chainId: Byte = args.addressSchemeByte.getOrElse('T').toByte } + println(s"Current chain id: ${AddressScheme.current.chainId.toChar}") + command match { + case Command.GenerateAccountSeed => generateAccountSeed(args) + case Command.CreateAccountStorage => createAccountStorage(args) + case Command.CreateDocumentation => createDocumentation(args) + case Command.CreateApiKey => createApiKey(args) + case Command.CheckServer => checkServer(args, config, matcherSettings) + case Command.RunComparison => runComparison(args) + case Command.MakeOrderbookSnapshots => makeSnapshots(args) + case Command.CheckConfigFile => checkConfig(args) + case Command.CleanAssets => cleanAssets(args, matcherSettings) + case Command.InspectAsset => inspectAsset(args, matcherSettings) + case Command.SetAsset => setAsset(args, matcherSettings) + case Command.ListAssetPairs => listAssetPairs(args, matcherSettings) + case Command.InspectOrderBook => inspectOrderBook(args, matcherSettings) + case Command.DeleteOrderBook => deleteOrderBook(args, matcherSettings) + case Command.InspectOrder => inspectOrder(args, matcherSettings) + } + println("Done") + } } - } } sealed trait Command { @@ -852,7 +866,7 @@ object WavesDexCli extends ScoptImplicits { orderId: String = "", authServiceRestApi: Option[String] = None, accountSeed: Option[String] = None, - timeout: FiniteDuration = 30 seconds + timeout: FiniteDuration = 0 seconds ) // noinspection ScalaStyle diff --git a/dex/src/main/scala/com/wavesplatform/dex/settings/CliSettings.scala b/dex/src/main/scala/com/wavesplatform/dex/settings/CliSettings.scala index 4ece1d6829..142a2896cd 100644 --- a/dex/src/main/scala/com/wavesplatform/dex/settings/CliSettings.scala +++ b/dex/src/main/scala/com/wavesplatform/dex/settings/CliSettings.scala @@ -1,46 +1,33 @@ package com.wavesplatform.dex.settings +import cats.syntax.option._ import com.wavesplatform.dex.cli.WavesDexCli.Args import scala.concurrent.duration.FiniteDuration -import scala.util.chaining._ final case class CliSettings( ignoreUnusedProperties: Seq[String], - argsOverrides: ArgsOverrides + defaultArgs: DefaultArgs ) -final case class ArgsOverrides( - addressSchemeByte: Option[Char], - dexRestApi: Option[String], +final case class DefaultArgs( + addressSchemeByte: Char, + dexRestApi: String, nodeRestApi: Option[String], authServiceRestApi: Option[String], - timeout: Option[FiniteDuration] + timeout: FiniteDuration ) { // noinspection ScalaStyle - def updateArgs(args: Args): Args = { - val overrideAddressSchemeByte = addressSchemeByte - .tap(_.foreach(x => println(s"overriding address scheme byte with [$x]"))) - .orElse(args.addressSchemeByte) - val overrideDexRestApi = dexRestApi - .filterNot(_.isEmpty) - .tap(_.foreach(x => println(s"overriding dex rest api with [$x]"))) - .getOrElse(args.dexRestApi) - val overrideNodeRestApi = nodeRestApi - .filterNot(_.isEmpty) - .tap(_.foreach(x => println(s"overriding node rest api with [$x]"))) - .getOrElse(args.nodeRestApi) - val overrideAuthServiceRestApi = authServiceRestApi - .filterNot(_.isEmpty) - .tap(_.foreach(x => println(s"overriding auth service rest api with [$x]"))) - .orElse(args.authServiceRestApi) - val overrideTimeout = timeout - .tap(_.foreach(x => println(s"overriding timeout with [$x]"))) - .getOrElse(args.timeout) + def coverEmptyValues(args: Args): Args = { + val overrideAddressSchemeByte = args.addressSchemeByte.getOrElse(addressSchemeByte) + val overrideDexRestApi = if (args.dexRestApi.isEmpty) dexRestApi else args.dexRestApi + val overrideNodeRestApi = if (args.nodeRestApi.isEmpty) nodeRestApi.getOrElse("") else args.nodeRestApi + val overrideAuthServiceRestApi = if (args.authServiceRestApi.isEmpty) authServiceRestApi else args.authServiceRestApi + val overrideTimeout = if (args.timeout.length == 0) args.timeout else args.timeout args.copy( - addressSchemeByte = overrideAddressSchemeByte, + addressSchemeByte = overrideAddressSchemeByte.some, dexRestApi = overrideDexRestApi, nodeRestApi = overrideNodeRestApi, authServiceRestApi = overrideAuthServiceRestApi,