Skip to content

Commit

Permalink
Simplify configReaders
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirlogachev committed Feb 3, 2025
1 parent 96dcc6f commit e396035
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ object GenesisBlockGenerator {
case class DistributionItem(seedText: String, nonce: Int, amount: Share, miner: Boolean = true)

object DistributionItem {
given ConfigReader[DistributionItem] = deriveReader[DistributionItem]
// This given is required for default args to work.
// Details: https://github.com/pureconfig/pureconfig/issues/1673
// Note: the proposed approach with `extension` doesn't work.
given ConfigReader[DistributionItem] = deriveReader
}

case class Settings(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ case class FunctionalitySettings(
}

object FunctionalitySettings {
given ConfigReader[FunctionalitySettings] = deriveReader[FunctionalitySettings]
// This given is required for default args to work.
// Details: https://github.com/pureconfig/pureconfig/issues/1673
// Note: the proposed approach with `extension` doesn't work.
given ConfigReader[FunctionalitySettings] = deriveReader

val MAINNET: FunctionalitySettings = apply(
featureCheckBlocksPeriod = 5000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ case class DBSettings(
)

object DBSettings {
given ConfigReader[DBSettings] = deriveReader[DBSettings]
// This given is required for default args to work.
// Details: https://github.com/pureconfig/pureconfig/issues/1673
// Note: the proposed approach with `extension` doesn't work.
given ConfigReader[DBSettings] = deriveReader
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package com.wavesplatform.settings

import pureconfig.*
import pureconfig.generic.semiauto.deriveReader

case class FeaturesSettings(autoShutdownOnUnsupportedFeature: Boolean, supported: List[Short] = defaultSupported)
case class FeaturesSettings(autoShutdownOnUnsupportedFeature: Boolean, supported: List[Short] = List.empty)

object FeaturesSettings {
// Note: This setup (default values + manual ConfigReader instance)
// is a workaround for `pureconfig-generic-scala3` (it doesn't support default values from case classes yet)
val defaultSupported: List[Short] = List.empty

given ConfigReader[FeaturesSettings] = ConfigReader.fromCursor(cur =>
for {
objCur <- cur.asObjectCursor
autoShutdownOnUnsupportedFeature <- objCur.required[Boolean]("auto-shutdown-on-unsupported-feature")
supported <- objCur.optionalWithDefault("supported", defaultSupported)
} yield FeaturesSettings(autoShutdownOnUnsupportedFeature, supported)
)
// This given is required for default args to work.
// Details: https://github.com/pureconfig/pureconfig/issues/1673
// Note: the proposed approach with `extension` doesn't work.
given ConfigReader[FeaturesSettings] = deriveReader
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ case class RideRunnerBlockchainState(
)

object RideRunnerBlockchainState {
// required for default args to work properly: https://github.com/pureconfig/pureconfig/issues/1673
given ConfigReader[RideRunnerBlockchainState] = deriveReader[RideRunnerBlockchainState]
// This given is required for default args to work.
// Details: https://github.com/pureconfig/pureconfig/issues/1673
// Note: the proposed approach with `extension` doesn't work.
given ConfigReader[RideRunnerBlockchainState] = deriveReader
}

0 comments on commit e396035

Please sign in to comment.