mirror of
https://github.com/corda/corda.git
synced 2025-03-22 03:55:26 +00:00
Add filter composition for clauses
This commit is contained in:
parent
06a8680d37
commit
607ba634fe
@ -9,6 +9,7 @@ import java.util.*
|
||||
/**
|
||||
* Compose a number of clauses, such that all of the clauses must run for verification to pass.
|
||||
*/
|
||||
// TODO: Rename to AllOf
|
||||
class AllComposition<S : ContractState, C : CommandData, K : Any>(firstClause: Clause<S, C, K>, vararg remainingClauses: Clause<S, C, K>) : CompositeClause<S, C, K>() {
|
||||
override val clauses = ArrayList<Clause<S, C, K>>()
|
||||
|
||||
|
@ -9,6 +9,7 @@ import java.util.*
|
||||
/**
|
||||
* Compose a number of clauses, such that any number of the clauses can run.
|
||||
*/
|
||||
// TODO: Rename to AnyOf
|
||||
class AnyComposition<in S : ContractState, C : CommandData, in K : Any>(vararg rawClauses: Clause<S, C, K>) : CompositeClause<S, C, K>() {
|
||||
override val clauses: List<Clause<S, C, K>> = rawClauses.asList()
|
||||
|
||||
|
@ -0,0 +1,25 @@
|
||||
package com.r3corda.core.contracts.clauses
|
||||
|
||||
import com.r3corda.core.contracts.AuthenticatedObject
|
||||
import com.r3corda.core.contracts.CommandData
|
||||
import com.r3corda.core.contracts.ContractState
|
||||
import com.r3corda.core.contracts.TransactionForContract
|
||||
|
||||
/**
|
||||
* Filter the states that are passed through to the wrapped clause, to restrict them to a specific type.
|
||||
*/
|
||||
class FilterOn<S : ContractState, C : CommandData, K : Any>(val clause: Clause<S, C, K>,
|
||||
val filterStates: (List<ContractState>) -> List<S>) : Clause<ContractState, C, K>() {
|
||||
override val requiredCommands: Set<Class<out CommandData>>
|
||||
= clause.requiredCommands
|
||||
|
||||
override fun getExecutionPath(commands: List<AuthenticatedObject<C>>): List<Clause<*, *, *>>
|
||||
= clause.getExecutionPath(commands)
|
||||
|
||||
override fun verify(tx: TransactionForContract,
|
||||
inputs: List<ContractState>,
|
||||
outputs: List<ContractState>,
|
||||
commands: List<AuthenticatedObject<C>>,
|
||||
groupingKey: K?): Set<C>
|
||||
= clause.verify(tx, filterStates(inputs), filterStates(outputs), commands, groupingKey)
|
||||
}
|
@ -10,6 +10,7 @@ import java.util.*
|
||||
/**
|
||||
* Compose a number of clauses, such that the first match is run, and it errors if none is run.
|
||||
*/
|
||||
// TODO: Rename to FirstOf
|
||||
class FirstComposition<S : ContractState, C : CommandData, K : Any>(val firstClause: Clause<S, C, K>, vararg remainingClauses: Clause<S, C, K>) : CompositeClause<S, C, K>() {
|
||||
companion object {
|
||||
val logger = loggerFor<FirstComposition<*, *, *>>()
|
||||
|
Loading…
x
Reference in New Issue
Block a user