Skip to content

Commit

Permalink
DEX-1344 Prepare release 2.3.5 - CLI fixes (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
vsuharnikov authored Aug 17, 2021
1 parent b7e6e7f commit 9aa4136
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 61 deletions.
8 changes: 4 additions & 4 deletions dex/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
Expand Down
76 changes: 45 additions & 31 deletions dex/src/main/scala/com/wavesplatform/dex/cli/WavesDexCli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -434,6 +434,11 @@ object WavesDexCli extends ScoptImplicits {
.text("The network byte as char. By default it is the testnet: 'T'")
.valueName("<one char>")
.action((x, s) => s.copy(addressSchemeByte = x.some)),
opt[String]("dex-config")
.abbr("dc")
.text("DEX config path")
.valueName("<raw-string>")
.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")
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
39 changes: 13 additions & 26 deletions dex/src/main/scala/com/wavesplatform/dex/settings/CliSettings.scala
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 9aa4136

Please sign in to comment.