mirror of
https://github.com/corda/corda.git
synced 2024-12-24 07:06:44 +00:00
Converted sealed data types to be data classes
This commit is contained in:
parent
da92806b99
commit
faef877a8d
@ -30,9 +30,13 @@ data class PartiallyResolvedTransaction(
|
|||||||
val inputs: List<ObservableValue<InputResolution>>) {
|
val inputs: List<ObservableValue<InputResolution>>) {
|
||||||
val id = transaction.id
|
val id = transaction.id
|
||||||
|
|
||||||
sealed class InputResolution(val stateRef: StateRef) {
|
sealed class InputResolution {
|
||||||
class Unresolved(stateRef: StateRef) : InputResolution(stateRef)
|
abstract val stateRef: StateRef
|
||||||
class Resolved(val stateAndRef: StateAndRef<ContractState>) : InputResolution(stateAndRef.ref)
|
|
||||||
|
data class Unresolved(override val stateRef: StateRef) : InputResolution()
|
||||||
|
data class Resolved(val stateAndRef: StateAndRef<ContractState>) : InputResolution() {
|
||||||
|
override val stateRef: StateRef get() = stateAndRef.ref
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@ -54,22 +58,13 @@ data class PartiallyResolvedTransaction(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class TransactionCreateStatus(val message: String?) {
|
data class FlowStatus(val status: String)
|
||||||
class Started(message: String?) : TransactionCreateStatus(message)
|
|
||||||
class Failed(message: String?) : TransactionCreateStatus(message)
|
|
||||||
|
|
||||||
override fun toString(): String = message ?: javaClass.simpleName
|
sealed class StateMachineStatus {
|
||||||
}
|
abstract val stateMachineName: String
|
||||||
|
|
||||||
data class FlowStatus(
|
data class Added(override val stateMachineName: String) : StateMachineStatus()
|
||||||
val status: String
|
data class Removed(override val stateMachineName: String) : StateMachineStatus()
|
||||||
)
|
|
||||||
|
|
||||||
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 StateMachineData(
|
data class StateMachineData(
|
||||||
|
@ -9,9 +9,6 @@ import net.corda.core.transactions.TransactionBuilder
|
|||||||
/** Defines transaction build & validation logic for a specific transaction type */
|
/** Defines transaction build & validation logic for a specific transaction type */
|
||||||
@CordaSerializable
|
@CordaSerializable
|
||||||
sealed class TransactionType {
|
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:
|
* Check that the transaction is valid based on:
|
||||||
* - General platform rules
|
* - General platform rules
|
||||||
@ -63,9 +60,9 @@ sealed class TransactionType {
|
|||||||
abstract fun verifyTransaction(tx: LedgerTransaction)
|
abstract fun verifyTransaction(tx: LedgerTransaction)
|
||||||
|
|
||||||
/** A general transaction type where transaction validity is determined by custom contract code */
|
/** 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 */
|
/** 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) {
|
override fun verifyTransaction(tx: LedgerTransaction) {
|
||||||
verifyNoNotaryChange(tx)
|
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
|
* 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.
|
* 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]
|
* 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.
|
* 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<*>) {
|
override fun addInputState(stateAndRef: StateAndRef<*>) {
|
||||||
signers.addAll(stateAndRef.state.data.participants)
|
signers.addAll(stateAndRef.state.data.participants)
|
||||||
super.addInputState(stateAndRef)
|
super.addInputState(stateAndRef)
|
||||||
|
@ -47,18 +47,10 @@ sealed class CompositeKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** The leaf node of the tree – a wrapper around a [PublicKey] primitive */
|
/** 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>) = publicKey in keys
|
override fun isFulfilledBy(keys: Iterable<PublicKey>) = publicKey in keys
|
||||||
|
|
||||||
override val keys: Set<PublicKey>
|
override val keys: Set<PublicKey> get() = setOf(publicKey)
|
||||||
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 fun toString() = publicKey.toStringShort()
|
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
|
* 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.
|
* signatures required) to satisfy the sub-tree rooted at this node.
|
||||||
*/
|
*/
|
||||||
class Node(val threshold: Int,
|
data class Node(val threshold: Int, val children: List<CompositeKey>, val weights: List<Int>) : CompositeKey() {
|
||||||
val children: List<CompositeKey>,
|
|
||||||
val weights: List<Int>) : CompositeKey() {
|
|
||||||
|
|
||||||
override fun isFulfilledBy(keys: Iterable<PublicKey>): Boolean {
|
override fun isFulfilledBy(keys: Iterable<PublicKey>): Boolean {
|
||||||
val totalWeight = children.mapIndexed { i, childNode ->
|
val totalWeight = children.mapIndexed { i, childNode ->
|
||||||
if (childNode.isFulfilledBy(keys)) weights[i] else 0
|
if (childNode.isFulfilledBy(keys)) weights[i] else 0
|
||||||
@ -82,35 +71,13 @@ sealed class CompositeKey {
|
|||||||
return totalWeight >= threshold
|
return totalWeight >= threshold
|
||||||
}
|
}
|
||||||
|
|
||||||
override val keys: Set<PublicKey>
|
override val keys: Set<PublicKey> get() = children.flatMap { it.keys }.toSet()
|
||||||
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 fun toString() = "(${children.joinToString()})"
|
override fun toString() = "(${children.joinToString()})"
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A helper class for building a [CompositeKey.Node]. */
|
/** A helper class for building a [CompositeKey.Node]. */
|
||||||
class Builder() {
|
class Builder {
|
||||||
private val children: MutableList<CompositeKey> = mutableListOf()
|
private val children: MutableList<CompositeKey> = mutableListOf()
|
||||||
private val weights: MutableList<Int> = mutableListOf()
|
private val weights: MutableList<Int> = mutableListOf()
|
||||||
|
|
||||||
|
@ -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,
|
* 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.
|
* 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) {
|
sealed class MerkleTree {
|
||||||
class Leaf(val value: SecureHash) : MerkleTree(value)
|
abstract val hash: SecureHash
|
||||||
class Node(val value: SecureHash, val left: MerkleTree, val right: MerkleTree) : MerkleTree(value)
|
|
||||||
|
data class Leaf(override val hash: SecureHash) : MerkleTree()
|
||||||
|
data class Node(override val hash: SecureHash, val left: MerkleTree, val right: MerkleTree) : MerkleTree()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private fun isPow2(num: Int): Boolean = num and (num-1) == 0
|
private fun isPow2(num: Int): Boolean = num and (num-1) == 0
|
||||||
|
@ -54,9 +54,9 @@ class PartialMerkleTree(val root: PartialTree) {
|
|||||||
*/
|
*/
|
||||||
@CordaSerializable
|
@CordaSerializable
|
||||||
sealed class PartialTree {
|
sealed class PartialTree {
|
||||||
class IncludedLeaf(val hash: SecureHash) : PartialTree()
|
data class IncludedLeaf(val hash: SecureHash) : PartialTree()
|
||||||
class Leaf(val hash: SecureHash) : PartialTree()
|
data class Leaf(val hash: SecureHash) : PartialTree()
|
||||||
class Node(val left: PartialTree, val right: PartialTree) : PartialTree()
|
data class Node(val left: PartialTree, val right: PartialTree) : PartialTree()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@ -104,10 +104,10 @@ class PartialMerkleTree(val root: PartialTree) {
|
|||||||
): Pair<Boolean, PartialTree> {
|
): Pair<Boolean, PartialTree> {
|
||||||
return when (root) {
|
return when (root) {
|
||||||
is MerkleTree.Leaf ->
|
is MerkleTree.Leaf ->
|
||||||
if (root.value in includeHashes) {
|
if (root.hash in includeHashes) {
|
||||||
usedHashes.add(root.value)
|
usedHashes.add(root.hash)
|
||||||
Pair(true, PartialTree.IncludedLeaf(root.value))
|
Pair(true, PartialTree.IncludedLeaf(root.hash))
|
||||||
} else Pair(false, PartialTree.Leaf(root.value))
|
} else Pair(false, PartialTree.Leaf(root.hash))
|
||||||
is MerkleTree.Node -> {
|
is MerkleTree.Node -> {
|
||||||
val leftNode = buildPartialTree(root.left, includeHashes, usedHashes)
|
val leftNode = buildPartialTree(root.left, includeHashes, usedHashes)
|
||||||
val rightNode = buildPartialTree(root.right, includeHashes, usedHashes)
|
val rightNode = buildPartialTree(root.right, includeHashes, usedHashes)
|
||||||
@ -117,7 +117,7 @@ class PartialMerkleTree(val root: PartialTree) {
|
|||||||
Pair(true, newTree)
|
Pair(true, newTree)
|
||||||
} else {
|
} else {
|
||||||
// This node has no included leaves below. Cut the tree here and store a hash as a Leaf.
|
// 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)
|
Pair(false, newTree)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 prefixChars(prefixLen: Int = 6) = toString().substring(0, prefixLen)
|
||||||
fun hashConcat(other: SecureHash) = (this.bytes + other.bytes).sha256()
|
fun hashConcat(other: SecureHash) = (this.bytes + other.bytes).sha256()
|
||||||
|
@ -26,17 +26,19 @@ data class StateMachineInfo(
|
|||||||
val id: StateMachineRunId,
|
val id: StateMachineRunId,
|
||||||
val flowLogicClassName: String,
|
val flowLogicClassName: String,
|
||||||
val progressTrackerStepAndUpdates: Pair<String, Observable<String>>?
|
val progressTrackerStepAndUpdates: Pair<String, Observable<String>>?
|
||||||
)
|
) {
|
||||||
|
override fun toString(): String = "${javaClass.simpleName}($id, $flowLogicClassName)"
|
||||||
|
}
|
||||||
|
|
||||||
@CordaSerializable
|
@CordaSerializable
|
||||||
sealed class StateMachineUpdate(val id: StateMachineRunId) {
|
sealed class StateMachineUpdate {
|
||||||
class Added(val stateMachineInfo: StateMachineInfo) : StateMachineUpdate(stateMachineInfo.id) {
|
abstract val id: StateMachineRunId
|
||||||
override fun toString() = "Added($id, ${stateMachineInfo.flowLogicClassName})"
|
|
||||||
|
data class Added(val stateMachineInfo: StateMachineInfo) : StateMachineUpdate() {
|
||||||
|
override val id: StateMachineRunId get() = stateMachineInfo.id
|
||||||
}
|
}
|
||||||
|
|
||||||
class Removed(id: StateMachineRunId) : StateMachineUpdate(id) {
|
data class Removed(override val id: StateMachineRunId) : StateMachineUpdate()
|
||||||
override fun toString() = "Removed($id)"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,10 +21,12 @@ import rx.Observable
|
|||||||
interface NetworkMapCache {
|
interface NetworkMapCache {
|
||||||
|
|
||||||
@CordaSerializable
|
@CordaSerializable
|
||||||
sealed class MapChange(val node: NodeInfo) {
|
sealed class MapChange {
|
||||||
class Added(node: NodeInfo) : MapChange(node)
|
abstract val node: NodeInfo
|
||||||
class Removed(node: NodeInfo) : MapChange(node)
|
|
||||||
class Modified(node: NodeInfo, val previousNode: NodeInfo) : MapChange(node)
|
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 */
|
/** A list of all nodes the cache is aware of */
|
||||||
|
@ -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.
|
* 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
|
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() {
|
data class Service(val service: ServiceEntry) : PartyInfo() {
|
||||||
override val party = service.identity
|
override val party get() = service.identity
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,7 +8,7 @@ import net.corda.core.serialization.CordaSerializable
|
|||||||
* don't need a declared service type.
|
* don't need a declared service type.
|
||||||
*/
|
*/
|
||||||
@CordaSerializable
|
@CordaSerializable
|
||||||
sealed class ServiceType(val id: String) {
|
class ServiceType private constructor(val id: String) {
|
||||||
init {
|
init {
|
||||||
// Enforce:
|
// Enforce:
|
||||||
//
|
//
|
||||||
@ -16,9 +16,6 @@ sealed class ServiceType(val id: String) {
|
|||||||
// * IDs can only contain alphanumeric, full stop and underscore ASCII characters
|
// * IDs can only contain alphanumeric, full stop and underscore ASCII characters
|
||||||
require(id.matches(Regex("[a-z][a-zA-Z0-9._]+"))) { id }
|
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 {
|
companion object {
|
||||||
val corda: ServiceType
|
val corda: ServiceType
|
||||||
@ -26,7 +23,7 @@ sealed class ServiceType(val id: String) {
|
|||||||
val stack = Throwable().stackTrace
|
val stack = Throwable().stackTrace
|
||||||
val caller = stack.first().className
|
val caller = stack.first().className
|
||||||
require(caller.startsWith("net.corda.")) { "Corda ServiceType namespace is reserved for Corda core components" }
|
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")
|
val notary: ServiceType = corda.getSubType("notary")
|
||||||
@ -35,21 +32,22 @@ sealed class ServiceType(val id: String) {
|
|||||||
|
|
||||||
fun getServiceType(namespace: String, typeId: String): ServiceType {
|
fun getServiceType(namespace: String, typeId: String): ServiceType {
|
||||||
require(!namespace.startsWith("corda")) { "Corda namespace is protected" }
|
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)
|
fun getSubType(subTypeId: String): ServiceType = baseWithSubType(id, subTypeId)
|
||||||
|
|
||||||
override operator fun equals(other: Any?): Boolean = (other is ServiceType) && (other.id == this.id)
|
|
||||||
|
|
||||||
fun isSubTypeOf(superType: ServiceType) = (id == superType.id) || id.startsWith(superType.id + ".")
|
fun isSubTypeOf(superType: ServiceType) = (id == superType.id) || id.startsWith(superType.id + ".")
|
||||||
fun isNotary() = isSubTypeOf(notary)
|
fun isNotary() = isSubTypeOf(notary)
|
||||||
fun isValidatingNotary() = isNotary() && id.contains(".validating")
|
fun isValidatingNotary() = isNotary() && id.contains(".validating")
|
||||||
fun isNetworkMap() = id == networkMap.id
|
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 hashCode(): Int = id.hashCode()
|
||||||
override fun toString(): String = id
|
override fun toString(): String = id
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ import java.util.*
|
|||||||
* but for the [TransactionType.NotaryChange] transactions it is the set of all input [ContractState.participants].
|
* but for the [TransactionType.NotaryChange] transactions it is the set of all input [ContractState.participants].
|
||||||
*/
|
*/
|
||||||
open class TransactionBuilder(
|
open class TransactionBuilder(
|
||||||
protected val type: TransactionType = TransactionType.General(),
|
protected val type: TransactionType = TransactionType.General,
|
||||||
var notary: Party? = null,
|
var notary: Party? = null,
|
||||||
var lockId: UUID = (Strand.currentStrand() as? FlowStateMachine<*>)?.id?.uuid ?: UUID.randomUUID(),
|
var lockId: UUID = (Strand.currentStrand() as? FlowStateMachine<*>)?.id?.uuid ?: UUID.randomUUID(),
|
||||||
protected val inputs: MutableList<StateRef> = arrayListOf(),
|
protected val inputs: MutableList<StateRef> = arrayListOf(),
|
||||||
|
@ -37,15 +37,15 @@ import java.util.*
|
|||||||
class ProgressTracker(vararg steps: Step) {
|
class ProgressTracker(vararg steps: Step) {
|
||||||
@CordaSerializable
|
@CordaSerializable
|
||||||
sealed class Change {
|
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
|
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
|
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}"
|
override fun toString() = "Structural step change in child of ${parent.label}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ object NotaryFlow {
|
|||||||
|
|
||||||
private fun validateTimestamp(t: Timestamp?) {
|
private fun validateTimestamp(t: Timestamp?) {
|
||||||
if (t != null && !timestampChecker.isValid(t))
|
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
|
@CordaSerializable
|
||||||
sealed class NotaryError {
|
sealed class NotaryError {
|
||||||
class Conflict(val txId: SecureHash, val conflict: SignedData<UniquenessProvider.Conflict>) : NotaryError() {
|
data class Conflict(val txId: SecureHash, val conflict: SignedData<UniquenessProvider.Conflict>) : NotaryError() {
|
||||||
override fun toString() = "One or more input states for transaction $txId have been used in another transaction"
|
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 */
|
/** 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()
|
data class TransactionInvalid(val msg: String) : NotaryError()
|
||||||
class SignaturesInvalid(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()
|
override fun toString() = cause.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ class TransactionTests {
|
|||||||
commands = emptyList(),
|
commands = emptyList(),
|
||||||
notary = DUMMY_NOTARY,
|
notary = DUMMY_NOTARY,
|
||||||
signers = listOf(DUMMY_KEY_1.public.composite, DUMMY_KEY_2.public.composite),
|
signers = listOf(DUMMY_KEY_1.public.composite, DUMMY_KEY_2.public.composite),
|
||||||
type = TransactionType.General(),
|
type = TransactionType.General,
|
||||||
timestamp = null
|
timestamp = null
|
||||||
)
|
)
|
||||||
val bytes: SerializedBytes<WireTransaction> = wtx.serialized
|
val bytes: SerializedBytes<WireTransaction> = wtx.serialized
|
||||||
@ -76,7 +76,7 @@ class TransactionTests {
|
|||||||
null,
|
null,
|
||||||
signers,
|
signers,
|
||||||
timestamp,
|
timestamp,
|
||||||
TransactionType.General()
|
TransactionType.General
|
||||||
)
|
)
|
||||||
|
|
||||||
transaction.type.verify(transaction)
|
transaction.type.verify(transaction)
|
||||||
@ -103,7 +103,7 @@ class TransactionTests {
|
|||||||
DUMMY_NOTARY,
|
DUMMY_NOTARY,
|
||||||
signers,
|
signers,
|
||||||
timestamp,
|
timestamp,
|
||||||
TransactionType.General()
|
TransactionType.General
|
||||||
)
|
)
|
||||||
|
|
||||||
assertFailsWith<TransactionVerificationException.DuplicateInputStates> { transaction.type.verify(transaction) }
|
assertFailsWith<TransactionVerificationException.DuplicateInputStates> { transaction.type.verify(transaction) }
|
||||||
@ -130,7 +130,7 @@ class TransactionTests {
|
|||||||
notary,
|
notary,
|
||||||
signers,
|
signers,
|
||||||
timestamp,
|
timestamp,
|
||||||
TransactionType.General()
|
TransactionType.General
|
||||||
)
|
)
|
||||||
|
|
||||||
assertFailsWith<TransactionVerificationException.NotaryChangeInWrongTransactionType> { transaction.type.verify(transaction) }
|
assertFailsWith<TransactionVerificationException.NotaryChangeInWrongTransactionType> { transaction.type.verify(transaction) }
|
||||||
|
@ -226,7 +226,7 @@ class PartialMerkleTreeTest {
|
|||||||
commands = testTx.commands,
|
commands = testTx.commands,
|
||||||
notary = notary,
|
notary = notary,
|
||||||
signers = listOf(MEGA_CORP_PUBKEY, DUMMY_PUBKEY_1),
|
signers = listOf(MEGA_CORP_PUBKEY, DUMMY_PUBKEY_1),
|
||||||
type = TransactionType.General(),
|
type = TransactionType.General,
|
||||||
timestamp = timestamp
|
timestamp = timestamp
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,10 @@ sealed class CashFlowCommand {
|
|||||||
/**
|
/**
|
||||||
* A command to initiate the Cash flow with.
|
* A command to initiate the Cash flow with.
|
||||||
*/
|
*/
|
||||||
class IssueCash(val amount: Amount<Currency>,
|
data class IssueCash(val amount: Amount<Currency>,
|
||||||
val issueRef: OpaqueBytes,
|
val issueRef: OpaqueBytes,
|
||||||
val recipient: Party,
|
val recipient: Party,
|
||||||
val notary: Party) : CashFlowCommand() {
|
val notary: Party) : CashFlowCommand() {
|
||||||
override fun startFlow(proxy: CordaRPCOps) = proxy.startFlow(::CashIssueFlow, amount, issueRef, recipient, notary)
|
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 amount the amount of currency to issue on to the ledger.
|
||||||
* @param recipient the party to issue the cash to.
|
* @param recipient the party to issue the cash to.
|
||||||
*/
|
*/
|
||||||
class PayCash(val amount: Amount<Currency>, val recipient: Party, val issuerConstraint: Party? = null) : CashFlowCommand() {
|
data class PayCash(val amount: Amount<Currency>, val recipient: Party, val issuerConstraint: Party? = null) : CashFlowCommand() {
|
||||||
override fun startFlow(proxy: CordaRPCOps) = proxy.startFlow(::CashPaymentFlow, amount, recipient)
|
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 amount the amount of currency to exit from the ledger.
|
||||||
* @param issueRef the reference previously specified on the issuance.
|
* @param issueRef the reference previously specified on the issuance.
|
||||||
*/
|
*/
|
||||||
class ExitCash(val amount: Amount<Currency>, val issueRef: OpaqueBytes) : CashFlowCommand() {
|
data class ExitCash(val amount: Amount<Currency>, val issueRef: OpaqueBytes) : CashFlowCommand() {
|
||||||
override fun startFlow(proxy: CordaRPCOps) = proxy.startFlow(::CashExitFlow, amount, issueRef)
|
override fun startFlow(proxy: CordaRPCOps) = proxy.startFlow(::CashExitFlow, amount, issueRef)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,13 +4,11 @@ import net.corda.contracts.asset.*
|
|||||||
import net.corda.contracts.testing.fillWithSomeTestCash
|
import net.corda.contracts.testing.fillWithSomeTestCash
|
||||||
import net.corda.core.contracts.*
|
import net.corda.core.contracts.*
|
||||||
import net.corda.core.crypto.Party
|
import net.corda.core.crypto.Party
|
||||||
import net.corda.core.crypto.SecureHash
|
|
||||||
import net.corda.core.crypto.composite
|
import net.corda.core.crypto.composite
|
||||||
import net.corda.core.days
|
import net.corda.core.days
|
||||||
import net.corda.core.node.services.Vault
|
import net.corda.core.node.services.Vault
|
||||||
import net.corda.core.node.services.VaultService
|
import net.corda.core.node.services.VaultService
|
||||||
import net.corda.core.seconds
|
import net.corda.core.seconds
|
||||||
import net.corda.core.transactions.LedgerTransaction
|
|
||||||
import net.corda.core.transactions.SignedTransaction
|
import net.corda.core.transactions.SignedTransaction
|
||||||
import net.corda.core.utilities.DUMMY_NOTARY
|
import net.corda.core.utilities.DUMMY_NOTARY
|
||||||
import net.corda.core.utilities.DUMMY_NOTARY_KEY
|
import net.corda.core.utilities.DUMMY_NOTARY_KEY
|
||||||
@ -38,7 +36,7 @@ interface ICommercialPaperTestTemplate {
|
|||||||
fun getMoveCommand(): CommandData
|
fun getMoveCommand(): CommandData
|
||||||
}
|
}
|
||||||
|
|
||||||
class JavaCommercialPaperTest() : ICommercialPaperTestTemplate {
|
class JavaCommercialPaperTest : ICommercialPaperTestTemplate {
|
||||||
override fun getPaper(): ICommercialPaperState = JavaCommercialPaper.State(
|
override fun getPaper(): ICommercialPaperState = JavaCommercialPaper.State(
|
||||||
MEGA_CORP.ref(123),
|
MEGA_CORP.ref(123),
|
||||||
MEGA_CORP_PUBKEY,
|
MEGA_CORP_PUBKEY,
|
||||||
@ -51,7 +49,7 @@ class JavaCommercialPaperTest() : ICommercialPaperTestTemplate {
|
|||||||
override fun getMoveCommand(): CommandData = JavaCommercialPaper.Commands.Move()
|
override fun getMoveCommand(): CommandData = JavaCommercialPaper.Commands.Move()
|
||||||
}
|
}
|
||||||
|
|
||||||
class KotlinCommercialPaperTest() : ICommercialPaperTestTemplate {
|
class KotlinCommercialPaperTest : ICommercialPaperTestTemplate {
|
||||||
override fun getPaper(): ICommercialPaperState = CommercialPaper.State(
|
override fun getPaper(): ICommercialPaperState = CommercialPaper.State(
|
||||||
issuance = MEGA_CORP.ref(123),
|
issuance = MEGA_CORP.ref(123),
|
||||||
owner = MEGA_CORP_PUBKEY,
|
owner = MEGA_CORP_PUBKEY,
|
||||||
@ -197,11 +195,6 @@ class CommercialPaperTestsGeneric {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun cashOutputsToVault(vararg outputs: TransactionState<Cash.State>): Pair<LedgerTransaction, List<StateAndRef<Cash.State>>> {
|
|
||||||
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
|
* 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)
|
* transaction participants (enforces uniqueness of vault content in lieu of partipant identity)
|
||||||
|
@ -73,7 +73,7 @@ class WiredTransactionGenerator : Generator<WireTransaction>(WireTransaction::cl
|
|||||||
commands = commands,
|
commands = commands,
|
||||||
notary = PartyGenerator().generate(random, status),
|
notary = PartyGenerator().generate(random, status),
|
||||||
signers = commands.flatMap { it.signers },
|
signers = commands.flatMap { it.signers },
|
||||||
type = TransactionType.General(),
|
type = TransactionType.General,
|
||||||
timestamp = TimestampGenerator().generate(random, status)
|
timestamp = TimestampGenerator().generate(random, status)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,8 @@ import java.nio.file.FileSystems
|
|||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
|
||||||
sealed class ConnectionDirection {
|
sealed class ConnectionDirection {
|
||||||
class Inbound(val acceptorFactoryClassName: String) : ConnectionDirection()
|
data class Inbound(val acceptorFactoryClassName: String) : ConnectionDirection()
|
||||||
class Outbound(
|
data class Outbound(
|
||||||
val expectedCommonName: String? = null,
|
val expectedCommonName: String? = null,
|
||||||
val connectorFactoryClassName: String = NettyConnectorFactory::class.java.name
|
val connectorFactoryClassName: String = NettyConnectorFactory::class.java.name
|
||||||
) : ConnectionDirection()
|
) : ConnectionDirection()
|
||||||
|
@ -121,7 +121,7 @@ class VaultSchemaTest {
|
|||||||
notary,
|
notary,
|
||||||
signers,
|
signers,
|
||||||
timestamp,
|
timestamp,
|
||||||
TransactionType.General()
|
TransactionType.General
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ class VaultSchemaTest {
|
|||||||
notary,
|
notary,
|
||||||
signers,
|
signers,
|
||||||
timestamp,
|
timestamp,
|
||||||
TransactionType.General()
|
TransactionType.General
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -513,7 +513,7 @@ sealed class CertificateChainCheckPolicy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MustContainOneOf(val trustedAliases: Set<String>) : CertificateChainCheckPolicy() {
|
data class MustContainOneOf(val trustedAliases: Set<String>) : CertificateChainCheckPolicy() {
|
||||||
override fun createCheck(keyStore: KeyStore, trustStore: KeyStore): Check {
|
override fun createCheck(keyStore: KeyStore, trustStore: KeyStore): Check {
|
||||||
val trustedPublicKeys = trustedAliases.map { trustStore.getCertificate(it).publicKey }.toSet()
|
val trustedPublicKeys = trustedAliases.map { trustStore.getCertificate(it).publicKey }.toSet()
|
||||||
return object : Check {
|
return object : Check {
|
||||||
|
@ -2,7 +2,6 @@ package net.corda.node.services.statemachine
|
|||||||
|
|
||||||
import net.corda.core.crypto.SecureHash
|
import net.corda.core.crypto.SecureHash
|
||||||
|
|
||||||
// TODO revisit when Kotlin 1.1 is released and data classes can extend other classes
|
|
||||||
interface FlowIORequest {
|
interface FlowIORequest {
|
||||||
// This is used to identify where we suspended, in case of message mismatch errors and other things where we
|
// 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.
|
// don't have the original stack trace because it's in a suspended fiber.
|
||||||
|
@ -32,13 +32,11 @@ sealed class FlowSessionState {
|
|||||||
abstract val sendToParty: Party
|
abstract val sendToParty: Party
|
||||||
|
|
||||||
/** [otherParty] may be a specific peer or a service 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 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 val sendToParty: Party get() = peerParty
|
||||||
override fun toString(): String = "${javaClass.simpleName}($peerParty, $peerSessionId)"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,15 +51,15 @@ object BFTSMaRt {
|
|||||||
/** Sent from [Server] to [Client]. */
|
/** Sent from [Server] to [Client]. */
|
||||||
@CordaSerializable
|
@CordaSerializable
|
||||||
sealed class ReplicaResponse {
|
sealed class ReplicaResponse {
|
||||||
class Error(val error: NotaryError) : ReplicaResponse()
|
data class Error(val error: NotaryError) : ReplicaResponse()
|
||||||
class Signature(val txSignature: DigitalSignature) : ReplicaResponse()
|
data class Signature(val txSignature: DigitalSignature) : ReplicaResponse()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An aggregate response from all replica ([Server]) replies sent from [Client] back to the calling application. */
|
/** An aggregate response from all replica ([Server]) replies sent from [Client] back to the calling application. */
|
||||||
@CordaSerializable
|
@CordaSerializable
|
||||||
sealed class ClusterResponse {
|
sealed class ClusterResponse {
|
||||||
class Error(val error: NotaryError) : ClusterResponse()
|
data class Error(val error: NotaryError) : ClusterResponse()
|
||||||
class Signatures(val txSignatures: List<DigitalSignature>) : ClusterResponse()
|
data class Signatures(val txSignatures: List<DigitalSignature>) : ClusterResponse()
|
||||||
}
|
}
|
||||||
|
|
||||||
class Client(val id: Int) : SingletonSerializeAsToken() {
|
class Client(val id: Int) : SingletonSerializeAsToken() {
|
||||||
@ -193,7 +193,7 @@ object BFTSMaRt {
|
|||||||
|
|
||||||
protected fun validateTimestamp(t: Timestamp?) {
|
protected fun validateTimestamp(t: Timestamp?) {
|
||||||
if (t != null && !timestampChecker.isValid(t))
|
if (t != null && !timestampChecker.isValid(t))
|
||||||
throw NotaryException(NotaryError.TimestampInvalid())
|
throw NotaryException(NotaryError.TimestampInvalid)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun sign(bytes: ByteArray): DigitalSignature.WithKey {
|
protected fun sign(bytes: ByteArray): DigitalSignature.WithKey {
|
||||||
|
@ -252,16 +252,11 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
|||||||
return network.createNode(legalName = legalName, nodeFactory = NoNMSNodeFactory)
|
return network.createNode(legalName = legalName, nodeFactory = NoNMSNodeFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class Changed(val node: NodeInfo) {
|
sealed class Changed {
|
||||||
override fun equals(other: Any?): Boolean = other?.javaClass == this.javaClass && (other as Changed).node == this.node
|
data class Added(val node: NodeInfo) : Changed() {
|
||||||
override fun hashCode(): Int = node.hashCode()
|
|
||||||
override fun toString(): String = "${javaClass.simpleName}($node)"
|
|
||||||
|
|
||||||
class Added(node: NodeInfo) : Changed(node) {
|
|
||||||
constructor(node: MockNode) : this(node.info)
|
constructor(node: MockNode) : this(node.info)
|
||||||
}
|
}
|
||||||
|
data class Removed(val node: NodeInfo) : Changed() {
|
||||||
class Removed(node: NodeInfo) : Changed(node) {
|
|
||||||
constructor(node: MockNode) : this(node.info)
|
constructor(node: MockNode) : this(node.info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ class RequeryConfigurationTest {
|
|||||||
commands = emptyList(),
|
commands = emptyList(),
|
||||||
notary = DUMMY_NOTARY,
|
notary = DUMMY_NOTARY,
|
||||||
signers = emptyList(),
|
signers = emptyList(),
|
||||||
type = TransactionType.General(),
|
type = TransactionType.General,
|
||||||
timestamp = null
|
timestamp = null
|
||||||
)
|
)
|
||||||
return SignedTransaction(wtx.serialized, listOf(DigitalSignature.WithKey(NullPublicKey, ByteArray(1))))
|
return SignedTransaction(wtx.serialized, listOf(DigitalSignature.WithKey(NullPublicKey, ByteArray(1))))
|
||||||
|
@ -153,7 +153,7 @@ class DBTransactionStorageTests {
|
|||||||
commands = emptyList(),
|
commands = emptyList(),
|
||||||
notary = DUMMY_NOTARY,
|
notary = DUMMY_NOTARY,
|
||||||
signers = emptyList(),
|
signers = emptyList(),
|
||||||
type = TransactionType.General(),
|
type = TransactionType.General,
|
||||||
timestamp = null
|
timestamp = null
|
||||||
)
|
)
|
||||||
return SignedTransaction(wtx.serialized, listOf(DigitalSignature.WithKey(NullPublicKey, ByteArray(1))))
|
return SignedTransaction(wtx.serialized, listOf(DigitalSignature.WithKey(NullPublicKey, ByteArray(1))))
|
||||||
|
@ -68,7 +68,7 @@ data class GeneratedLedger(
|
|||||||
commands.map { it.first },
|
commands.map { it.first },
|
||||||
null,
|
null,
|
||||||
signers,
|
signers,
|
||||||
TransactionType.General(),
|
TransactionType.General,
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
val newOutputStateAndRefs = outputs.mapIndexed { i, state ->
|
val newOutputStateAndRefs = outputs.mapIndexed { i, state ->
|
||||||
@ -103,7 +103,7 @@ data class GeneratedLedger(
|
|||||||
commands.map { it.first },
|
commands.map { it.first },
|
||||||
inputNotary,
|
inputNotary,
|
||||||
signers,
|
signers,
|
||||||
TransactionType.General(),
|
TransactionType.General,
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
val newOutputStateAndRefs = outputs.mapIndexed { i, state ->
|
val newOutputStateAndRefs = outputs.mapIndexed { i, state ->
|
||||||
@ -144,7 +144,7 @@ data class GeneratedLedger(
|
|||||||
emptyList(),
|
emptyList(),
|
||||||
inputNotary,
|
inputNotary,
|
||||||
signers,
|
signers,
|
||||||
TransactionType.NotaryChange(),
|
TransactionType.NotaryChange,
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
val newOutputStateAndRefs = outputs.mapIndexed { i, state ->
|
val newOutputStateAndRefs = outputs.mapIndexed { i, state ->
|
||||||
|
Loading…
Reference in New Issue
Block a user