diff --git a/contracts/src/main/java/com/r3corda/contracts/JavaCommercialPaper.java b/contracts/src/main/java/com/r3corda/contracts/JavaCommercialPaper.java index b2a1997354..3fe14944e0 100644 --- a/contracts/src/main/java/com/r3corda/contracts/JavaCommercialPaper.java +++ b/contracts/src/main/java/com/r3corda/contracts/JavaCommercialPaper.java @@ -127,7 +127,10 @@ public class JavaCommercialPaper implements Contract { public interface Clauses { class Group extends GroupClauseVerifier { - public Group() { + // This complains because we're passing generic types into a varargs, but it is valid so we suppress the + // warning. + @SuppressWarnings("unchecked") + Group() { super(new AnyComposition<>( new Clauses.Redeem(), new Clauses.Move(), diff --git a/contracts/src/main/kotlin/com/r3corda/contracts/CommercialPaper.kt b/contracts/src/main/kotlin/com/r3corda/contracts/CommercialPaper.kt index 21e61320d2..c2ebea1e02 100644 --- a/contracts/src/main/kotlin/com/r3corda/contracts/CommercialPaper.kt +++ b/contracts/src/main/kotlin/com/r3corda/contracts/CommercialPaper.kt @@ -95,8 +95,8 @@ class CommercialPaper : Contract { inputs: List, outputs: List, commands: List>, - token: Issued?): Set { - val consumedCommands = super.verify(tx, inputs, outputs, commands, token) + groupingKey: Issued?): Set { + val consumedCommands = super.verify(tx, inputs, outputs, commands, groupingKey) commands.requireSingleCommand() val timestamp = tx.timestamp val time = timestamp?.before ?: throw IllegalArgumentException("Issuances must be timestamped") diff --git a/contracts/src/main/kotlin/com/r3corda/contracts/asset/Obligation.kt b/contracts/src/main/kotlin/com/r3corda/contracts/asset/Obligation.kt index 8dca61e63c..56baa4fa34 100644 --- a/contracts/src/main/kotlin/com/r3corda/contracts/asset/Obligation.kt +++ b/contracts/src/main/kotlin/com/r3corda/contracts/asset/Obligation.kt @@ -325,7 +325,7 @@ class Obligation

: Contract { * Net two or more obligation states together in a close-out netting style. Limited to bilateral netting * as only the beneficiary (not the obligor) needs to sign. */ - data class Net(val type: NetType) : Commands + data class Net(override val type: NetType) : NetCommand, Commands /** * A command stating that a debt has been moved, optionally to fulfil another contract. diff --git a/contracts/src/main/kotlin/com/r3corda/contracts/clause/Net.kt b/contracts/src/main/kotlin/com/r3corda/contracts/clause/Net.kt index 674150aa61..8b9b4252f8 100644 --- a/contracts/src/main/kotlin/com/r3corda/contracts/clause/Net.kt +++ b/contracts/src/main/kotlin/com/r3corda/contracts/clause/Net.kt @@ -51,7 +51,8 @@ open class NetClause : Clause() { outputs: List, commands: List>, groupingKey: Unit?): Set { - val command = commands.requireSingleCommand() + val matchedCommands: List> = commands.filter { it.value is NetCommand } + val command = matchedCommands.requireSingleCommand() val groups = when (command.value.type) { NetType.CLOSE_OUT -> tx.groupStates { it: Obligation.State

-> it.bilateralNetState } NetType.PAYMENT -> tx.groupStates { it: Obligation.State

-> it.multilateralNetState } @@ -59,7 +60,7 @@ open class NetClause : Clause() { for ((groupInputs, groupOutputs, key) in groups) { verifyNetCommand(groupInputs, groupOutputs, command, key) } - return setOf(command.value as C) + return matchedCommands.map { it.value }.toSet() } /** @@ -68,7 +69,7 @@ open class NetClause : Clause() { @VisibleForTesting fun verifyNetCommand(inputs: List>, outputs: List>, - command: AuthenticatedObject, + command: AuthenticatedObject, netState: NetState

) { val template = netState.template // Create two maps of balances from obligors to beneficiaries, one for input states, the other for output states. diff --git a/core/src/main/kotlin/com/r3corda/core/contracts/Structures.kt b/core/src/main/kotlin/com/r3corda/core/contracts/Structures.kt index b8c949a97c..b62d81cbd1 100644 --- a/core/src/main/kotlin/com/r3corda/core/contracts/Structures.kt +++ b/core/src/main/kotlin/com/r3corda/core/contracts/Structures.kt @@ -355,6 +355,12 @@ interface MoveCommand : CommandData { val contractHash: SecureHash? } +/** A common netting command for contracts whose states can be netted. */ +interface NetCommand : CommandData { + /** The type of netting to apply, see [NetType] for options. */ + val type: NetType +} + /** Wraps an object that was signed by a public key, which may be a well known/recognised institutional key. */ data class AuthenticatedObject( val signers: List, diff --git a/core/src/main/kotlin/com/r3corda/core/contracts/clauses/AnyComposition.kt b/core/src/main/kotlin/com/r3corda/core/contracts/clauses/AnyComposition.kt index 9e9ebe9fa2..00d7e671f4 100644 --- a/core/src/main/kotlin/com/r3corda/core/contracts/clauses/AnyComposition.kt +++ b/core/src/main/kotlin/com/r3corda/core/contracts/clauses/AnyComposition.kt @@ -9,7 +9,7 @@ import java.util.* /** * Compose a number of clauses, such that any number of the clauses can run. */ -class AnyComposition(vararg val rawClauses: Clause) : CompositeClause() { +class AnyComposition(vararg rawClauses: Clause) : CompositeClause() { override val clauses: List> = rawClauses.asList() override fun matchedClauses(commands: List>): List> = clauses.filter { it.matches(commands) }