mirror of
https://github.com/corda/corda.git
synced 2024-12-23 14:52:29 +00:00
commit
0fb9f37518
@ -127,7 +127,10 @@ public class JavaCommercialPaper implements Contract {
|
||||
|
||||
public interface Clauses {
|
||||
class Group extends GroupClauseVerifier<State, Commands, State> {
|
||||
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(),
|
||||
|
@ -95,8 +95,8 @@ class CommercialPaper : Contract {
|
||||
inputs: List<State>,
|
||||
outputs: List<State>,
|
||||
commands: List<AuthenticatedObject<Commands>>,
|
||||
token: Issued<Terms>?): Set<Commands> {
|
||||
val consumedCommands = super.verify(tx, inputs, outputs, commands, token)
|
||||
groupingKey: Issued<Terms>?): Set<Commands> {
|
||||
val consumedCommands = super.verify(tx, inputs, outputs, commands, groupingKey)
|
||||
commands.requireSingleCommand<Commands.Issue>()
|
||||
val timestamp = tx.timestamp
|
||||
val time = timestamp?.before ?: throw IllegalArgumentException("Issuances must be timestamped")
|
||||
|
@ -325,7 +325,7 @@ class Obligation<P> : 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.
|
||||
|
@ -51,7 +51,8 @@ open class NetClause<C: CommandData, P> : Clause<ContractState, C, Unit>() {
|
||||
outputs: List<ContractState>,
|
||||
commands: List<AuthenticatedObject<C>>,
|
||||
groupingKey: Unit?): Set<C> {
|
||||
val command = commands.requireSingleCommand<Obligation.Commands.Net>()
|
||||
val matchedCommands: List<AuthenticatedObject<C>> = commands.filter { it.value is NetCommand }
|
||||
val command = matchedCommands.requireSingleCommand<Obligation.Commands.Net>()
|
||||
val groups = when (command.value.type) {
|
||||
NetType.CLOSE_OUT -> tx.groupStates { it: Obligation.State<P> -> it.bilateralNetState }
|
||||
NetType.PAYMENT -> tx.groupStates { it: Obligation.State<P> -> it.multilateralNetState }
|
||||
@ -59,7 +60,7 @@ open class NetClause<C: CommandData, P> : Clause<ContractState, C, Unit>() {
|
||||
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<C: CommandData, P> : Clause<ContractState, C, Unit>() {
|
||||
@VisibleForTesting
|
||||
fun verifyNetCommand(inputs: List<Obligation.State<P>>,
|
||||
outputs: List<Obligation.State<P>>,
|
||||
command: AuthenticatedObject<Obligation.Commands.Net>,
|
||||
command: AuthenticatedObject<NetCommand>,
|
||||
netState: NetState<P>) {
|
||||
val template = netState.template
|
||||
// Create two maps of balances from obligors to beneficiaries, one for input states, the other for output states.
|
||||
|
@ -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<out T : Any>(
|
||||
val signers: List<PublicKey>,
|
||||
|
@ -9,7 +9,7 @@ import java.util.*
|
||||
/**
|
||||
* Compose a number of clauses, such that any number of the clauses can run.
|
||||
*/
|
||||
class AnyComposition<in S : ContractState, C : CommandData, in K : Any>(vararg val rawClauses: Clause<S, C, K>) : CompositeClause<S, C, K>() {
|
||||
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()
|
||||
|
||||
override fun matchedClauses(commands: List<AuthenticatedObject<C>>): List<Clause<S, C, K>> = clauses.filter { it.matches(commands) }
|
||||
|
@ -41,6 +41,7 @@ dependencies {
|
||||
// Log4J: logging framework (with SLF4J bindings)
|
||||
compile "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}"
|
||||
compile "org.apache.logging.log4j:log4j-core:${log4j_version}"
|
||||
compile "org.apache.logging.log4j:log4j-web:${log4j_version}"
|
||||
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
||||
|
Loading…
Reference in New Issue
Block a user