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

Update/mvp #453

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
root = true

[{*.kt,*.kts}]
max_line_length = 140
ktlint_code_style = intellij_idea
ktlint_experimental = disabled
ktlint_standard_final-newline = disabled
ktlint_standard_string-template-indent = disabled
ktlint_standard_multiline-if-else = disabled
ktlint_standard_property-wrapping = disabled
ktlint_standard_parameter-wrapping = disabled
ktlint_standard_multiline-expression-wrapping = disabled
ktlint_standard_function-literal = disabled
ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = 3
ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = 3
ktlint_standard_binary-expression-wrapping = disabled
# ktlint_function_signature_body_expression_wrapping = multiline

[libs/contracts/src/main/kotlin/com/fil/fib/contract/Error.kt]
max_line_length = 1000
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
build/
.idea/
.kotlin/
.gradle/
*/*/out

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ subprojects {

java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
languageVersion = JavaLanguageVersion.of(21)
}

withJavadocJar()
Expand Down
53 changes: 30 additions & 23 deletions docker-compose/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
services:
irohad0:
image: hyperledger/iroha:2.0.0-pre-rc.22.2
image: hyperledger/iroha:2.0.0-rc.1.0
platform: linux/amd64
environment:
CHAIN: 00000000-0000-0000-0000-000000000000
PUBLIC_KEY: ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D
PRIVATE_KEY: 802620A4DFC16789FBF9A588525E4AC7F791AC51B12AEE8919EACC03EB2FC31D32C692
P2P_PUBLIC_ADDRESS: irohad0:1337
P2P_ADDRESS: 0.0.0.0:1337
API_ADDRESS: 0.0.0.0:8080
TRUSTED_PEERS: '[{"address":"irohad2:1339","public_key":"ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10"},{"address":"irohad1:1338","public_key":"ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D"},{"address":"irohad3:1340","public_key":"ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE"}]'
GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
TRUSTED_PEERS: '["ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D@irohad1:1338","ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10@irohad2:1339","ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE@irohad3:1340"]'
GENESIS_PRIVATE_KEY: 80262082B3BDE54AEBECA4146257DA0DE8D59D8E46D5FE34887DCD8072866792FCB3AD
GENESIS: /tmp/genesis.signed.scale
TOPOLOGY: '[{"address":"irohad2:1339","public_key":"ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10"},{"address":"irohad1:1338","public_key":"ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D"},{"address":"irohad0:1337","public_key":"ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D"},{"address":"irohad3:1340","public_key":"ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE"}]'
TOPOLOGY: '["ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D","ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D","ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10","ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE"]'
ports:
- 1337:1337
- 8080:8080
- 1337:1337
- 8080:8080
volumes:
- "../modules/test-tools/src/main/resources:/config"
- "../modules/test-tools/src/main/resources:/config"
init: true
healthcheck:
test: test $(curl -s http://127.0.0.1:8080/status/blocks) -gt 0
Expand All @@ -29,34 +30,38 @@ services:
/bin/sh -c "
EXECUTOR_RELATIVE_PATH=$(jq -r '.executor' /config/genesis.json) && \\
EXECUTOR_ABSOLUTE_PATH=$(realpath \"/config/$$EXECUTOR_RELATIVE_PATH\") && \\
WASM_DIR_RELATIVE_PATH=$(jq -r '.wasm_dir' /config/genesis.json) && \\
WASM_DIR_ABSOLUTE_PATH=$(realpath \"/config/$$WASM_DIR_RELATIVE_PATH\") && \\
jq \\
--arg executor \"$$EXECUTOR_ABSOLUTE_PATH\" \\
--arg wasm_dir \"$$WASM_DIR_ABSOLUTE_PATH\" \\
--argjson topology \"$$TOPOLOGY\" \\
'.executor = $$executor | .topology = $$topology' /config/genesis.json \\
'.executor = $$executor | .wasm_dir = $$wasm_dir | .topology = $$topology' /config/genesis.json \\
>/tmp/genesis.json && \\
kagami genesis sign /tmp/genesis.json \\
--public-key $$GENESIS_PUBLIC_KEY \\
--private-key $$GENESIS_PRIVATE_KEY \\
--out-file $$GENESIS \\
&& \\
irohad
exec irohad
"
irohad1:
image: hyperledger/iroha:2.0.0-pre-rc.22.2
image: hyperledger/iroha:2.0.0-rc.1.0
platform: linux/amd64
environment:
CHAIN: 00000000-0000-0000-0000-000000000000
PUBLIC_KEY: ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D
PRIVATE_KEY: 8026203ECA64ADC23DC106C9D703233375EA6AC345AD7299FF3AD45F355DE6CD1B5510
P2P_PUBLIC_ADDRESS: irohad1:1338
P2P_ADDRESS: 0.0.0.0:1338
API_ADDRESS: 0.0.0.0:8081
GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
TRUSTED_PEERS: '[{"address":"irohad2:1339","public_key":"ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10"},{"address":"irohad0:1337","public_key":"ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D"},{"address":"irohad3:1340","public_key":"ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE"}]'
TRUSTED_PEERS: '["ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D@irohad0:1337","ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10@irohad2:1339","ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE@irohad3:1340"]'
ports:
- 1338:1338
- 8081:8081
- 1338:1338
- 8081:8081
volumes:
- "../modules/test-tools/src/main/resources:/config"
- "../modules/test-tools/src/main/resources:/config"
init: true
healthcheck:
test: test $(curl -s http://127.0.0.1:8081/status/blocks) -gt 0
Expand All @@ -65,21 +70,22 @@ services:
retries: 30
start_period: 4s
irohad2:
image: hyperledger/iroha:2.0.0-pre-rc.22.2
image: hyperledger/iroha:2.0.0-rc.1.0
platform: linux/amd64
environment:
CHAIN: 00000000-0000-0000-0000-000000000000
PUBLIC_KEY: ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10
PRIVATE_KEY: 8026207B1C78F733EDAFD6AF9BAC3A0D6C5A494557DD031609A4FDD9796EEF471D928C
P2P_PUBLIC_ADDRESS: irohad2:1339
P2P_ADDRESS: 0.0.0.0:1339
API_ADDRESS: 0.0.0.0:8082
GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
TRUSTED_PEERS: '[{"address":"irohad1:1338","public_key":"ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D"},{"address":"irohad0:1337","public_key":"ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D"},{"address":"irohad3:1340","public_key":"ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE"}]'
TRUSTED_PEERS: '["ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D@irohad0:1337","ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D@irohad1:1338","ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE@irohad3:1340"]'
ports:
- 1339:1339
- 8082:8082
- 1339:1339
- 8082:8082
volumes:
- "../modules/test-tools/src/main/resources:/config"
- "../modules/test-tools/src/main/resources:/config"
init: true
healthcheck:
test: test $(curl -s http://127.0.0.1:8082/status/blocks) -gt 0
Expand All @@ -88,21 +94,22 @@ services:
retries: 30
start_period: 4s
irohad3:
image: hyperledger/iroha:2.0.0-pre-rc.22.2
image: hyperledger/iroha:2.0.0-rc.1.0
platform: linux/amd64
environment:
CHAIN: 00000000-0000-0000-0000-000000000000
PUBLIC_KEY: ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE
PRIVATE_KEY: 8026206C7FF4CA09D395C7B7332C654099406E929C6238942E3CE85155CC1A5E2CF519
P2P_PUBLIC_ADDRESS: irohad3:1340
P2P_ADDRESS: 0.0.0.0:1340
API_ADDRESS: 0.0.0.0:8083
GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
TRUSTED_PEERS: '[{"address":"irohad2:1339","public_key":"ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10"},{"address":"irohad1:1338","public_key":"ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D"},{"address":"irohad0:1337","public_key":"ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D"}]'
TRUSTED_PEERS: '["ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D@irohad0:1337","ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D@irohad1:1338","ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10@irohad2:1339"]'
ports:
- 1340:1340
- 8083:8083
- 1340:1340
- 8083:8083
volumes:
- "../modules/test-tools/src/main/resources:/config"
- "../modules/test-tools/src/main/resources:/config"
init: true
healthcheck:
test: test $(curl -s http://127.0.0.1:8083/status/blocks) -gt 0
Expand Down
21 changes: 13 additions & 8 deletions examples/tutorial/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
val ktorVer = project.properties["ktorVer"] as String

dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.0")
implementation(project(":admin-client"))

implementation("net.i2p.crypto:eddsa:0.3.0")
implementation("org.bouncycastle:bcprov-jdk15on:1.65")
implementation("com.github.multiformats:java-multihash:1.3.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
implementation("io.ktor:ktor-client-logging:$ktorVer")
}

implementation(project(":model"))
implementation(project(":block"))
api(project(":admin-client"))
tasks.jacocoTestReport {
mustRunAfter(":admin-client:jacocoTestReport")
mustRunAfter(":block:jacocoTestReport")
mustRunAfter(":client:jacocoTestReport")
mustRunAfter(":codegen:jacocoTestReport")
mustRunAfter(":model:jacocoTestReport")
mustRunAfter(":test-tools:jacocoTestReport")
}

tasks.jacocoTestReport {
Expand Down
14 changes: 7 additions & 7 deletions examples/tutorial/src/main/kotlin/jp/co/soramitsu/iroha2/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import jp.co.soramitsu.iroha2.generated.AssetId
import jp.co.soramitsu.iroha2.generated.AssetType
import jp.co.soramitsu.iroha2.generated.AssetValue
import kotlinx.coroutines.runBlocking
import java.net.URL
import java.math.BigDecimal
import java.net.URI
import java.util.UUID

fun main(args: Array<String>): Unit = runBlocking {
fun main(): Unit = runBlocking {
val chainId = UUID.fromString("00000000-0000-0000-0000-000000000000")
val apiUrl = "http://127.0.0.1:8080"
val peerUrl = "http://127.0.0.1:1337"
val admin = AccountId(
"wonderland".asDomainId(),
publicKeyFromHex("CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03").toIrohaPublicKey(),
Expand All @@ -20,7 +20,7 @@ fun main(args: Array<String>): Unit = runBlocking {
"CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03",
"CCF31D85E3B32A4BEA59987CE0C78E3B8E2DB93881468AB2435FE45D5C9DCD53",
)
val client = AdminIroha2Client(URL(apiUrl), URL(peerUrl))
val client = AdminIroha2Client(listOf(URI(apiUrl).toURL()), chainId, admin, adminKeyPair)
val query = Query(client, admin, adminKeyPair)
query.findAllDomains()
.also { println("ALL DOMAINS: ${it.map { d -> d.id.asString() }}") }
Expand All @@ -29,7 +29,7 @@ fun main(args: Array<String>): Unit = runBlocking {
query.findAllAssets()
.also { println("ALL ASSETS: ${it.map { d -> d.id.asString() }}") }

val sendTransaction = SendTransaction(client, admin, adminKeyPair, chainId)
val sendTransaction = SendTransaction(client)

val domain = "looking_glass_${System.currentTimeMillis()}"
sendTransaction.registerDomain(domain).also { println("DOMAIN $domain CREATED") }
Expand All @@ -56,12 +56,12 @@ fun main(args: Array<String>): Unit = runBlocking {
sendTransaction.registerAsset(whiteRabbitAsset, AssetValue.Numeric(0.asNumeric()))
.also { println("ASSET $whiteRabbitAsset CREATED") }

sendTransaction.transferAsset(madHatterAsset, 10, whiteRabbit.asString(), madHatter, madHatterKeyPair)
sendTransaction.transferAsset(madHatterAsset, BigDecimal(10), whiteRabbit.asString())
.also { println("$madHatter TRANSFERRED FROM $madHatterAsset TO $whiteRabbitAsset: 10") }
query.getAccountAmount(madHatter, madHatterAsset.definition).also { println("$madHatterAsset BALANCE: $it") }
query.getAccountAmount(whiteRabbit, whiteRabbitAsset.definition).also { println("$whiteRabbitAsset BALANCE: $it") }

sendTransaction.burnAssets(madHatterAsset, 10, madHatter, madHatterKeyPair)
sendTransaction.burnAssets(madHatterAsset, BigDecimal(10))
.also { println("$madHatterAsset WAS BURN") }

query.getAccountAmount(madHatter, madHatterAsset.definition)
Expand Down
56 changes: 34 additions & 22 deletions examples/tutorial/src/main/kotlin/jp/co/soramitsu/iroha2/Query.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package jp.co.soramitsu.iroha2

import jp.co.soramitsu.iroha2.generated.AccountId
import jp.co.soramitsu.iroha2.generated.AccountIdPredicateAtom
import jp.co.soramitsu.iroha2.generated.AccountIdProjectionOfPredicateMarker
import jp.co.soramitsu.iroha2.generated.AssetDefinitionId
import jp.co.soramitsu.iroha2.generated.AssetIdProjectionOfPredicateMarker
import jp.co.soramitsu.iroha2.generated.AssetProjectionOfPredicateMarker
import jp.co.soramitsu.iroha2.generated.AssetValue
import jp.co.soramitsu.iroha2.generated.GenericPredicateBox
import jp.co.soramitsu.iroha2.generated.QueryOutputPredicate
import jp.co.soramitsu.iroha2.generated.CompoundPredicateOfAccount
import jp.co.soramitsu.iroha2.generated.CompoundPredicateOfAsset
import jp.co.soramitsu.iroha2.generated.CompoundPredicateOfDomain
import jp.co.soramitsu.iroha2.query.QueryBuilder
import java.math.BigInteger
import java.security.KeyPair
Expand All @@ -15,31 +20,38 @@ open class Query(
private val keyPair: KeyPair,
) {

suspend fun findAllDomains(queryFilter: GenericPredicateBox<QueryOutputPredicate>? = null) = QueryBuilder
.findAllDomains(queryFilter)
.account(admin)
.buildSigned(keyPair)
.let { client.sendQuery(it) }
suspend fun findAllDomains(filter: CompoundPredicateOfDomain? = null) = client.submit(
QueryBuilder
.findDomains(filter)
.signAs(admin, keyPair),
)

suspend fun findAllAccounts(queryFilter: GenericPredicateBox<QueryOutputPredicate>? = null) = QueryBuilder
.findAllAccounts(queryFilter)
.account(admin)
.buildSigned(keyPair)
.let { client.sendQuery(it) }
suspend fun findAllAccounts(filter: CompoundPredicateOfAccount? = null) = client.submit(
QueryBuilder
.findAccounts(filter)
.signAs(admin, keyPair),
)

suspend fun findAllAssets(queryFilter: GenericPredicateBox<QueryOutputPredicate>? = null) = QueryBuilder
.findAllAssets(queryFilter)
.account(admin)
.buildSigned(keyPair)
.let { client.sendQuery(it) }
suspend fun findAllAssets(filter: CompoundPredicateOfAsset? = null) = client.submit(
QueryBuilder
.findAssets(filter).signAs(admin, keyPair),
)

suspend fun getAccountAmount(accountId: AccountId, assetDefinitionId: AssetDefinitionId): BigInteger =
QueryBuilder.findAssetsByAccountId(accountId)
.account(admin)
.buildSigned(keyPair)
suspend fun getAccountAmount(accountId: AccountId, assetDefinitionId: AssetDefinitionId): BigInteger {
val byAccountIdFilter = CompoundPredicateOfAsset.Atom(
AssetProjectionOfPredicateMarker.Id(
AssetIdProjectionOfPredicateMarker.Account(
AccountIdProjectionOfPredicateMarker.Atom(
AccountIdPredicateAtom.Equals(accountId),
),
),
),
)
return client.submit(QueryBuilder.findAssets(byAccountIdFilter).signAs(admin, keyPair))
.let { query ->
client.sendQuery(query).find { it.id.definition == assetDefinitionId }?.value
query.find { it.id.definition == assetDefinitionId }?.value
}.let { value ->
value?.cast<AssetValue.Numeric>()?.numeric?.mantissa
} ?: throw RuntimeException("NOT FOUND")
}
}
Loading
Loading