Check gas price (#494)

* add gas validation option

* gas price config for chains

* check gas price

* add tests

* fix txt

* make gas price dls

* fix config
This commit is contained in:
Anton
2024-05-31 15:46:55 +03:00
committed by GitHub
parent 4aff35994f
commit 772142e156
9 changed files with 133 additions and 19 deletions

View File

@@ -12,11 +12,29 @@ data class ChainsConfig(private val chains: List<ChainConfig>) : Iterable<Chains
override fun iterator(): Iterator<ChainConfig> {
return chains.iterator()
}
companion object {
@JvmStatic
fun default(): ChainsConfig = ChainsConfig(emptyList())
}
class GasPriceCondition(private val condition: String) {
fun check(value: Long): Boolean {
val (op, valueStr) = condition.split(" ")
return when (op) {
"ne" -> value != valueStr.toLong()
"eq" -> value == valueStr.toLong()
"gt" -> value > valueStr.toLong()
"lt" -> value < valueStr.toLong()
"ge" -> value >= valueStr.toLong()
"le" -> value <= valueStr.toLong()
else -> throw IllegalArgumentException("Unsupported condition: $condition")
}
}
fun rules() = condition
}
data class ChainConfig(
val expectedBlockTime: Duration,
val syncingLagSize: Int,
@@ -30,7 +48,8 @@ data class ChainsConfig(private val chains: List<ChainConfig>) : Iterable<Chains
val callLimitContract: String?,
val id: String,
val blockchain: String,
val type: String
val type: String,
val gasPriceCondition: GasPriceCondition? = null,
) {
companion object {
@JvmStatic
@@ -50,12 +69,15 @@ data class ChainsConfig(private val chains: List<ChainConfig>) : Iterable<Chains
callLimitContract,
"undefined",
"undefined",
"unknown"
"unknown",
null,
)
@JvmStatic
fun defaultWithGasPriceCondition(gasPriceCondition: String) = defaultWithContract(null).copy(
gasPriceCondition = GasPriceCondition(gasPriceCondition),
)
}
}
fun resolve(chain: String): ChainConfig {