Enforce transaction validity rules

This commit is contained in:
Andrius Dagys 2017-08-07 12:26:48 +01:00
parent 76ffd485ac
commit f5776d6bd7
2 changed files with 4 additions and 3 deletions

View File

@ -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" }
}
}

View File

@ -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. */