From d3bb0403559213a15c47781c485c45c49ed213df Mon Sep 17 00:00:00 2001 From: Andrzej Cichocki Date: Tue, 16 May 2017 11:30:50 +0100 Subject: [PATCH] Refactoring related to BFT notary demo (#680) * Fix: Add missing @StartableByRPC to fix the Raft notary demo * Make loadConfig take a Config object, for cordformation Node * Unduplicate User.toMap * Unduplicate WHITESPACE regex, choose possessive form * Use slash to make a Path * Remove Companion where redundant * Remove unused code --- .../kotlin/net/corda/kotlin/rpc/NodeConfig.kt | 6 ---- core/src/main/kotlin/net/corda/core/Utils.kt | 3 +- .../core/utilities/LegalNameValidator.kt | 4 ++- .../core/crypto/PartialMerkleTreeTest.kt | 2 +- .../net/corda/core/testing/Generators.kt | 2 +- .../corda/contracts/asset/ObligationTests.kt | 4 +-- .../kotlin/net/corda/flows/IssuerFlowTest.kt | 6 ++-- .../kotlin/net/corda/nodeapi/RPCStructures.kt | 5 +++ .../corda/nodeapi/config/ConfigParsingTest.kt | 4 +-- .../main/kotlin/net/corda/node/ArgsParser.kt | 6 ++-- .../kotlin/net/corda/node/driver/Driver.kt | 22 ++++--------- .../node/services/config/ConfigUtilities.kt | 10 +++--- .../services/config/ConfigOperatorTests.kt | 24 ++++++++++++++ .../kotlin/net/corda/attachmentdemo/Main.kt | 5 ++- samples/raft-notary-demo/build.gradle | 7 ++-- .../main/kotlin/net/corda/notarydemo/Main.kt | 7 ++-- .../kotlin/net/corda/notarydemo/NotaryDemo.kt | 32 ++----------------- .../notarydemo/flows/DummyIssueAndMove.kt | 2 ++ .../flows/RPCStartableNotaryFlowClient.kt | 8 +++++ .../main/kotlin/net/corda/traderdemo/Main.kt | 3 +- .../net/corda/testing/node/NodeBasedTest.kt | 12 +++---- .../corda/demobench/model/NetworkMapConfig.kt | 7 ++-- .../kotlin/net/corda/demobench/model/User.kt | 6 ---- 23 files changed, 86 insertions(+), 101 deletions(-) create mode 100644 node/src/test/kotlin/net/corda/node/services/config/ConfigOperatorTests.kt create mode 100644 samples/raft-notary-demo/src/main/kotlin/net/corda/notarydemo/flows/RPCStartableNotaryFlowClient.kt diff --git a/client/rpc/src/smoke-test/kotlin/net/corda/kotlin/rpc/NodeConfig.kt b/client/rpc/src/smoke-test/kotlin/net/corda/kotlin/rpc/NodeConfig.kt index 055806d4e1..75c4074be1 100644 --- a/client/rpc/src/smoke-test/kotlin/net/corda/kotlin/rpc/NodeConfig.kt +++ b/client/rpc/src/smoke-test/kotlin/net/corda/kotlin/rpc/NodeConfig.kt @@ -46,9 +46,3 @@ class NodeConfig( return if (obj == null) config else body(config, obj).atPath(path) } } - -private fun User.toMap(): Map = mapOf( - "username" to username, - "password" to password, - "permissions" to permissions -) diff --git a/core/src/main/kotlin/net/corda/core/Utils.kt b/core/src/main/kotlin/net/corda/core/Utils.kt index 6bdb45d83e..9bb01b11f9 100644 --- a/core/src/main/kotlin/net/corda/core/Utils.kt +++ b/core/src/main/kotlin/net/corda/core/Utils.kt @@ -136,7 +136,8 @@ fun ListenableFuture.toObservable(): Observable { } /** Allows you to write code like: Paths.get("someDir") / "subdir" / "filename" but using the Paths API to avoid platform separator problems. */ -operator fun Path.div(other: String): Path = resolve(other) +operator fun Path.div(other: String) = resolve(other) +operator fun String.div(other: String) = Paths.get(this) / other fun Path.createDirectory(vararg attrs: FileAttribute<*>): Path = Files.createDirectory(this, *attrs) fun Path.createDirectories(vararg attrs: FileAttribute<*>): Path = Files.createDirectories(this, *attrs) diff --git a/core/src/main/kotlin/net/corda/core/utilities/LegalNameValidator.kt b/core/src/main/kotlin/net/corda/core/utilities/LegalNameValidator.kt index 8dc0c45270..804dd4ed7a 100644 --- a/core/src/main/kotlin/net/corda/core/utilities/LegalNameValidator.kt +++ b/core/src/main/kotlin/net/corda/core/utilities/LegalNameValidator.kt @@ -24,12 +24,14 @@ fun validateLegalName(normalizedLegalName: String) { rules.forEach { it.validate(normalizedLegalName) } } +val WHITESPACE = "\\s++".toRegex() + /** * The normalize function will trim the input string, replace any multiple spaces with a single space, * and normalize the string according to NFKC normalization form. */ fun normaliseLegalName(legalName: String): String { - val trimmedLegalName = legalName.trim().replace(Regex("\\s+"), " ") + val trimmedLegalName = legalName.trim().replace(WHITESPACE, " ") return Normalizer.normalize(trimmedLegalName, Normalizer.Form.NFKC) } diff --git a/core/src/test/kotlin/net/corda/core/crypto/PartialMerkleTreeTest.kt b/core/src/test/kotlin/net/corda/core/crypto/PartialMerkleTreeTest.kt index 475bb65ee7..18d0b5923e 100644 --- a/core/src/test/kotlin/net/corda/core/crypto/PartialMerkleTreeTest.kt +++ b/core/src/test/kotlin/net/corda/core/crypto/PartialMerkleTreeTest.kt @@ -61,7 +61,7 @@ class PartialMerkleTreeTest { @Test fun `building Merkle tree - no hashes`() { - assertFailsWith { MerkleTree.Companion.getMerkleTree(emptyList()) } + assertFailsWith { MerkleTree.getMerkleTree(emptyList()) } } @Test diff --git a/core/src/test/kotlin/net/corda/core/testing/Generators.kt b/core/src/test/kotlin/net/corda/core/testing/Generators.kt index dabc585926..436ef4125e 100644 --- a/core/src/test/kotlin/net/corda/core/testing/Generators.kt +++ b/core/src/test/kotlin/net/corda/core/testing/Generators.kt @@ -71,7 +71,7 @@ class SecureHashGenerator : Generator(SecureHash::class.java) { class StateRefGenerator : Generator(StateRef::class.java) { override fun generate(random: SourceOfRandomness, status: GenerationStatus): StateRef { - return StateRef(SecureHash.Companion.sha256(random.nextBytes(16)), random.nextInt(0, 10)) + return StateRef(SecureHash.sha256(random.nextBytes(16)), random.nextInt(0, 10)) } } diff --git a/finance/src/test/kotlin/net/corda/contracts/asset/ObligationTests.kt b/finance/src/test/kotlin/net/corda/contracts/asset/ObligationTests.kt index 6e1f6514f1..2c451a085a 100644 --- a/finance/src/test/kotlin/net/corda/contracts/asset/ObligationTests.kt +++ b/finance/src/test/kotlin/net/corda/contracts/asset/ObligationTests.kt @@ -21,7 +21,7 @@ class ObligationTests { val defaultRef = OpaqueBytes(ByteArray(1, { 1 })) val defaultIssuer = MEGA_CORP.ref(defaultRef) val oneMillionDollars = 1000000.DOLLARS `issued by` defaultIssuer - val trustedCashContract = nonEmptySetOf(SecureHash.Companion.randomSHA256() as SecureHash) + val trustedCashContract = nonEmptySetOf(SecureHash.randomSHA256() as SecureHash) val megaIssuedDollars = nonEmptySetOf(Issued(defaultIssuer, USD)) val megaIssuedPounds = nonEmptySetOf(Issued(defaultIssuer, GBP)) val fivePm = TEST_TX_TIME.truncatedTo(ChronoUnit.DAYS).plus(17, ChronoUnit.HOURS) @@ -759,7 +759,7 @@ class ObligationTests { // States must not be nettable if the cash contract differs assertNotEquals(fiveKDollarsFromMegaToMega.bilateralNetState, - fiveKDollarsFromMegaToMega.copy(template = megaCorpDollarSettlement.copy(acceptableContracts = nonEmptySetOf(SecureHash.Companion.randomSHA256()))).bilateralNetState) + fiveKDollarsFromMegaToMega.copy(template = megaCorpDollarSettlement.copy(acceptableContracts = nonEmptySetOf(SecureHash.randomSHA256()))).bilateralNetState) // States must not be nettable if the trusted issuers differ val miniCorpIssuer = nonEmptySetOf(Issued(MINI_CORP.ref(1), USD)) diff --git a/finance/src/test/kotlin/net/corda/flows/IssuerFlowTest.kt b/finance/src/test/kotlin/net/corda/flows/IssuerFlowTest.kt index 52657aa6dd..1056c9ff1b 100644 --- a/finance/src/test/kotlin/net/corda/flows/IssuerFlowTest.kt +++ b/finance/src/test/kotlin/net/corda/flows/IssuerFlowTest.kt @@ -40,7 +40,7 @@ class IssuerFlowTest { bankClientNode = net.createPartyNode(notaryNode.info.address, MEGA_CORP.name) // using default IssueTo Party Reference - val issueToPartyAndRef = bankClientNode.info.legalIdentity.ref(OpaqueBytes.Companion.of(123)) + val issueToPartyAndRef = bankClientNode.info.legalIdentity.ref(OpaqueBytes.of(123)) val (issuer, issuerResult) = runIssuerAndIssueRequester(bankOfCordaNode, bankClientNode, 1000000.DOLLARS, issueToPartyAndRef) assertEquals(issuerResult.get(), issuer.get().resultFuture.get()) @@ -62,7 +62,7 @@ class IssuerFlowTest { bankOfCordaNode = net.createPartyNode(notaryNode.info.address, BOC.name) // using default IssueTo Party Reference - val issueToPartyAndRef = bankOfCordaNode.info.legalIdentity.ref(OpaqueBytes.Companion.of(123)) + val issueToPartyAndRef = bankOfCordaNode.info.legalIdentity.ref(OpaqueBytes.of(123)) val (issuer, issuerResult) = runIssuerAndIssueRequester(bankOfCordaNode, bankOfCordaNode, 1000000.DOLLARS, issueToPartyAndRef) assertEquals(issuerResult.get(), issuer.get().resultFuture.get()) @@ -80,7 +80,7 @@ class IssuerFlowTest { bankClientNode = net.createPartyNode(notaryNode.info.address, MEGA_CORP.name) // using default IssueTo Party Reference - val issueToPartyAndRef = bankClientNode.info.legalIdentity.ref(OpaqueBytes.Companion.of(123)) + val issueToPartyAndRef = bankClientNode.info.legalIdentity.ref(OpaqueBytes.of(123)) // this test exercises the Cashflow issue and move subflows to ensure consistent spending of issued states val amount = 10000.DOLLARS diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/RPCStructures.kt b/node-api/src/main/kotlin/net/corda/nodeapi/RPCStructures.kt index d7d70a5428..bda75a2bd4 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/RPCStructures.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/RPCStructures.kt @@ -18,6 +18,11 @@ data class User( val password: String, val permissions: Set) { override fun toString(): String = "${javaClass.simpleName}($username, permissions=$permissions)" + fun toMap() = mapOf( + "username" to username, + "password" to password, + "permissions" to permissions + ) } /** Records the protocol version in which this RPC was added. */ diff --git a/node-api/src/test/kotlin/net/corda/nodeapi/config/ConfigParsingTest.kt b/node-api/src/test/kotlin/net/corda/nodeapi/config/ConfigParsingTest.kt index addad4367a..3a09140194 100644 --- a/node-api/src/test/kotlin/net/corda/nodeapi/config/ConfigParsingTest.kt +++ b/node-api/src/test/kotlin/net/corda/nodeapi/config/ConfigParsingTest.kt @@ -12,12 +12,10 @@ import org.bouncycastle.asn1.x500.X500Name import org.junit.Test import java.net.URL import java.nio.file.Path -import java.nio.file.Paths import java.time.Instant import java.time.LocalDate import java.util.* import kotlin.reflect.full.primaryConstructor -import kotlin.test.assertEquals class ConfigParsingTest { @Test @@ -70,7 +68,7 @@ class ConfigParsingTest { @Test fun `Path`() { - val path = Paths.get("tmp") / "test" + val path = "tmp" / "test" testPropertyType(path, path / "file", valuesToString = true) } diff --git a/node/src/main/kotlin/net/corda/node/ArgsParser.kt b/node/src/main/kotlin/net/corda/node/ArgsParser.kt index 6292608493..6168e4b99b 100644 --- a/node/src/main/kotlin/net/corda/node/ArgsParser.kt +++ b/node/src/main/kotlin/net/corda/node/ArgsParser.kt @@ -65,9 +65,7 @@ data class CmdLineOptions(val baseDirectory: Path, val isVersion: Boolean, val noLocalShell: Boolean, val sshdServer: Boolean) { - fun loadConfig(allowMissingConfig: Boolean = false, configOverrides: Map = emptyMap()): FullNodeConfiguration { - return ConfigHelper - .loadConfig(baseDirectory, configFile, allowMissingConfig, configOverrides) + fun loadConfig() = ConfigHelper + .loadConfig(baseDirectory, configFile) .parseAs() - } } diff --git a/node/src/main/kotlin/net/corda/node/driver/Driver.kt b/node/src/main/kotlin/net/corda/node/driver/Driver.kt index d2a9f3f2a1..af4e6b01dc 100644 --- a/node/src/main/kotlin/net/corda/node/driver/Driver.kt +++ b/node/src/main/kotlin/net/corda/node/driver/Driver.kt @@ -18,9 +18,7 @@ import net.corda.core.node.services.ServiceInfo import net.corda.core.node.services.ServiceType import net.corda.core.utilities.* import net.corda.node.LOGS_DIRECTORY_NAME -import net.corda.node.services.config.ConfigHelper -import net.corda.node.services.config.FullNodeConfiguration -import net.corda.node.services.config.VerifierType +import net.corda.node.services.config.* import net.corda.node.services.network.NetworkMapService import net.corda.node.services.transactions.RaftValidatingNotaryService import net.corda.node.utilities.ServiceIdentityGenerator @@ -491,9 +489,9 @@ class DriverDSL( val webAddress = portAllocation.nextHostAndPort() val debugPort = if (isDebug) debugPortAllocation.nextPort() else null // TODO: Derive name from the full picked name, don't just wrap the common name - val name = providedName ?: X509Utilities.getDevX509Name("${pickA(name).commonName}-${p2pAddress.port}") + val name = providedName ?: X509Utilities.getDevX509Name("${oneOf(names).commonName}-${p2pAddress.port}") val baseDirectory = driverDirectory / name.commonName - val configOverrides = mapOf( + val configOverrides = configOf( "myLegalName" to name.toString(), "p2pAddress" to p2pAddress.toString(), "rpcAddress" to rpcAddress.toString(), @@ -511,13 +509,7 @@ class DriverDSL( } }, "useTestClock" to useTestClock, - "rpcUsers" to rpcUsers.map { - mapOf( - "username" to it.username, - "password" to it.password, - "permissions" to it.permissions - ) - }, + "rpcUsers" to rpcUsers.map { it.toMap() }, "verifierType" to verifierType.name ) + customOverrides @@ -612,7 +604,7 @@ class DriverDSL( val config = ConfigHelper.loadConfig( baseDirectory = baseDirectory, allowMissingConfig = true, - configOverrides = mapOf( + configOverrides = configOf( "myLegalName" to dedicatedNetworkMapLegalName.toString(), // TODO: remove the webAddress as NMS doesn't need to run a web server. This will cause all // node port numbers to be shifted, so all demos and docs need to be updated accordingly. @@ -635,13 +627,13 @@ class DriverDSL( } companion object { - val name = arrayOf( + private val names = arrayOf( ALICE.name, BOB.name, DUMMY_BANK_A.name ) - fun pickA(array: Array): A = array[Math.abs(Random().nextInt()) % array.size] + private fun oneOf(array: Array) = array[Random().nextInt(array.size)] private fun startNode( executorService: ListeningScheduledExecutorService, diff --git a/node/src/main/kotlin/net/corda/node/services/config/ConfigUtilities.kt b/node/src/main/kotlin/net/corda/node/services/config/ConfigUtilities.kt index 8eea06c609..ded16966be 100644 --- a/node/src/main/kotlin/net/corda/node/services/config/ConfigUtilities.kt +++ b/node/src/main/kotlin/net/corda/node/services/config/ConfigUtilities.kt @@ -18,21 +18,23 @@ import net.corda.nodeapi.config.SSLConfiguration import org.bouncycastle.asn1.x500.X500Name import java.nio.file.Path +fun configOf(vararg pairs: Pair) = ConfigFactory.parseMap(mapOf(*pairs)) +operator fun Config.plus(overrides: Map) = ConfigFactory.parseMap(overrides).withFallback(this) + object ConfigHelper { private val log = loggerFor() fun loadConfig(baseDirectory: Path, configFile: Path = baseDirectory / "node.conf", allowMissingConfig: Boolean = false, - configOverrides: Map = emptyMap()): Config { + configOverrides: Config = ConfigFactory.empty()): Config { val parseOptions = ConfigParseOptions.defaults() val defaultConfig = ConfigFactory.parseResources("reference.conf", parseOptions.setAllowMissing(false)) val appConfig = ConfigFactory.parseFile(configFile.toFile(), parseOptions.setAllowMissing(allowMissingConfig)) - val overrideConfig = ConfigFactory.parseMap(configOverrides + mapOf( + val finalConfig = configOf( // Add substitution values here "basedir" to baseDirectory.toString()) - ) - val finalConfig = overrideConfig + .withFallback(configOverrides) .withFallback(appConfig) .withFallback(defaultConfig) .resolve() diff --git a/node/src/test/kotlin/net/corda/node/services/config/ConfigOperatorTests.kt b/node/src/test/kotlin/net/corda/node/services/config/ConfigOperatorTests.kt new file mode 100644 index 0000000000..92f7340b16 --- /dev/null +++ b/node/src/test/kotlin/net/corda/node/services/config/ConfigOperatorTests.kt @@ -0,0 +1,24 @@ +package net.corda.node.services.config + +import com.typesafe.config.ConfigFactory +import net.corda.nodeapi.config.toProperties +import org.junit.Test +import kotlin.test.assertEquals + +class ConfigOperatorTests { + + @Test + fun `config plus behaves the same as map plus`() { + val config = arrayOf("x" to "y1", "a" to "b", "z" to "Z") + val overrides = arrayOf("x" to "y2", "c" to "d", "z" to null) + val old = ConfigFactory.parseMap(mapOf(*config) + mapOf(*overrides)) + val new = configOf(*config) + mapOf(*overrides) + listOf(old, new).map { it.toProperties() }.forEach { c -> + assertEquals("y2", c["x"]) + assertEquals("b", c["a"]) + assertEquals("d", c["c"]) + assertEquals(null, c["z"]) + } + } + +} diff --git a/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/Main.kt b/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/Main.kt index ec1c836120..9e7485eda3 100644 --- a/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/Main.kt +++ b/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/Main.kt @@ -8,7 +8,6 @@ import net.corda.core.utilities.DUMMY_NOTARY import net.corda.node.driver.driver import net.corda.node.services.transactions.SimpleNotaryService import net.corda.nodeapi.User -import java.nio.file.Paths /** * This file is exclusively for being able to run your nodes through an IDE (as opposed to running deployNodes) @@ -16,8 +15,8 @@ import java.nio.file.Paths */ fun main(args: Array) { val demoUser = listOf(User("demo", "demo", setOf("StartFlow.net.corda.flows.FinalityFlow"))) - driver(isDebug = true, driverDirectory = Paths.get("build") / "attachment-demo-nodes") { - startNode(DUMMY_NOTARY.name, setOf(ServiceInfo(SimpleNotaryService.Companion.type))) + driver(isDebug = true, driverDirectory = "build" / "attachment-demo-nodes") { + startNode(DUMMY_NOTARY.name, setOf(ServiceInfo(SimpleNotaryService.type))) startNode(DUMMY_BANK_A.name, rpcUsers = demoUser) startNode(DUMMY_BANK_B.name, rpcUsers = demoUser) waitForAllNodesToFinish() diff --git a/samples/raft-notary-demo/build.gradle b/samples/raft-notary-demo/build.gradle index b2348d8940..dada41b57b 100644 --- a/samples/raft-notary-demo/build.gradle +++ b/samples/raft-notary-demo/build.gradle @@ -1,3 +1,5 @@ +import net.corda.plugins.Cordform + apply plugin: 'java' apply plugin: 'kotlin' apply plugin: 'idea' @@ -68,7 +70,7 @@ task generateNotaryIdentity(type: JavaExec, dependsOn: 'cleanNodes') { args = [nodeDirs, notaryType, notaryName] } -task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar', 'generateNotaryIdentity']) { +task deployNodes(type: Cordform, dependsOn: ['jar', generateNotaryIdentity]) { directory deployTo networkMap "CN=Notary 1,O=R3,OU=corda,L=London,C=UK" node { @@ -80,7 +82,7 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar', 'generateN cordapps = [] rpcUsers = [['username': "demo", 'password': "demo", 'permissions': [ 'StartFlow.net.corda.notarydemo.flows.DummyIssueAndMove', - 'StartFlow.net.corda.flows.NotaryFlow$Client' + 'StartFlow.net.corda.notarydemo.flows.RPCStartableNotaryFlowClient' ]]] } node { @@ -126,4 +128,3 @@ task notarise(type: JavaExec) { classpath = sourceSets.main.runtimeClasspath main = 'net.corda.notarydemo.NotaryDemoKt' } - diff --git a/samples/raft-notary-demo/src/main/kotlin/net/corda/notarydemo/Main.kt b/samples/raft-notary-demo/src/main/kotlin/net/corda/notarydemo/Main.kt index 2ecda145e9..56196a625f 100644 --- a/samples/raft-notary-demo/src/main/kotlin/net/corda/notarydemo/Main.kt +++ b/samples/raft-notary-demo/src/main/kotlin/net/corda/notarydemo/Main.kt @@ -6,7 +6,6 @@ import net.corda.core.div import net.corda.core.utilities.ALICE import net.corda.core.utilities.BOB import net.corda.core.utilities.DUMMY_NOTARY -import net.corda.flows.NotaryFlow import net.corda.node.driver.NetworkMapStartStrategy import net.corda.node.driver.PortAllocation import net.corda.node.driver.driver @@ -14,14 +13,14 @@ import net.corda.node.services.startFlowPermission import net.corda.node.services.transactions.RaftValidatingNotaryService import net.corda.nodeapi.User import net.corda.notarydemo.flows.DummyIssueAndMove +import net.corda.notarydemo.flows.RPCStartableNotaryFlowClient import org.bouncycastle.asn1.x500.X500Name -import java.nio.file.Paths /** Creates and starts all nodes required for the demo. */ fun main(args: Array) { - val demoUser = listOf(User("demo", "demo", setOf(startFlowPermission(), startFlowPermission()))) + val demoUser = listOf(User("demo", "demo", setOf(startFlowPermission(), startFlowPermission()))) val networkMap = NetworkMapStartStrategy.Nominated(DUMMY_NOTARY.name.appendToCommonName("1"), HostAndPort.fromParts("localhost", 10009)) - driver(isDebug = true, driverDirectory = Paths.get("build") / "notary-demo-nodes", networkMapStartStrategy = networkMap, portAllocation = PortAllocation.Incremental(10001)) { + driver(isDebug = true, driverDirectory = "build" / "notary-demo-nodes", networkMapStartStrategy = networkMap, portAllocation = PortAllocation.Incremental(10001)) { startNode(ALICE.name, rpcUsers = demoUser) startNode(BOB.name) startNotaryCluster(X500Name("CN=Raft,O=R3,OU=corda,L=Zurich,C=CH"), clusterSize = 3, type = RaftValidatingNotaryService.type) diff --git a/samples/raft-notary-demo/src/main/kotlin/net/corda/notarydemo/NotaryDemo.kt b/samples/raft-notary-demo/src/main/kotlin/net/corda/notarydemo/NotaryDemo.kt index 7136c0685a..ccbdc5b6bf 100644 --- a/samples/raft-notary-demo/src/main/kotlin/net/corda/notarydemo/NotaryDemo.kt +++ b/samples/raft-notary-demo/src/main/kotlin/net/corda/notarydemo/NotaryDemo.kt @@ -2,23 +2,16 @@ package net.corda.notarydemo import com.google.common.net.HostAndPort import com.google.common.util.concurrent.Futures -import joptsimple.OptionParser import net.corda.client.rpc.CordaRPCClient import net.corda.client.rpc.notUsed import net.corda.core.crypto.toStringShort -import net.corda.core.div import net.corda.core.getOrThrow import net.corda.core.messaging.CordaRPCOps import net.corda.core.messaging.startFlow import net.corda.core.transactions.SignedTransaction import net.corda.core.utilities.BOB -import net.corda.flows.NotaryFlow -import net.corda.nodeapi.config.SSLConfiguration import net.corda.notarydemo.flows.DummyIssueAndMove -import org.bouncycastle.asn1.x500.X500Name -import java.nio.file.Path -import java.nio.file.Paths -import kotlin.system.exitProcess +import net.corda.notarydemo.flows.RPCStartableNotaryFlowClient fun main(args: Array) { val host = HostAndPort.fromString("localhost:10003") @@ -85,28 +78,7 @@ private class NotaryDemoClientApi(val rpc: CordaRPCOps) { private fun notariseTransactions(transactions: List): List { // TODO: Remove this suppress when we upgrade to kotlin 1.1 or when JetBrain fixes the bug. @Suppress("UNSUPPORTED_FEATURE") - val signatureFutures = transactions.map { rpc.startFlow(NotaryFlow::Client, it).returnValue } + val signatureFutures = transactions.map { rpc.startFlow(::RPCStartableNotaryFlowClient, it).returnValue } return Futures.allAsList(signatureFutures).getOrThrow().map { it.map { it.by.toStringShort() }.joinToString() } } } - -private fun getCertPath(args: Array): String? { - val parser = OptionParser() - val certsPath = parser.accepts("certificates").withRequiredArg() - val options = try { - parser.parse(*args) - } catch (e: Exception) { - println(e.message) - exitProcess(1) - } - return options.valueOf(certsPath) -} - -// TODO: Take this out once we have a dedicated RPC port and allow SSL on it to be optional. -private fun sslConfigFor(nodename: String, certsPath: String?): SSLConfiguration { - return object : SSLConfiguration { - override val keyStorePassword: String = "cordacadevpass" - override val trustStorePassword: String = "trustpass" - override val certificatesDirectory: Path = if (certsPath != null) Paths.get(certsPath) else Paths.get("build") / "nodes" / nodename / "certificates" - } -} diff --git a/samples/raft-notary-demo/src/main/kotlin/net/corda/notarydemo/flows/DummyIssueAndMove.kt b/samples/raft-notary-demo/src/main/kotlin/net/corda/notarydemo/flows/DummyIssueAndMove.kt index 103d2fe57c..11b4fd12b3 100644 --- a/samples/raft-notary-demo/src/main/kotlin/net/corda/notarydemo/flows/DummyIssueAndMove.kt +++ b/samples/raft-notary-demo/src/main/kotlin/net/corda/notarydemo/flows/DummyIssueAndMove.kt @@ -4,9 +4,11 @@ import co.paralleluniverse.fibers.Suspendable import net.corda.core.contracts.DummyContract import net.corda.core.identity.Party import net.corda.core.flows.FlowLogic +import net.corda.core.flows.StartableByRPC import net.corda.core.transactions.SignedTransaction import java.util.* +@StartableByRPC class DummyIssueAndMove(private val notary: Party, private val counterpartyNode: Party) : FlowLogic() { @Suspendable override fun call(): SignedTransaction { diff --git a/samples/raft-notary-demo/src/main/kotlin/net/corda/notarydemo/flows/RPCStartableNotaryFlowClient.kt b/samples/raft-notary-demo/src/main/kotlin/net/corda/notarydemo/flows/RPCStartableNotaryFlowClient.kt new file mode 100644 index 0000000000..a3d16c4984 --- /dev/null +++ b/samples/raft-notary-demo/src/main/kotlin/net/corda/notarydemo/flows/RPCStartableNotaryFlowClient.kt @@ -0,0 +1,8 @@ +package net.corda.notarydemo.flows + +import net.corda.core.flows.StartableByRPC +import net.corda.core.transactions.SignedTransaction +import net.corda.flows.NotaryFlow + +@StartableByRPC +class RPCStartableNotaryFlowClient(stx: SignedTransaction) : NotaryFlow.Client(stx) diff --git a/samples/trader-demo/src/main/kotlin/net/corda/traderdemo/Main.kt b/samples/trader-demo/src/main/kotlin/net/corda/traderdemo/Main.kt index a5af0ab52c..1660ae7bfa 100644 --- a/samples/trader-demo/src/main/kotlin/net/corda/traderdemo/Main.kt +++ b/samples/trader-demo/src/main/kotlin/net/corda/traderdemo/Main.kt @@ -11,7 +11,6 @@ import net.corda.node.services.startFlowPermission import net.corda.node.services.transactions.SimpleNotaryService import net.corda.nodeapi.User import net.corda.testing.BOC -import java.nio.file.Paths /** * This file is exclusively for being able to run your nodes through an IDE (as opposed to running deployNodes) @@ -22,7 +21,7 @@ fun main(args: Array) { startFlowPermission(), startFlowPermission()) val demoUser = listOf(User("demo", "demo", permissions)) - driver(driverDirectory = Paths.get("build") / "trader-demo-nodes", isDebug = true) { + driver(driverDirectory = "build" / "trader-demo-nodes", isDebug = true) { val user = User("user1", "test", permissions = setOf(startFlowPermission())) startNode(DUMMY_NOTARY.name, setOf(ServiceInfo(SimpleNotaryService.type))) startNode(DUMMY_BANK_A.name, rpcUsers = demoUser) diff --git a/test-utils/src/main/kotlin/net/corda/testing/node/NodeBasedTest.kt b/test-utils/src/main/kotlin/net/corda/testing/node/NodeBasedTest.kt index cf93e05ebe..0d58b85366 100644 --- a/test-utils/src/main/kotlin/net/corda/testing/node/NodeBasedTest.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/node/NodeBasedTest.kt @@ -12,6 +12,8 @@ import net.corda.node.driver.addressMustNotBeBound import net.corda.node.internal.Node import net.corda.node.services.config.ConfigHelper import net.corda.node.services.config.FullNodeConfiguration +import net.corda.node.services.config.configOf +import net.corda.node.services.config.plus import net.corda.node.services.transactions.RaftValidatingNotaryService import net.corda.node.utilities.ServiceIdentityGenerator import net.corda.nodeapi.User @@ -141,18 +143,12 @@ abstract class NodeBasedTest { val config = ConfigHelper.loadConfig( baseDirectory = baseDirectory, allowMissingConfig = true, - configOverrides = mapOf( + configOverrides = configOf( "myLegalName" to legalName.toString(), "p2pAddress" to localPort[0].toString(), "rpcAddress" to localPort[1].toString(), "extraAdvertisedServiceIds" to advertisedServices.map { it.toString() }, - "rpcUsers" to rpcUsers.map { - mapOf( - "username" to it.username, - "password" to it.password, - "permissions" to it.permissions - ) - } + "rpcUsers" to rpcUsers.map { it.toMap() } ) + configOverrides ) diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NetworkMapConfig.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NetworkMapConfig.kt index bd08931e76..9aef0146f8 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NetworkMapConfig.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NetworkMapConfig.kt @@ -1,6 +1,7 @@ package net.corda.demobench.model import net.corda.core.crypto.commonName +import net.corda.core.utilities.WHITESPACE import org.bouncycastle.asn1.x500.X500Name open class NetworkMapConfig(val legalName: X500Name, val p2pPort: Int) { @@ -9,7 +10,5 @@ open class NetworkMapConfig(val legalName: X500Name, val p2pPort: Int) { } -private val WHITESPACE = "\\s++".toRegex() - -fun String.stripWhitespace() = this.replace(WHITESPACE, "") -fun String.toKey() = this.stripWhitespace().toLowerCase() +fun String.stripWhitespace() = replace(WHITESPACE, "") +fun String.toKey() = stripWhitespace().toLowerCase() diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/User.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/User.kt index 7c821b65b0..aadbeb7e06 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/model/User.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/User.kt @@ -5,12 +5,6 @@ package net.corda.demobench.model import net.corda.nodeapi.User import java.util.* -fun User.toMap(): Map = mapOf( - "username" to username, - "password" to password, - "permissions" to permissions -) - @Suppress("UNCHECKED_CAST") fun toUser(map: Map) = User( map.getOrElse("username", { "none" }) as String,