add base support of polkadot/substrate/vara chain (#332)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import com.squareup.kotlinpoet.*
|
||||
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
|
||||
import io.emeraldpay.dshackle.BlockchainType
|
||||
import io.emeraldpay.dshackle.config.ChainsConfig
|
||||
import io.emeraldpay.dshackle.config.ChainsConfigReader
|
||||
import io.emeraldpay.dshackle.foundation.ChainOptionsReader
|
||||
@@ -18,7 +19,7 @@ open class CodeGen(private val config: ChainsConfig) {
|
||||
builder.addEnumConstant(
|
||||
"UNSPECIFIED",
|
||||
TypeSpec.anonymousClassBuilder()
|
||||
.addSuperclassConstructorParameter("%L, %S, %S, %S, %L, %L", 0, "UNSPECIFIED", "Unknown", "0x0", "BigInteger.ZERO", "emptyList()")
|
||||
.addSuperclassConstructorParameter("%L, %S, %S, %S, %L, %L, %L", 0, "UNSPECIFIED", "Unknown", "0x0", "BigInteger.ZERO", "emptyList()", "BlockchainType.UNKNOWN")
|
||||
.build(),
|
||||
)
|
||||
for (chain in config) {
|
||||
@@ -27,13 +28,14 @@ open class CodeGen(private val config: ChainsConfig) {
|
||||
.replace(' ', '_'),
|
||||
TypeSpec.anonymousClassBuilder()
|
||||
.addSuperclassConstructorParameter(
|
||||
"%L, %S, %S, %S, %L, %L",
|
||||
"%L, %S, %S, %S, %L, %L, %L",
|
||||
chain.grpcId,
|
||||
chain.code,
|
||||
chain.blockchain.replaceFirstChar { it.uppercase() } + " " + chain.id.replaceFirstChar { it.uppercase() },
|
||||
chain.chainId,
|
||||
"BigInteger(\"" + chain.netVersion + "\")",
|
||||
"listOf(" + chain.shortNames.map { "\"${it}\"" }.joinToString() + ")",
|
||||
type(chain.type)
|
||||
)
|
||||
.build(),
|
||||
)
|
||||
@@ -65,6 +67,7 @@ open class CodeGen(private val config: ChainsConfig) {
|
||||
.addParameter("chainId", String::class)
|
||||
.addParameter("netVersion", BigInteger::class)
|
||||
.addParameter("shortNames", List::class.asClassName().parameterizedBy(String::class.asClassName()))
|
||||
.addParameter("type", BlockchainType::class)
|
||||
.build(),
|
||||
)
|
||||
.addProperty(
|
||||
@@ -96,12 +99,27 @@ open class CodeGen(private val config: ChainsConfig) {
|
||||
PropertySpec.builder("shortNames", List::class.asClassName().parameterizedBy(String::class.asClassName()))
|
||||
.initializer("shortNames")
|
||||
.build(),
|
||||
),
|
||||
)
|
||||
.addProperty(
|
||||
PropertySpec.builder("type", BlockchainType::class)
|
||||
.initializer("type")
|
||||
.build(),
|
||||
)
|
||||
).build()
|
||||
return FileSpec.builder("io.emeraldpay.dshackle", "Chain")
|
||||
.addType(chainType)
|
||||
.build()
|
||||
}
|
||||
|
||||
private fun type(type: String): String {
|
||||
return when(type) {
|
||||
"eth" -> "BlockchainType.ETHEREUM"
|
||||
"bitcoin" -> "BlockchainType.BITCOIN"
|
||||
"starknet" -> "BlockchainType.STARKNET"
|
||||
"polkadot" -> "BlockchainType.POLKADOT"
|
||||
else -> throw IllegalArgumentException("unknown blockchain type $type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class ChainsCodeGenTask : DefaultTask() {
|
||||
|
||||
Reference in New Issue
Block a user