mirror of
https://github.com/corda/corda.git
synced 2025-02-07 03:29:19 +00:00
Correct warnings
This commit is contained in:
parent
b913b18e02
commit
9cccc7a2b7
@ -127,7 +127,10 @@ public class JavaCommercialPaper implements Contract {
|
|||||||
|
|
||||||
public interface Clauses {
|
public interface Clauses {
|
||||||
class Group extends GroupClauseVerifier<State, Commands, State> {
|
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<>(
|
super(new AnyComposition<>(
|
||||||
new Clauses.Redeem(),
|
new Clauses.Redeem(),
|
||||||
new Clauses.Move(),
|
new Clauses.Move(),
|
||||||
|
@ -95,8 +95,8 @@ class CommercialPaper : Contract {
|
|||||||
inputs: List<State>,
|
inputs: List<State>,
|
||||||
outputs: List<State>,
|
outputs: List<State>,
|
||||||
commands: List<AuthenticatedObject<Commands>>,
|
commands: List<AuthenticatedObject<Commands>>,
|
||||||
token: Issued<Terms>?): Set<Commands> {
|
groupingKey: Issued<Terms>?): Set<Commands> {
|
||||||
val consumedCommands = super.verify(tx, inputs, outputs, commands, token)
|
val consumedCommands = super.verify(tx, inputs, outputs, commands, groupingKey)
|
||||||
commands.requireSingleCommand<Commands.Issue>()
|
commands.requireSingleCommand<Commands.Issue>()
|
||||||
val timestamp = tx.timestamp
|
val timestamp = tx.timestamp
|
||||||
val time = timestamp?.before ?: throw IllegalArgumentException("Issuances must be timestamped")
|
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
|
* 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.
|
* 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.
|
* 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>,
|
outputs: List<ContractState>,
|
||||||
commands: List<AuthenticatedObject<C>>,
|
commands: List<AuthenticatedObject<C>>,
|
||||||
groupingKey: Unit?): Set<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) {
|
val groups = when (command.value.type) {
|
||||||
NetType.CLOSE_OUT -> tx.groupStates { it: Obligation.State<P> -> it.bilateralNetState }
|
NetType.CLOSE_OUT -> tx.groupStates { it: Obligation.State<P> -> it.bilateralNetState }
|
||||||
NetType.PAYMENT -> tx.groupStates { it: Obligation.State<P> -> it.multilateralNetState }
|
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) {
|
for ((groupInputs, groupOutputs, key) in groups) {
|
||||||
verifyNetCommand(groupInputs, groupOutputs, command, key)
|
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
|
@VisibleForTesting
|
||||||
fun verifyNetCommand(inputs: List<Obligation.State<P>>,
|
fun verifyNetCommand(inputs: List<Obligation.State<P>>,
|
||||||
outputs: List<Obligation.State<P>>,
|
outputs: List<Obligation.State<P>>,
|
||||||
command: AuthenticatedObject<Obligation.Commands.Net>,
|
command: AuthenticatedObject<NetCommand>,
|
||||||
netState: NetState<P>) {
|
netState: NetState<P>) {
|
||||||
val template = netState.template
|
val template = netState.template
|
||||||
// Create two maps of balances from obligors to beneficiaries, one for input states, the other for output states.
|
// 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?
|
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. */
|
/** 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>(
|
data class AuthenticatedObject<out T : Any>(
|
||||||
val signers: List<PublicKey>,
|
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.
|
* 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 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) }
|
override fun matchedClauses(commands: List<AuthenticatedObject<C>>): List<Clause<S, C, K>> = clauses.filter { it.matches(commands) }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user