From f5776d6bd7699bdb3ae0a599b21c8ae35d81a3cd Mon Sep 17 00:00:00 2001 From: Andrius Dagys Date: Mon, 7 Aug 2017 12:26:48 +0100 Subject: [PATCH] Enforce transaction validity rules --- .../kotlin/net/corda/core/transactions/BaseTransaction.kt | 4 ++-- .../kotlin/net/corda/core/transactions/WireTransaction.kt | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/kotlin/net/corda/core/transactions/BaseTransaction.kt b/core/src/main/kotlin/net/corda/core/transactions/BaseTransaction.kt index 276415b041..da0d98dbe7 100644 --- a/core/src/main/kotlin/net/corda/core/transactions/BaseTransaction.kt +++ b/core/src/main/kotlin/net/corda/core/transactions/BaseTransaction.kt @@ -27,8 +27,8 @@ abstract class BaseTransaction : NamedByHash { } private fun checkNotarySetIfInputsPresent() { - if (notary == null) { - check(inputs.isEmpty()) { "The notary must be specified explicitly for any transaction that has inputs" } + if (inputs.isNotEmpty()) { + check(notary != null) { "The notary must be specified explicitly for any transaction that has inputs" } } } diff --git a/core/src/main/kotlin/net/corda/core/transactions/WireTransaction.kt b/core/src/main/kotlin/net/corda/core/transactions/WireTransaction.kt index c3492655f1..7d2e382f2d 100644 --- a/core/src/main/kotlin/net/corda/core/transactions/WireTransaction.kt +++ b/core/src/main/kotlin/net/corda/core/transactions/WireTransaction.kt @@ -33,8 +33,9 @@ data class WireTransaction( ) : CoreTransaction(), TraversableTransaction { init { checkBaseInvariants() + check(inputs.isNotEmpty() || outputs.isNotEmpty()) { "A transaction must contain at least one input or output state" } + check(commands.isNotEmpty()) { "A transaction must contain at least one command" } if (timeWindow != null) check(notary != null) { "Transactions with time-windows must be notarised" } - check(availableComponents.isNotEmpty()) { "A WireTransaction cannot be empty" } } /** The transaction id is represented by the root hash of Merkle tree over the transaction components. */