Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: update to rc20 #384

Merged
merged 16 commits into from
Nov 3, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.net.URL
fun main(args: Array<String>): Unit = runBlocking {
val peerUrl = "http://127.0.0.1:8080"
val telemetryUrl = "http://127.0.0.1:8180"
val admin = AccountId("bob".asName(), "wonderland".asDomainId())
val admin = AccountId("wonderland".asDomainId(), "bob".asName())
val adminKeyPair = keyPairFromHex(
"7233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0",
"9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ open class AdminIroha2Client(
/**
* Send metrics request
*/
suspend fun metrics(): String = client.get("${getTelemetryUrl()}$METRICS_ENDPOINT").body()
suspend fun metrics(): String = client.get("${getApiUrl()}$METRICS_ENDPOINT").body()

/**
* Send health check request
Expand All @@ -66,7 +66,7 @@ open class AdminIroha2Client(
/**
* Send status check request
*/
suspend fun status(): PeerStatus = client.get("${getTelemetryUrl()}$STATUS_ENDPOINT").body()
suspend fun status(): PeerStatus = client.get("${getApiUrl()}$STATUS_ENDPOINT").body()

/**
* Send schema request
Expand Down
38 changes: 19 additions & 19 deletions modules/block/src/main/kotlin/jp/co/soramitsu/iroha2/Genesis.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package jp.co.soramitsu.iroha2

import jp.co.soramitsu.iroha2.generated.ExecutorMode
import jp.co.soramitsu.iroha2.generated.Expression
import jp.co.soramitsu.iroha2.generated.IdentifiableBox
import jp.co.soramitsu.iroha2.generated.InstructionBox
import jp.co.soramitsu.iroha2.generated.InstructionExpr
import jp.co.soramitsu.iroha2.generated.Metadata
import jp.co.soramitsu.iroha2.generated.NewAccount
import jp.co.soramitsu.iroha2.generated.NewAssetDefinition
import jp.co.soramitsu.iroha2.generated.NewDomain
import jp.co.soramitsu.iroha2.generated.RawGenesisBlock
import jp.co.soramitsu.iroha2.generated.RegisterBox
import jp.co.soramitsu.iroha2.generated.RegisterExpr
import jp.co.soramitsu.iroha2.generated.RegistrableBox
import jp.co.soramitsu.iroha2.generated.ValidatorMode
import jp.co.soramitsu.iroha2.generated.Value
import java.nio.file.Files
import java.nio.file.Path
Expand All @@ -37,31 +37,31 @@ open class Genesis(open val block: RawGenesisBlock) {

companion object {

val validatorMode = this::class.java.classLoader.getResource("validator.wasm")
?.let { ValidatorMode.Path("validator.wasm") }
?: throw IrohaSdkException("validator.wasm not found")
val executorMode = this::class.java.classLoader.getResource("executor.wasm")
?.let { ExecutorMode.Path("executor.wasm") }
?: throw IrohaSdkException("executor.wasm not found")

/**
* Return empty genesis
*/
fun getEmpty() = Genesis(RawGenesisBlock(listOf(listOf()), validatorMode))
fun getEmpty() = Genesis(RawGenesisBlock(listOf(listOf()), executorMode))

/**
* List of genesis blocks to single block with unique instructions
*/
fun List<Genesis>.toSingle(): Genesis {
val uniqueIsi: MutableSet<InstructionBox> = mutableSetOf()
val uniqueIsi: MutableSet<InstructionExpr> = mutableSetOf()
this.forEach { genesis ->
uniqueIsi.addAll(genesis.block.transactions.flatten())
}

return Genesis(RawGenesisBlock(listOf(uniqueIsi.mergeMetadata()), validatorMode))
return Genesis(RawGenesisBlock(listOf(uniqueIsi.mergeMetadata()), executorMode))
}

private fun MutableSet<InstructionBox>.mergeMetadata(): List<InstructionBox> {
private fun MutableSet<InstructionExpr>.mergeMetadata(): List<InstructionExpr> {
val metadataMap = mutableMapOf<Any, Metadata>()

// only for InstructionBox.Register
// only for InstructionExpr.Register
this.extractIdentifiableBoxes().forEach { idBox ->
metadataMap.putMergedMetadata(idBox)
}
Expand All @@ -71,16 +71,16 @@ open class Genesis(open val block: RawGenesisBlock) {
val idBox = toReplace.first().extractIdentifiableBox()
val registrableBox = idBox?.toRegisterBox(metadata)
?: throw RuntimeException("IdentifiableBox shouldn't be null")
this.add(InstructionBox.Register(RegisterBox(registrableBox.evaluatesTo())))
this.add(InstructionExpr.Register(RegisterExpr(registrableBox.evaluatesTo())))
}

return this.sorted()
}

private fun MutableSet<InstructionBox>.sorted() = this.sortedWith(
private fun MutableSet<InstructionExpr>.sorted() = this.sortedWith(
compareByDescending { instruction ->
when (instruction) {
is InstructionBox.Register -> when (instruction.extractIdentifiableBox()) {
is InstructionExpr.Register -> when (instruction.extractIdentifiableBox()) {
is IdentifiableBox.NewDomain -> 5
is IdentifiableBox.NewAccount -> 4
is IdentifiableBox.NewAssetDefinition -> 3
Expand Down Expand Up @@ -142,15 +142,15 @@ open class Genesis(open val block: RawGenesisBlock) {
}
}

private fun MutableSet<InstructionBox>.findIsiToReplace(
private fun MutableSet<InstructionExpr>.findIsiToReplace(
metadata: Map<Any, Metadata>,
): MutableMap<Metadata, MutableList<InstructionBox.Register>> {
val isiToReplace = mutableMapOf<Metadata, MutableList<InstructionBox.Register>>()
): MutableMap<Metadata, MutableList<InstructionExpr.Register>> {
val isiToReplace = mutableMapOf<Metadata, MutableList<InstructionExpr.Register>>()

this.forEach { instruction ->
runCatching {
instruction.cast<InstructionBox.Register>()
.registerBox.`object`.expression
instruction.cast<InstructionExpr.Register>()
.registerExpr.`object`.expression
.cast<Expression.Raw>().value
.cast<Value.Identifiable>().identifiableBox
}.onSuccess { idBox ->
Expand Down
Loading