Skip to content

Commit

Permalink
DEX-902 Scala 2.13.3 and dependencies update (#359)
Browse files Browse the repository at this point in the history
* Scala version, akka, scalatest, silencer, scalacheck, monocle, ficus, kamon, waves protobuf schemas, quill jdbc, sttp client, testcontainers, kafka client, scorex, postgres, swagger ui, influx db and common net updated
  • Loading branch information
DenisSerebryansky committed Sep 9, 2020
1 parent e19724b commit 41db755
Show file tree
Hide file tree
Showing 36 changed files with 98 additions and 79 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ lazy val root = (project in file("."))

inScope(Global)(
Seq(
scalaVersion := "2.13.2",
scalaVersion := "2.13.3",
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision,
organization := "com.wavesplatform",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object GenesisConfigGenerator {

object Settings {
implicit val chosenCase: NameMapper = net.ceedubs.ficus.readers.namemappers.implicits.hyphenCase
implicit val settingsReader: ValueReader[Settings] = arbitraryTypeValueReader[Settings]
implicit val settingsReader: ValueReader[Settings] = arbitraryTypeValueReader[Settings].value
}

case class FullAddressInfo(seedText: SeedText,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ object Block {
transactionData: Seq[GenesisTransaction],
signer: KeyPair): Either[GenericError, Block] =
build(version, timestamp, reference, consensusData, transactionData, SignerData(signer, ByteStr.empty))
.map(unsigned => unsigned.copy(signerData = SignerData(signer, ByteStr(crypto.sign(signer, unsigned.bytes.value)))))
.map(unsigned => unsigned.copy(signerData = SignerData(signer, ByteStr(crypto.sign(signer, unsigned.bytes.value())))))
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ package object json {
case Array(amtAssetStr, prcAssetStr) => AssetPair.createAssetPair(amtAssetStr, prcAssetStr)
case _ => throw new Exception(s"$assetPairStr (incorrect assets count, expected 2 but got ${assetPairStrArr.size})")
}
) fold (ex => throw new Exception(s"$assetPairStr (${ex.getMessage})"), identity)
).fold(ex => throw new Exception(s"$assetPairStr (${ex.getMessage})"), identity)
assetPair -> offset
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object GlobalTimer {

implicit class TimerOpsImplicits(val timer: Timer) extends AnyVal {
def schedule[A](f: => Future[A], delay: FiniteDuration): Future[A] = {
val p = Promise[A]
val p = Promise[A]()
try {
timer.newTimeout(_ => p.completeWith(f), delay.length, delay.unit)
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CancelOrderTestSuite extends MatcherSuiteBase {
val ids = for { i <- 1 to 10 } yield {
val o = mkOrder(acc, wavesUsdPair, OrderType.SELL, i.waves, 100 + i)
placeAndAwaitAtDex(o)
o.id.value
o.id.value()
}

dex1.api.cancelAllByIdsWithApiKey(acc, ids.toSet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class PostgresHistoryDatabaseTestSuite extends MatcherSuiteBase with HasPostgres

def getFileContentStr(fileName: String): String = {
val fileStream = getClass.getResourceAsStream(fileName)
Source.fromInputStream(fileStream).getLines.mkString
Source.fromInputStream(fileStream).getLines().mkString
}

def executeCreateTablesStatement(sqlConnection: Connection): Try[Unit] = Try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object GatlingFeeder {
private def mkObsStrings(pairsFile: File, numberPerClient: Int): String = {
val source = Source.fromFile(pairsFile)
try {
val pairs = Random.shuffle(source.getLines.toVector)
val pairs = Random.shuffle(source.getLines().toVector)
require(numberPerClient <= pairs.size, "numberPerClient > available asset pairs in file")
pairs.take(numberPerClient).map(x => s"""{"T":"obs","S":"$x","d":100}""").mkString(";")
} finally source.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ object TankGenerator {
_ =>
accounts.map(mkOrder(
_,
if (math.random < 0.5 || !matching) Type.BUY else Type.SELL,
if (math.random() < 0.5 || !matching) Type.BUY else Type.SELL,
settings.defaults.minimalOrderAmount + Random.nextInt(settings.defaults.minimalOrderAmount.toInt * 10),
settings.defaults.minimalOrderPrice + Random.nextInt(settings.defaults.minimalOrderPrice.toInt * 10),
pairs(Random.nextInt(pairs.length))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object WavesDexLoadCli extends ScoptImplicits {
cmd(Command.CreateFeederFile.name)
.action((_, s) => s.copy(command = Command.CreateFeederFile.some))
.text("Creates files for Gatling feeder")
children (
.children (
opt[Int]("accounts-number")
.abbr("an")
.text("The number of generated accounts")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ import com.wavesplatform.wavesj.matcher.Order
import com.wavesplatform.wavesj.matcher.Order.Type
import com.wavesplatform.wavesj.{ApiJson, AssetPair, PrivateKeyAccount, Transactions}
import play.api.libs.json.{JsValue, Json}
import pureconfig._
import pureconfig.ConfigSource

import scala.annotation.nowarn
import pureconfig.generic.auto._

import scala.io.Source
import scala.util.Random

package object utils {

val settings =
@nowarn
val settings: Settings =
ConfigSource
.fromConfig(ConfigFactory.parseResources(scala.util.Properties.envOrElse("CONF", "devnet.conf")).getConfig("waves.dex.load"))
.load[Settings]
Expand Down Expand Up @@ -92,7 +95,8 @@ package object utils {
val pairs =
if (file.isEmpty) List.empty
else
source.getLines
source
.getLines()
.map(l => {
val splitted = l.split("-")
new AssetPair(splitted(0), splitted(1))
Expand Down
2 changes: 1 addition & 1 deletion dex/src/main/scala/com/wavesplatform/dex/Matcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ class Matcher(settings: MatcherSettings)(implicit val actorSystem: ActorSystem)
}

_ <- {
log.info("Preparing HTTP service ...")
log.info(s"Preparing HTTP service (Matcher's ID = ${settings.id}) ...")
// Indirectly initializes matcherActor, so it must be after loadAllKnownAssets
val combinedRoute = respondWithHeader(MatcherHttpServer(settings.id)) {
new CompositeHttpService(matcherApiTypes, matcherApiRoutes, settings.restApi).compositeRoute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class MatcherActor(settings: MatcherSettings,

private def working: Receive = {

case GetMarkets => sender ! tradedPairs.values.toSeq
case GetMarkets => sender() ! tradedPairs.values.toSeq
case GetSnapshotOffsets => sender() ! SnapshotOffsetsResponse(snapshotsState.snapshotOffsets)

case request: QueueEventWithMeta =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class SpendableBalancesActor(spendableBalances: (Address, Set[Asset]) => Future[
val (knownAssets, unknownAssets) = assetsMaybeBalances.partition { case (_, balance) => balance.isDefined }
if (unknownAssets.isEmpty) {
val knownPreparedState = knownAssets.collect { case (a, Some(b)) => a -> b }
sender ! SpendableBalancesActor.Reply.GetState(knownPreparedState)
sender() ! SpendableBalancesActor.Reply.GetState(knownPreparedState)
} else {
val requestSender = sender
val requestSender = sender()
spendableBalances(address, unknownAssets.keySet).onComplete {
case Success(r) => self.tell(SpendableBalancesActor.NodeBalanceRequestRoundtrip(address, knownAssets.keySet, r), requestSender)
case Failure(ex) =>
Expand All @@ -60,10 +60,10 @@ class SpendableBalancesActor(spendableBalances: (Address, Set[Asset]) => Future[
}

val result = source.filter { case (asset, _) => assets.contains(asset) }
sender ! SpendableBalancesActor.Reply.GetState(result)
sender() ! SpendableBalancesActor.Reply.GetState(result)

case SpendableBalancesActor.Query.GetSnapshot(address) =>
val requestSender = sender
val requestSender = sender()
fullState.get(address) match {
case Some(state) => requestSender ! SpendableBalancesActor.Reply.GetSnapshot(state.filterNot(_._2 == 0).asRight)
case None =>
Expand All @@ -85,7 +85,7 @@ class SpendableBalancesActor(spendableBalances: (Address, Set[Asset]) => Future[
incompleteStateChanges -= address
addressState
}
sender ! SpendableBalancesActor.Reply.GetSnapshot(addressState.asRight)
sender() ! SpendableBalancesActor.Reply.GetSnapshot(addressState.asRight)

case SpendableBalancesActor.Command.UpdateStates(changes) =>
changes.foreach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ class AddressActor(owner: Address,
log.debug(s"Got $command")
val orderId = command.order.id()

if (totalActiveOrders >= settings.maxActiveOrders) sender ! error.ActiveOrdersLimitReached(settings.maxActiveOrders)
else if (failedPlacements.contains(orderId) || hasOrder(orderId)) sender ! error.OrderDuplicate(orderId)
if (totalActiveOrders >= settings.maxActiveOrders) sender() ! error.ActiveOrdersLimitReached(settings.maxActiveOrders)
else if (failedPlacements.contains(orderId) || hasOrder(orderId)) sender() ! error.OrderDuplicate(orderId)
else {
val shouldProcess = placementQueue.isEmpty
placementQueue = placementQueue.enqueue(orderId)
pendingCommands.put(orderId, PendingCommand(command, sender))
pendingCommands.put(orderId, PendingCommand(command, sender()))
if (shouldProcess) processNextPlacement()
else log.trace(s"${placementQueue.headOption} is processing, moving $orderId to the queue")
}
Expand All @@ -91,7 +91,7 @@ class AddressActor(owner: Address,
log.debug(s"Got $command")
pendingCommands.get(orderId) match {
case Some(pc) =>
sender ! {
sender() ! {
pc.command match {
case _: Command.PlaceOrder => error.OrderNotFound(orderId)
case _: Command.CancelOrder => error.OrderCanceled(orderId)
Expand All @@ -101,7 +101,7 @@ class AddressActor(owner: Address,
case None =>
activeOrders.get(orderId) match {
case None =>
sender ! {
sender() ! {
orderDB.status(orderId) match {
case OrderStatus.NotFound => error.OrderNotFound(orderId)
case _: OrderStatus.Cancelled => error.OrderCanceled(orderId)
Expand All @@ -110,9 +110,9 @@ class AddressActor(owner: Address,
}

case Some(ao) =>
if (ao.isMarket) sender ! error.MarketOrderCancel(orderId)
if (ao.isMarket) sender() ! error.MarketOrderCancel(orderId)
else {
pendingCommands.put(orderId, PendingCommand(command, sender))
pendingCommands.put(orderId, PendingCommand(command, sender()))
cancel(ao.order, command.source)
}
}
Expand All @@ -122,10 +122,10 @@ class AddressActor(owner: Address,
val toCancelIds = getActiveLimitOrders(command.pair).map(_.id)
if (toCancelIds.isEmpty) {
log.debug(s"Got $command, nothing to cancel")
sender ! Event.BatchCancelCompleted(Map.empty)
sender() ! Event.BatchCancelCompleted(Map.empty)
} else {
log.debug(s"Got $command, to cancel: ${toCancelIds.mkString(", ")}")
context.actorOf(BatchOrderCancelActor.props(toCancelIds.toSet, command.source, self, sender, settings.batchCancelTimeout))
context.actorOf(BatchOrderCancelActor.props(toCancelIds.toSet, command.source, self, sender(), settings.batchCancelTimeout))
}

case command: Command.CancelOrders =>
Expand All @@ -139,9 +139,9 @@ class AddressActor(owner: Address,
)

val initResponse = unknownIds.map(id => id -> error.OrderNotFound(id).asLeft[AddressActor.Event.OrderCanceled]).toMap
if (toCancelIds.isEmpty) sender ! Event.BatchCancelCompleted(initResponse)
if (toCancelIds.isEmpty) sender() ! Event.BatchCancelCompleted(initResponse)
else
context.actorOf(BatchOrderCancelActor.props(toCancelIds, command.source, self, sender, settings.batchCancelTimeout, initResponse))
context.actorOf(BatchOrderCancelActor.props(toCancelIds, command.source, self, sender(), settings.batchCancelTimeout, initResponse))

case msg: Message.BalanceChanged =>
if (wsAddressState.hasActiveSubscriptions) {
Expand All @@ -162,14 +162,14 @@ class AddressActor(owner: Address,
}
}

case Query.GetReservedBalance => sender ! Reply.Balance(openVolume.filter(_._2 > 0))
case Query.GetTradableBalance(forAssets) => getTradableBalance(forAssets).map(Reply.Balance).pipeTo(sender)
case Query.GetReservedBalance => sender() ! Reply.Balance(openVolume.filter(_._2 > 0))
case Query.GetTradableBalance(forAssets) => getTradableBalance(forAssets).map(Reply.Balance).pipeTo(sender())

case Query.GetOrderStatus(orderId) =>
sender ! Reply.GetOrderStatus(activeOrders.get(orderId).fold[OrderStatus](orderDB.status(orderId))(_.status))
sender() ! Reply.GetOrderStatus(activeOrders.get(orderId).fold[OrderStatus](orderDB.status(orderId))(_.status))

case Query.GetOrderStatusInfo(orderId) =>
sender ! Reply.OrdersStatusInfo(
sender() ! Reply.OrdersStatusInfo(
activeOrders
.get(orderId)
.map(ao => OrderInfo.v5(ao, ao.status)) orElse orderDB.getOrderInfo(orderId)
Expand All @@ -185,7 +185,7 @@ class AddressActor(owner: Address,
else Seq.empty

val matchingClosedOrders = if (orderListType.hasClosed) orderDB.getFinalizedOrders(owner, maybePair) else Seq.empty
sender ! Reply.OrdersStatuses(matchingActiveOrders ++ matchingClosedOrders)
sender() ! Reply.OrdersStatuses(matchingActiveOrders ++ matchingClosedOrders)

case Event.StoreFailed(orderId, reason, queueEvent) =>
failedPlacements.add(orderId)
Expand Down Expand Up @@ -446,7 +446,7 @@ class AddressActor(owner: Address,
wsAddressState = status match {
case OrderStatus.Accepted => wsAddressState.putOrderUpdate(remaining.id, WsOrder.fromDomain(remaining, status))
case _: OrderStatus.Cancelled => wsAddressState.putOrderStatusNameUpdate(remaining.id, status)
case _ =>
case _ =>
if (unmatchable) wsAddressState.putOrderStatusNameUpdate(remaining.id, status)
else wsAddressState.putOrderFillingInfoAndStatusNameUpdate(remaining, status)
}
Expand Down Expand Up @@ -614,10 +614,10 @@ object AddressActor {
sealed trait Source extends Product with Serializable
object Source {
// If you change this list, don't forget to change sourceToBytes
case object NotTracked extends Source
case object Request extends Source // User or admin, we don't know
case object Expiration extends Source
case object BalanceTracking extends Source
case object NotTracked extends Source
case object Request extends Source // User or admin, we don't know
case object Expiration extends Source
case object BalanceTracking extends Source
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AddressDirectoryActor(orderDB: OrderDB, addressActorProps: (Address, Boole

private def forward(address: Address, msg: Any): Unit = (children get address, msg) match {
case (None, _: AddressActor.Message.BalanceChanged) =>
case _ => children getOrElseUpdate (address, createAddressActor(address)) forward msg
case _ => children.getOrElseUpdate(address, createAddressActor(address)) forward msg
}

override def receive: Receive = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.wavesplatform.dex.settings.OrderRestrictionsSettings
import com.wavesplatform.dex.time.Time
import monocle.macros.GenLens

import scala.annotation.nowarn
import scala.collection.immutable.TreeMap
import scala.concurrent.duration.FiniteDuration

Expand Down Expand Up @@ -251,6 +252,7 @@ object AggregatedOrderBookActor {
case (k, v) => k -> v.view.map(_.amount).sum
}

@nowarn
def sum(orig: TreeMap[Price, Amount], diff: Map[Price, Amount]): TreeMap[Price, Amount] =
diff.foldLeft(orig) {
case (r, (price, amount)) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BroadcastExchangeTransactionActor(settings: ExchangeTransactionBroadcastSe

confirmed { toCheck.map(_.id()) }
.flatMap { confirmations =>
val (confirmed, unconfirmed) = toCheck.partition(tx => confirmations(tx.id.value))
val (confirmed, unconfirmed) = toCheck.partition(tx => confirmations(tx.id.value()))
val (expired, ready) = unconfirmed.partition(_.timestamp <= expireMs)

Future
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ object WsExternalClientHandlerActor {
clientRef ! WsError.from(e, matcherTime)
Behaviors.same
case Right(jwtPayload) =>
val subscriptionLifetime = (jwtPayload.activeTokenExpirationInSeconds * 1000 - time.correctedTime).millis
val subscriptionLifetime = (jwtPayload.activeTokenExpirationInSeconds * 1000 - time.correctedTime()).millis
val expiration = scheduleOnce(subscriptionLifetime, CancelAddressSubscription(address))

addressSubscriptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TestWsHandlerActor(testId: Int, keepAlive: Boolean) extends Actor with Sco
}

override val receive: Receive = {
case AssignSourceRef => context.become { awaitPings(sourceRef = sender) }
case AssignSourceRef => context.become { awaitPings(sourceRef = sender()) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class MatcherWebSocketRoute(wsInternalBroadcastRef: typed.ActorRef[WsInternalBro
}

object MatcherWebSocketRoute {
private[MatcherWebSocketRoute] class CloseHandler(val close: () => Unit, val closed: Promise[Done] = Promise[Done]) {
private[MatcherWebSocketRoute] class CloseHandler(val close: () => Unit, val closed: Promise[Done] = Promise[Done]()) {
def closeOn(f: Future[Done]): Unit = closed.completeWith(f)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.wavesplatform.dex.domain.model.{Amount, Price}
import com.wavesplatform.dex.model.{LastTrade, LevelAmounts}
import monocle.macros.GenLens

import scala.annotation.nowarn
import scala.collection.immutable.TreeMap

case class WsOrderBookState(wsConnections: Map[ActorRef[WsOrderBookChanges], Long],
Expand Down Expand Up @@ -74,6 +75,7 @@ case class WsOrderBookState(wsConnections: Map[ActorRef[WsOrderBookChanges], Lon
changedTickSize = None
)

@nowarn
def take(xs: TreeMap[Price, Amount], levels: Set[Price]): TreeMap[Price, Amount] = {
// 1. Levels will be always smaller, than xs
// 2. A level could gone from xs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import com.wavesplatform.dex.error.{Class, Entity, MatcherError}
import com.wavesplatform.dex.meta.{DescendantSamples, getSimpleName}
import play.api.libs.json.Json

import scala.annotation.nowarn

object MatcherErrorDoc {

object entitySamples extends DescendantSamples[Entity]
object classSamples extends DescendantSamples[Class]
object errorSamples extends DescendantSamples[MatcherError]

@nowarn
def mkMarkdown: String = {
val entities = entitySamples.run
.map(x => x.code -> getSimpleName(x))
Expand Down
Loading

0 comments on commit 41db755

Please sign in to comment.