diff --git a/client/jfx/src/main/kotlin/net/corda/client/jfx/model/TransactionDataModel.kt b/client/jfx/src/main/kotlin/net/corda/client/jfx/model/TransactionDataModel.kt index 4a709616f1..9e0cc1e6e9 100644 --- a/client/jfx/src/main/kotlin/net/corda/client/jfx/model/TransactionDataModel.kt +++ b/client/jfx/src/main/kotlin/net/corda/client/jfx/model/TransactionDataModel.kt @@ -30,9 +30,13 @@ data class PartiallyResolvedTransaction( val inputs: List>) { val id = transaction.id - sealed class InputResolution(val stateRef: StateRef) { - class Unresolved(stateRef: StateRef) : InputResolution(stateRef) - class Resolved(val stateAndRef: StateAndRef) : InputResolution(stateAndRef.ref) + sealed class InputResolution { + abstract val stateRef: StateRef + + data class Unresolved(override val stateRef: StateRef) : InputResolution() + data class Resolved(val stateAndRef: StateAndRef) : InputResolution() { + override val stateRef: StateRef get() = stateAndRef.ref + } } companion object { @@ -54,22 +58,13 @@ data class PartiallyResolvedTransaction( } } -sealed class TransactionCreateStatus(val message: String?) { - class Started(message: String?) : TransactionCreateStatus(message) - class Failed(message: String?) : TransactionCreateStatus(message) +data class FlowStatus(val status: String) - override fun toString(): String = message ?: javaClass.simpleName -} +sealed class StateMachineStatus { + abstract val stateMachineName: String -data class FlowStatus( - val status: String -) - -sealed class StateMachineStatus(val stateMachineName: String) { - class Added(stateMachineName: String) : StateMachineStatus(stateMachineName) - class Removed(stateMachineName: String) : StateMachineStatus(stateMachineName) - - override fun toString(): String = "${javaClass.simpleName}($stateMachineName)" + data class Added(override val stateMachineName: String) : StateMachineStatus() + data class Removed(override val stateMachineName: String) : StateMachineStatus() } data class StateMachineData( diff --git a/core/src/main/kotlin/net/corda/core/contracts/TransactionTypes.kt b/core/src/main/kotlin/net/corda/core/contracts/TransactionTypes.kt index e1539781a9..a6185a43de 100644 --- a/core/src/main/kotlin/net/corda/core/contracts/TransactionTypes.kt +++ b/core/src/main/kotlin/net/corda/core/contracts/TransactionTypes.kt @@ -9,9 +9,6 @@ import net.corda.core.transactions.TransactionBuilder /** Defines transaction build & validation logic for a specific transaction type */ @CordaSerializable sealed class TransactionType { - override fun equals(other: Any?) = other?.javaClass == javaClass - override fun hashCode() = javaClass.name.hashCode() - /** * Check that the transaction is valid based on: * - General platform rules @@ -63,9 +60,9 @@ sealed class TransactionType { abstract fun verifyTransaction(tx: LedgerTransaction) /** A general transaction type where transaction validity is determined by custom contract code */ - class General : TransactionType() { + object General : TransactionType() { /** Just uses the default [TransactionBuilder] with no special logic */ - class Builder(notary: Party?) : TransactionBuilder(General(), notary) {} + class Builder(notary: Party?) : TransactionBuilder(General, notary) override fun verifyTransaction(tx: LedgerTransaction) { verifyNoNotaryChange(tx) @@ -141,12 +138,12 @@ sealed class TransactionType { * A special transaction type for reassigning a notary for a state. Validation does not involve running * any contract code, it just checks that the states are unmodified apart from the notary field. */ - class NotaryChange : TransactionType() { + object NotaryChange : TransactionType() { /** * A transaction builder that automatically sets the transaction type to [NotaryChange] * and adds the list of participants to the signers set for every input state. */ - class Builder(notary: Party) : TransactionBuilder(NotaryChange(), notary) { + class Builder(notary: Party) : TransactionBuilder(NotaryChange, notary) { override fun addInputState(stateAndRef: StateAndRef<*>) { signers.addAll(stateAndRef.state.data.participants) super.addInputState(stateAndRef) diff --git a/core/src/main/kotlin/net/corda/core/crypto/CompositeKey.kt b/core/src/main/kotlin/net/corda/core/crypto/CompositeKey.kt index a6f352503f..ed312e4e59 100644 --- a/core/src/main/kotlin/net/corda/core/crypto/CompositeKey.kt +++ b/core/src/main/kotlin/net/corda/core/crypto/CompositeKey.kt @@ -47,18 +47,10 @@ sealed class CompositeKey { } /** The leaf node of the tree – a wrapper around a [PublicKey] primitive */ - class Leaf(val publicKey: PublicKey) : CompositeKey() { + data class Leaf(val publicKey: PublicKey) : CompositeKey() { override fun isFulfilledBy(keys: Iterable) = publicKey in keys - override val keys: Set - get() = setOf(publicKey) - - // TODO: remove once data class inheritance is enabled - override fun equals(other: Any?): Boolean { - return this === other || other is Leaf && other.publicKey == this.publicKey - } - - override fun hashCode() = publicKey.hashCode() + override val keys: Set get() = setOf(publicKey) override fun toString() = publicKey.toStringShort() } @@ -70,10 +62,7 @@ sealed class CompositeKey { * The [threshold] specifies the minimum total weight required (in the simple case – the minimum number of child * signatures required) to satisfy the sub-tree rooted at this node. */ - class Node(val threshold: Int, - val children: List, - val weights: List) : CompositeKey() { - + data class Node(val threshold: Int, val children: List, val weights: List) : CompositeKey() { override fun isFulfilledBy(keys: Iterable): Boolean { val totalWeight = children.mapIndexed { i, childNode -> if (childNode.isFulfilledBy(keys)) weights[i] else 0 @@ -82,35 +71,13 @@ sealed class CompositeKey { return totalWeight >= threshold } - override val keys: Set - get() = children.flatMap { it.keys }.toSet() - - // Auto-generated. TODO: remove once data class inheritance is enabled - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other?.javaClass != javaClass) return false - - other as Node - - if (threshold != other.threshold) return false - if (weights != other.weights) return false - if (children != other.children) return false - - return true - } - - override fun hashCode(): Int { - var result = threshold - result = 31 * result + weights.hashCode() - result = 31 * result + children.hashCode() - return result - } + override val keys: Set get() = children.flatMap { it.keys }.toSet() override fun toString() = "(${children.joinToString()})" } /** A helper class for building a [CompositeKey.Node]. */ - class Builder() { + class Builder { private val children: MutableList = mutableListOf() private val weights: MutableList = mutableListOf() diff --git a/core/src/main/kotlin/net/corda/core/crypto/MerkleTree.kt b/core/src/main/kotlin/net/corda/core/crypto/MerkleTree.kt index 85e6911f8d..3e234ec3cf 100644 --- a/core/src/main/kotlin/net/corda/core/crypto/MerkleTree.kt +++ b/core/src/main/kotlin/net/corda/core/crypto/MerkleTree.kt @@ -11,9 +11,11 @@ import java.util.* * signers, tx type, timestamp. Merkle Tree is kept in a recursive data structure. Building is done bottom up, * from all leaves' hashes. If number of leaves is not a power of two, the tree is padded with zero hashes. */ -sealed class MerkleTree(val hash: SecureHash) { - class Leaf(val value: SecureHash) : MerkleTree(value) - class Node(val value: SecureHash, val left: MerkleTree, val right: MerkleTree) : MerkleTree(value) +sealed class MerkleTree { + abstract val hash: SecureHash + + data class Leaf(override val hash: SecureHash) : MerkleTree() + data class Node(override val hash: SecureHash, val left: MerkleTree, val right: MerkleTree) : MerkleTree() companion object { private fun isPow2(num: Int): Boolean = num and (num-1) == 0 diff --git a/core/src/main/kotlin/net/corda/core/crypto/PartialMerkleTree.kt b/core/src/main/kotlin/net/corda/core/crypto/PartialMerkleTree.kt index c7193ce8da..17caec2af2 100644 --- a/core/src/main/kotlin/net/corda/core/crypto/PartialMerkleTree.kt +++ b/core/src/main/kotlin/net/corda/core/crypto/PartialMerkleTree.kt @@ -54,9 +54,9 @@ class PartialMerkleTree(val root: PartialTree) { */ @CordaSerializable sealed class PartialTree { - class IncludedLeaf(val hash: SecureHash) : PartialTree() - class Leaf(val hash: SecureHash) : PartialTree() - class Node(val left: PartialTree, val right: PartialTree) : PartialTree() + data class IncludedLeaf(val hash: SecureHash) : PartialTree() + data class Leaf(val hash: SecureHash) : PartialTree() + data class Node(val left: PartialTree, val right: PartialTree) : PartialTree() } companion object { @@ -104,10 +104,10 @@ class PartialMerkleTree(val root: PartialTree) { ): Pair { return when (root) { is MerkleTree.Leaf -> - if (root.value in includeHashes) { - usedHashes.add(root.value) - Pair(true, PartialTree.IncludedLeaf(root.value)) - } else Pair(false, PartialTree.Leaf(root.value)) + if (root.hash in includeHashes) { + usedHashes.add(root.hash) + Pair(true, PartialTree.IncludedLeaf(root.hash)) + } else Pair(false, PartialTree.Leaf(root.hash)) is MerkleTree.Node -> { val leftNode = buildPartialTree(root.left, includeHashes, usedHashes) val rightNode = buildPartialTree(root.right, includeHashes, usedHashes) @@ -117,7 +117,7 @@ class PartialMerkleTree(val root: PartialTree) { Pair(true, newTree) } else { // This node has no included leaves below. Cut the tree here and store a hash as a Leaf. - val newTree = PartialTree.Leaf(root.value) + val newTree = PartialTree.Leaf(root.hash) Pair(false, newTree) } } diff --git a/core/src/main/kotlin/net/corda/core/crypto/SecureHash.kt b/core/src/main/kotlin/net/corda/core/crypto/SecureHash.kt index 36c2f22cb6..ee8f4a5afe 100644 --- a/core/src/main/kotlin/net/corda/core/crypto/SecureHash.kt +++ b/core/src/main/kotlin/net/corda/core/crypto/SecureHash.kt @@ -18,7 +18,7 @@ sealed class SecureHash(bytes: ByteArray) : OpaqueBytes(bytes) { } } - override fun toString() = BaseEncoding.base16().encode(bytes) + override fun toString(): String = BaseEncoding.base16().encode(bytes) fun prefixChars(prefixLen: Int = 6) = toString().substring(0, prefixLen) fun hashConcat(other: SecureHash) = (this.bytes + other.bytes).sha256() diff --git a/core/src/main/kotlin/net/corda/core/messaging/CordaRPCOps.kt b/core/src/main/kotlin/net/corda/core/messaging/CordaRPCOps.kt index 53be1a1485..32944e2679 100644 --- a/core/src/main/kotlin/net/corda/core/messaging/CordaRPCOps.kt +++ b/core/src/main/kotlin/net/corda/core/messaging/CordaRPCOps.kt @@ -26,17 +26,19 @@ data class StateMachineInfo( val id: StateMachineRunId, val flowLogicClassName: String, val progressTrackerStepAndUpdates: Pair>? -) +) { + override fun toString(): String = "${javaClass.simpleName}($id, $flowLogicClassName)" +} @CordaSerializable -sealed class StateMachineUpdate(val id: StateMachineRunId) { - class Added(val stateMachineInfo: StateMachineInfo) : StateMachineUpdate(stateMachineInfo.id) { - override fun toString() = "Added($id, ${stateMachineInfo.flowLogicClassName})" +sealed class StateMachineUpdate { + abstract val id: StateMachineRunId + + data class Added(val stateMachineInfo: StateMachineInfo) : StateMachineUpdate() { + override val id: StateMachineRunId get() = stateMachineInfo.id } - class Removed(id: StateMachineRunId) : StateMachineUpdate(id) { - override fun toString() = "Removed($id)" - } + data class Removed(override val id: StateMachineRunId) : StateMachineUpdate() } /** diff --git a/core/src/main/kotlin/net/corda/core/node/services/NetworkMapCache.kt b/core/src/main/kotlin/net/corda/core/node/services/NetworkMapCache.kt index 8e07ec5fed..7189372b89 100644 --- a/core/src/main/kotlin/net/corda/core/node/services/NetworkMapCache.kt +++ b/core/src/main/kotlin/net/corda/core/node/services/NetworkMapCache.kt @@ -21,10 +21,12 @@ import rx.Observable interface NetworkMapCache { @CordaSerializable - sealed class MapChange(val node: NodeInfo) { - class Added(node: NodeInfo) : MapChange(node) - class Removed(node: NodeInfo) : MapChange(node) - class Modified(node: NodeInfo, val previousNode: NodeInfo) : MapChange(node) + sealed class MapChange { + abstract val node: NodeInfo + + data class Added(override val node: NodeInfo) : MapChange() + data class Removed(override val node: NodeInfo) : MapChange() + data class Modified(override val node: NodeInfo, val previousNode: NodeInfo) : MapChange() } /** A list of all nodes the cache is aware of */ diff --git a/core/src/main/kotlin/net/corda/core/node/services/PartyInfo.kt b/core/src/main/kotlin/net/corda/core/node/services/PartyInfo.kt index b34086992a..97c7626fbd 100644 --- a/core/src/main/kotlin/net/corda/core/node/services/PartyInfo.kt +++ b/core/src/main/kotlin/net/corda/core/node/services/PartyInfo.kt @@ -7,12 +7,13 @@ import net.corda.core.node.ServiceEntry /** * Holds information about a [Party], which may refer to either a specific node or a service. */ -sealed class PartyInfo() { +sealed class PartyInfo { abstract val party: Party - class Node(val node: NodeInfo) : PartyInfo() { - override val party = node.legalIdentity + + data class Node(val node: NodeInfo) : PartyInfo() { + override val party get() = node.legalIdentity } - class Service(val service: ServiceEntry) : PartyInfo() { - override val party = service.identity + data class Service(val service: ServiceEntry) : PartyInfo() { + override val party get() = service.identity } } \ No newline at end of file diff --git a/core/src/main/kotlin/net/corda/core/node/services/ServiceType.kt b/core/src/main/kotlin/net/corda/core/node/services/ServiceType.kt index fc89811657..80111a3cdb 100644 --- a/core/src/main/kotlin/net/corda/core/node/services/ServiceType.kt +++ b/core/src/main/kotlin/net/corda/core/node/services/ServiceType.kt @@ -8,7 +8,7 @@ import net.corda.core.serialization.CordaSerializable * don't need a declared service type. */ @CordaSerializable -sealed class ServiceType(val id: String) { +class ServiceType private constructor(val id: String) { init { // Enforce: // @@ -16,9 +16,6 @@ sealed class ServiceType(val id: String) { // * IDs can only contain alphanumeric, full stop and underscore ASCII characters require(id.matches(Regex("[a-z][a-zA-Z0-9._]+"))) { id } } - private class ServiceTypeImpl(baseId: String, subTypeId: String) : ServiceType("$baseId.$subTypeId") - - private class ServiceTypeDirect(id: String) : ServiceType(id) companion object { val corda: ServiceType @@ -26,7 +23,7 @@ sealed class ServiceType(val id: String) { val stack = Throwable().stackTrace val caller = stack.first().className require(caller.startsWith("net.corda.")) { "Corda ServiceType namespace is reserved for Corda core components" } - return ServiceTypeDirect("corda") + return ServiceType("corda") } val notary: ServiceType = corda.getSubType("notary") @@ -35,21 +32,22 @@ sealed class ServiceType(val id: String) { fun getServiceType(namespace: String, typeId: String): ServiceType { require(!namespace.startsWith("corda")) { "Corda namespace is protected" } - return ServiceTypeImpl(namespace, typeId) + return baseWithSubType(namespace, typeId) } - fun parse(id: String): ServiceType = ServiceTypeDirect(id) + fun parse(id: String): ServiceType = ServiceType(id) + + private fun baseWithSubType(baseId: String, subTypeId: String) = ServiceType("$baseId.$subTypeId") } - fun getSubType(subTypeId: String): ServiceType = ServiceTypeImpl(id, subTypeId) - - override operator fun equals(other: Any?): Boolean = (other is ServiceType) && (other.id == this.id) + fun getSubType(subTypeId: String): ServiceType = baseWithSubType(id, subTypeId) fun isSubTypeOf(superType: ServiceType) = (id == superType.id) || id.startsWith(superType.id + ".") fun isNotary() = isSubTypeOf(notary) fun isValidatingNotary() = isNotary() && id.contains(".validating") fun isNetworkMap() = id == networkMap.id + override fun equals(other: Any?): Boolean = other === this || other is ServiceType && other.id == this.id override fun hashCode(): Int = id.hashCode() override fun toString(): String = id } diff --git a/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt b/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt index 024c4c51de..30d8308d4d 100644 --- a/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt +++ b/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt @@ -27,7 +27,7 @@ import java.util.* * but for the [TransactionType.NotaryChange] transactions it is the set of all input [ContractState.participants]. */ open class TransactionBuilder( - protected val type: TransactionType = TransactionType.General(), + protected val type: TransactionType = TransactionType.General, var notary: Party? = null, var lockId: UUID = (Strand.currentStrand() as? FlowStateMachine<*>)?.id?.uuid ?: UUID.randomUUID(), protected val inputs: MutableList = arrayListOf(), diff --git a/core/src/main/kotlin/net/corda/core/utilities/ProgressTracker.kt b/core/src/main/kotlin/net/corda/core/utilities/ProgressTracker.kt index 0f99b23ae4..88cfd52018 100644 --- a/core/src/main/kotlin/net/corda/core/utilities/ProgressTracker.kt +++ b/core/src/main/kotlin/net/corda/core/utilities/ProgressTracker.kt @@ -37,15 +37,15 @@ import java.util.* class ProgressTracker(vararg steps: Step) { @CordaSerializable sealed class Change { - class Position(val tracker: ProgressTracker, val newStep: Step) : Change() { + data class Position(val tracker: ProgressTracker, val newStep: Step) : Change() { override fun toString() = newStep.label } - class Rendering(val tracker: ProgressTracker, val ofStep: Step) : Change() { + data class Rendering(val tracker: ProgressTracker, val ofStep: Step) : Change() { override fun toString() = ofStep.label } - class Structural(val tracker: ProgressTracker, val parent: Step) : Change() { + data class Structural(val tracker: ProgressTracker, val parent: Step) : Change() { override fun toString() = "Structural step change in child of ${parent.label}" } } diff --git a/core/src/main/kotlin/net/corda/flows/NotaryFlow.kt b/core/src/main/kotlin/net/corda/flows/NotaryFlow.kt index c0325327e1..40fbbc90bd 100644 --- a/core/src/main/kotlin/net/corda/flows/NotaryFlow.kt +++ b/core/src/main/kotlin/net/corda/flows/NotaryFlow.kt @@ -117,7 +117,7 @@ object NotaryFlow { private fun validateTimestamp(t: Timestamp?) { if (t != null && !timestampChecker.isValid(t)) - throw NotaryException(NotaryError.TimestampInvalid()) + throw NotaryException(NotaryError.TimestampInvalid) } /** @@ -163,17 +163,17 @@ class NotaryException(val error: NotaryError) : FlowException("Error response fr @CordaSerializable sealed class NotaryError { - class Conflict(val txId: SecureHash, val conflict: SignedData) : NotaryError() { + data class Conflict(val txId: SecureHash, val conflict: SignedData) : NotaryError() { override fun toString() = "One or more input states for transaction $txId have been used in another transaction" } /** Thrown if the time specified in the timestamp command is outside the allowed tolerance */ - class TimestampInvalid : NotaryError() + object TimestampInvalid : NotaryError() - class TransactionInvalid(val msg: String) : NotaryError() - class SignaturesInvalid(val msg: String) : NotaryError() + data class TransactionInvalid(val msg: String) : NotaryError() + data class SignaturesInvalid(val msg: String) : NotaryError() - class SignaturesMissing(val cause: SignedTransaction.SignaturesMissingException) : NotaryError() { + data class SignaturesMissing(val cause: SignedTransaction.SignaturesMissingException) : NotaryError() { override fun toString() = cause.toString() } } diff --git a/core/src/test/kotlin/net/corda/core/contracts/TransactionTests.kt b/core/src/test/kotlin/net/corda/core/contracts/TransactionTests.kt index fa6d4a6250..1e86e3b0f0 100644 --- a/core/src/test/kotlin/net/corda/core/contracts/TransactionTests.kt +++ b/core/src/test/kotlin/net/corda/core/contracts/TransactionTests.kt @@ -31,7 +31,7 @@ class TransactionTests { commands = emptyList(), notary = DUMMY_NOTARY, signers = listOf(DUMMY_KEY_1.public.composite, DUMMY_KEY_2.public.composite), - type = TransactionType.General(), + type = TransactionType.General, timestamp = null ) val bytes: SerializedBytes = wtx.serialized @@ -76,7 +76,7 @@ class TransactionTests { null, signers, timestamp, - TransactionType.General() + TransactionType.General ) transaction.type.verify(transaction) @@ -103,7 +103,7 @@ class TransactionTests { DUMMY_NOTARY, signers, timestamp, - TransactionType.General() + TransactionType.General ) assertFailsWith { transaction.type.verify(transaction) } @@ -130,7 +130,7 @@ class TransactionTests { notary, signers, timestamp, - TransactionType.General() + TransactionType.General ) assertFailsWith { transaction.type.verify(transaction) } 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 f6dc90b2dc..ee4ae124a8 100644 --- a/core/src/test/kotlin/net/corda/core/crypto/PartialMerkleTreeTest.kt +++ b/core/src/test/kotlin/net/corda/core/crypto/PartialMerkleTreeTest.kt @@ -226,7 +226,7 @@ class PartialMerkleTreeTest { commands = testTx.commands, notary = notary, signers = listOf(MEGA_CORP_PUBKEY, DUMMY_PUBKEY_1), - type = TransactionType.General(), + type = TransactionType.General, timestamp = timestamp ) } diff --git a/finance/src/main/kotlin/net/corda/flows/CashFlowCommand.kt b/finance/src/main/kotlin/net/corda/flows/CashFlowCommand.kt index bbb4788011..b79e222c8b 100644 --- a/finance/src/main/kotlin/net/corda/flows/CashFlowCommand.kt +++ b/finance/src/main/kotlin/net/corda/flows/CashFlowCommand.kt @@ -18,10 +18,10 @@ sealed class CashFlowCommand { /** * A command to initiate the Cash flow with. */ - class IssueCash(val amount: Amount, - val issueRef: OpaqueBytes, - val recipient: Party, - val notary: Party) : CashFlowCommand() { + data class IssueCash(val amount: Amount, + val issueRef: OpaqueBytes, + val recipient: Party, + val notary: Party) : CashFlowCommand() { override fun startFlow(proxy: CordaRPCOps) = proxy.startFlow(::CashIssueFlow, amount, issueRef, recipient, notary) } @@ -31,7 +31,7 @@ sealed class CashFlowCommand { * @param amount the amount of currency to issue on to the ledger. * @param recipient the party to issue the cash to. */ - class PayCash(val amount: Amount, val recipient: Party, val issuerConstraint: Party? = null) : CashFlowCommand() { + data class PayCash(val amount: Amount, val recipient: Party, val issuerConstraint: Party? = null) : CashFlowCommand() { override fun startFlow(proxy: CordaRPCOps) = proxy.startFlow(::CashPaymentFlow, amount, recipient) } @@ -41,7 +41,7 @@ sealed class CashFlowCommand { * @param amount the amount of currency to exit from the ledger. * @param issueRef the reference previously specified on the issuance. */ - class ExitCash(val amount: Amount, val issueRef: OpaqueBytes) : CashFlowCommand() { + data class ExitCash(val amount: Amount, val issueRef: OpaqueBytes) : CashFlowCommand() { override fun startFlow(proxy: CordaRPCOps) = proxy.startFlow(::CashExitFlow, amount, issueRef) } } \ No newline at end of file diff --git a/finance/src/test/kotlin/net/corda/contracts/CommercialPaperTests.kt b/finance/src/test/kotlin/net/corda/contracts/CommercialPaperTests.kt index 9ce9d08273..73b86a5943 100644 --- a/finance/src/test/kotlin/net/corda/contracts/CommercialPaperTests.kt +++ b/finance/src/test/kotlin/net/corda/contracts/CommercialPaperTests.kt @@ -4,13 +4,11 @@ import net.corda.contracts.asset.* import net.corda.contracts.testing.fillWithSomeTestCash import net.corda.core.contracts.* import net.corda.core.crypto.Party -import net.corda.core.crypto.SecureHash import net.corda.core.crypto.composite import net.corda.core.days import net.corda.core.node.services.Vault import net.corda.core.node.services.VaultService import net.corda.core.seconds -import net.corda.core.transactions.LedgerTransaction import net.corda.core.transactions.SignedTransaction import net.corda.core.utilities.DUMMY_NOTARY import net.corda.core.utilities.DUMMY_NOTARY_KEY @@ -38,7 +36,7 @@ interface ICommercialPaperTestTemplate { fun getMoveCommand(): CommandData } -class JavaCommercialPaperTest() : ICommercialPaperTestTemplate { +class JavaCommercialPaperTest : ICommercialPaperTestTemplate { override fun getPaper(): ICommercialPaperState = JavaCommercialPaper.State( MEGA_CORP.ref(123), MEGA_CORP_PUBKEY, @@ -51,7 +49,7 @@ class JavaCommercialPaperTest() : ICommercialPaperTestTemplate { override fun getMoveCommand(): CommandData = JavaCommercialPaper.Commands.Move() } -class KotlinCommercialPaperTest() : ICommercialPaperTestTemplate { +class KotlinCommercialPaperTest : ICommercialPaperTestTemplate { override fun getPaper(): ICommercialPaperState = CommercialPaper.State( issuance = MEGA_CORP.ref(123), owner = MEGA_CORP_PUBKEY, @@ -197,11 +195,6 @@ class CommercialPaperTestsGeneric { } } - fun cashOutputsToVault(vararg outputs: TransactionState): Pair>> { - val ltx = LedgerTransaction(emptyList(), listOf(*outputs), emptyList(), emptyList(), SecureHash.randomSHA256(), null, emptyList(), null, TransactionType.General()) - return Pair(ltx, outputs.mapIndexed { index, state -> StateAndRef(state, StateRef(ltx.id, index)) }) - } - /** * Unit test requires two separate Database instances to represent each of the two * transaction participants (enforces uniqueness of vault content in lieu of partipant identity) diff --git a/finance/src/test/kotlin/net/corda/contracts/testing/Generators.kt b/finance/src/test/kotlin/net/corda/contracts/testing/Generators.kt index fcd858f96e..ceff5ec698 100644 --- a/finance/src/test/kotlin/net/corda/contracts/testing/Generators.kt +++ b/finance/src/test/kotlin/net/corda/contracts/testing/Generators.kt @@ -73,7 +73,7 @@ class WiredTransactionGenerator : Generator(WireTransaction::cl commands = commands, notary = PartyGenerator().generate(random, status), signers = commands.flatMap { it.signers }, - type = TransactionType.General(), + type = TransactionType.General, timestamp = TimestampGenerator().generate(random, status) ) } diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/ArtemisTcpTransport.kt b/node-api/src/main/kotlin/net/corda/nodeapi/ArtemisTcpTransport.kt index 8dbb3ddbca..a9b09c7b42 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/ArtemisTcpTransport.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/ArtemisTcpTransport.kt @@ -9,8 +9,8 @@ import java.nio.file.FileSystems import java.nio.file.Path sealed class ConnectionDirection { - class Inbound(val acceptorFactoryClassName: String) : ConnectionDirection() - class Outbound( + data class Inbound(val acceptorFactoryClassName: String) : ConnectionDirection() + data class Outbound( val expectedCommonName: String? = null, val connectorFactoryClassName: String = NettyConnectorFactory::class.java.name ) : ConnectionDirection() diff --git a/node-schemas/src/test/kotlin/net/corda/node/services/vault/schemas/VaultSchemaTest.kt b/node-schemas/src/test/kotlin/net/corda/node/services/vault/schemas/VaultSchemaTest.kt index dd400fb63c..c4ae91f994 100644 --- a/node-schemas/src/test/kotlin/net/corda/node/services/vault/schemas/VaultSchemaTest.kt +++ b/node-schemas/src/test/kotlin/net/corda/node/services/vault/schemas/VaultSchemaTest.kt @@ -121,7 +121,7 @@ class VaultSchemaTest { notary, signers, timestamp, - TransactionType.General() + TransactionType.General ) } @@ -153,7 +153,7 @@ class VaultSchemaTest { notary, signers, timestamp, - TransactionType.General() + TransactionType.General ) } diff --git a/node/src/main/kotlin/net/corda/node/services/messaging/ArtemisMessagingServer.kt b/node/src/main/kotlin/net/corda/node/services/messaging/ArtemisMessagingServer.kt index f95cb24f41..3e20c8ac82 100644 --- a/node/src/main/kotlin/net/corda/node/services/messaging/ArtemisMessagingServer.kt +++ b/node/src/main/kotlin/net/corda/node/services/messaging/ArtemisMessagingServer.kt @@ -513,7 +513,7 @@ sealed class CertificateChainCheckPolicy { } } - class MustContainOneOf(val trustedAliases: Set) : CertificateChainCheckPolicy() { + data class MustContainOneOf(val trustedAliases: Set) : CertificateChainCheckPolicy() { override fun createCheck(keyStore: KeyStore, trustStore: KeyStore): Check { val trustedPublicKeys = trustedAliases.map { trustStore.getCertificate(it).publicKey }.toSet() return object : Check { diff --git a/node/src/main/kotlin/net/corda/node/services/statemachine/FlowIORequest.kt b/node/src/main/kotlin/net/corda/node/services/statemachine/FlowIORequest.kt index 5f9862d37f..8a1d2342e3 100644 --- a/node/src/main/kotlin/net/corda/node/services/statemachine/FlowIORequest.kt +++ b/node/src/main/kotlin/net/corda/node/services/statemachine/FlowIORequest.kt @@ -2,7 +2,6 @@ package net.corda.node.services.statemachine import net.corda.core.crypto.SecureHash -// TODO revisit when Kotlin 1.1 is released and data classes can extend other classes interface FlowIORequest { // This is used to identify where we suspended, in case of message mismatch errors and other things where we // don't have the original stack trace because it's in a suspended fiber. diff --git a/node/src/main/kotlin/net/corda/node/services/statemachine/FlowSession.kt b/node/src/main/kotlin/net/corda/node/services/statemachine/FlowSession.kt index 6dddbeb67f..11dcd6f493 100644 --- a/node/src/main/kotlin/net/corda/node/services/statemachine/FlowSession.kt +++ b/node/src/main/kotlin/net/corda/node/services/statemachine/FlowSession.kt @@ -32,13 +32,11 @@ sealed class FlowSessionState { abstract val sendToParty: Party /** [otherParty] may be a specific peer or a service party */ - class Initiating(val otherParty: Party) : FlowSessionState() { + data class Initiating(val otherParty: Party) : FlowSessionState() { override val sendToParty: Party get() = otherParty - override fun toString(): String = "${javaClass.simpleName}($otherParty)" } - class Initiated(val peerParty: Party, val peerSessionId: Long) : FlowSessionState() { + data class Initiated(val peerParty: Party, val peerSessionId: Long) : FlowSessionState() { override val sendToParty: Party get() = peerParty - override fun toString(): String = "${javaClass.simpleName}($peerParty, $peerSessionId)" } } diff --git a/node/src/main/kotlin/net/corda/node/services/transactions/BFTSMaRt.kt b/node/src/main/kotlin/net/corda/node/services/transactions/BFTSMaRt.kt index c63e2b50ca..19b48eecc0 100644 --- a/node/src/main/kotlin/net/corda/node/services/transactions/BFTSMaRt.kt +++ b/node/src/main/kotlin/net/corda/node/services/transactions/BFTSMaRt.kt @@ -51,15 +51,15 @@ object BFTSMaRt { /** Sent from [Server] to [Client]. */ @CordaSerializable sealed class ReplicaResponse { - class Error(val error: NotaryError) : ReplicaResponse() - class Signature(val txSignature: DigitalSignature) : ReplicaResponse() + data class Error(val error: NotaryError) : ReplicaResponse() + data class Signature(val txSignature: DigitalSignature) : ReplicaResponse() } /** An aggregate response from all replica ([Server]) replies sent from [Client] back to the calling application. */ @CordaSerializable sealed class ClusterResponse { - class Error(val error: NotaryError) : ClusterResponse() - class Signatures(val txSignatures: List) : ClusterResponse() + data class Error(val error: NotaryError) : ClusterResponse() + data class Signatures(val txSignatures: List) : ClusterResponse() } class Client(val id: Int) : SingletonSerializeAsToken() { @@ -193,7 +193,7 @@ object BFTSMaRt { protected fun validateTimestamp(t: Timestamp?) { if (t != null && !timestampChecker.isValid(t)) - throw NotaryException(NotaryError.TimestampInvalid()) + throw NotaryException(NotaryError.TimestampInvalid) } protected fun sign(bytes: ByteArray): DigitalSignature.WithKey { diff --git a/node/src/test/kotlin/net/corda/node/services/AbstractNetworkMapServiceTest.kt b/node/src/test/kotlin/net/corda/node/services/AbstractNetworkMapServiceTest.kt index 766e1a5dd4..070cbeba8b 100644 --- a/node/src/test/kotlin/net/corda/node/services/AbstractNetworkMapServiceTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/AbstractNetworkMapServiceTest.kt @@ -252,16 +252,11 @@ abstract class AbstractNetworkMapServiceTest return network.createNode(legalName = legalName, nodeFactory = NoNMSNodeFactory) } - sealed class Changed(val node: NodeInfo) { - override fun equals(other: Any?): Boolean = other?.javaClass == this.javaClass && (other as Changed).node == this.node - override fun hashCode(): Int = node.hashCode() - override fun toString(): String = "${javaClass.simpleName}($node)" - - class Added(node: NodeInfo) : Changed(node) { + sealed class Changed { + data class Added(val node: NodeInfo) : Changed() { constructor(node: MockNode) : this(node.info) } - - class Removed(node: NodeInfo) : Changed(node) { + data class Removed(val node: NodeInfo) : Changed() { constructor(node: MockNode) : this(node.info) } } diff --git a/node/src/test/kotlin/net/corda/node/services/database/RequeryConfigurationTest.kt b/node/src/test/kotlin/net/corda/node/services/database/RequeryConfigurationTest.kt index d1d2be7e09..6f7f777340 100644 --- a/node/src/test/kotlin/net/corda/node/services/database/RequeryConfigurationTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/database/RequeryConfigurationTest.kt @@ -164,7 +164,7 @@ class RequeryConfigurationTest { commands = emptyList(), notary = DUMMY_NOTARY, signers = emptyList(), - type = TransactionType.General(), + type = TransactionType.General, timestamp = null ) return SignedTransaction(wtx.serialized, listOf(DigitalSignature.WithKey(NullPublicKey, ByteArray(1)))) diff --git a/node/src/test/kotlin/net/corda/node/services/persistence/DBTransactionStorageTests.kt b/node/src/test/kotlin/net/corda/node/services/persistence/DBTransactionStorageTests.kt index d8be7f760b..8aee0b23d0 100644 --- a/node/src/test/kotlin/net/corda/node/services/persistence/DBTransactionStorageTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/persistence/DBTransactionStorageTests.kt @@ -153,7 +153,7 @@ class DBTransactionStorageTests { commands = emptyList(), notary = DUMMY_NOTARY, signers = emptyList(), - type = TransactionType.General(), + type = TransactionType.General, timestamp = null ) return SignedTransaction(wtx.serialized, listOf(DigitalSignature.WithKey(NullPublicKey, ByteArray(1)))) diff --git a/verifier/src/integration-test/kotlin/net/corda/verifier/GeneratedLedger.kt b/verifier/src/integration-test/kotlin/net/corda/verifier/GeneratedLedger.kt index 972ab38480..4dbead346b 100644 --- a/verifier/src/integration-test/kotlin/net/corda/verifier/GeneratedLedger.kt +++ b/verifier/src/integration-test/kotlin/net/corda/verifier/GeneratedLedger.kt @@ -68,7 +68,7 @@ data class GeneratedLedger( commands.map { it.first }, null, signers, - TransactionType.General(), + TransactionType.General, null ) val newOutputStateAndRefs = outputs.mapIndexed { i, state -> @@ -103,7 +103,7 @@ data class GeneratedLedger( commands.map { it.first }, inputNotary, signers, - TransactionType.General(), + TransactionType.General, null ) val newOutputStateAndRefs = outputs.mapIndexed { i, state -> @@ -144,7 +144,7 @@ data class GeneratedLedger( emptyList(), inputNotary, signers, - TransactionType.NotaryChange(), + TransactionType.NotaryChange, null ) val newOutputStateAndRefs = outputs.mapIndexed { i, state ->