mirror of
https://github.com/corda/corda.git
synced 2025-06-02 07:30:53 +00:00
Split IRS verification into individual functions
This commit is contained in:
parent
3257640e7f
commit
49b58d8a43
@ -504,8 +504,17 @@ class InterestRateSwap() : Contract {
|
||||
|
||||
for ((inputs, outputs, key) in groups) {
|
||||
when (command.value) {
|
||||
is Commands.Agree -> {
|
||||
val irs = outputs.filterIsInstance<InterestRateSwap.State>().single()
|
||||
is Commands.Agree -> verifyAgree(inputs, outputs)
|
||||
is Commands.Fix -> verifyFix(inputs, outputs, tx)
|
||||
is Commands.Pay -> verifyPay()
|
||||
is Commands.Mature -> verifyMature(inputs)
|
||||
else -> throw IllegalArgumentException("Unrecognised verifiable command: ${command.value}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun verifyAgree(inputs: List<State>, outputs: List<State>) {
|
||||
val irs = outputs.filterIsInstance<State>().single()
|
||||
requireThat {
|
||||
"There are no in states for an agreement" by inputs.isEmpty()
|
||||
"There are events in the fix schedule" by (irs.calculation.fixedLegPaymentSchedule.size > 0)
|
||||
@ -528,9 +537,10 @@ class InterestRateSwap() : Contract {
|
||||
checkLegAmounts(arrayOf(irs.fixedLeg, irs.floatingLeg))
|
||||
checkLegDates(arrayOf(irs.fixedLeg, irs.floatingLeg))
|
||||
}
|
||||
is Commands.Fix -> {
|
||||
val irs = outputs.filterIsInstance<InterestRateSwap.State>().single()
|
||||
val prevIrs = inputs.filterIsInstance<InterestRateSwap.State>().single()
|
||||
|
||||
private fun verifyFix(inputs: List<State>, outputs: List<State>, tx: TransactionForContract) {
|
||||
val irs = outputs.filterIsInstance<State>().single()
|
||||
val prevIrs = inputs.filterIsInstance<State>().single()
|
||||
val paymentDifferences = getFloatingLegPaymentsDifferences(prevIrs.calculation.floatingLegPaymentSchedule, irs.calculation.floatingLegPaymentSchedule)
|
||||
|
||||
// Having both of these tests are "redundant" as far as verify() goes, however, by performing both
|
||||
@ -562,23 +572,20 @@ class InterestRateSwap() : Contract {
|
||||
// "The fixing is not in the future " by (fixCommand) // The oracle should not have signed this .
|
||||
}
|
||||
}
|
||||
is Commands.Pay -> {
|
||||
|
||||
private fun verifyPay() {
|
||||
requireThat {
|
||||
"Payments not supported / verifiable yet" by false
|
||||
}
|
||||
}
|
||||
is Commands.Mature -> {
|
||||
val irs = inputs.filterIsInstance<InterestRateSwap.State>().single()
|
||||
|
||||
private fun verifyMature(inputs: List<State>) {
|
||||
val irs = inputs.filterIsInstance<State>().single()
|
||||
requireThat {
|
||||
"No more fixings to be applied" by (irs.calculation.nextFixingDate() == null)
|
||||
}
|
||||
}
|
||||
|
||||
else -> throw IllegalArgumentException("Unrecognised verifiable command: ${command.value}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface Commands : CommandData {
|
||||
class Fix : TypeOnlyCommandData(), Commands // Receive interest rate from oracle, Both sides agree
|
||||
class Pay : TypeOnlyCommandData(), Commands // Not implemented just yet
|
||||
|
Loading…
x
Reference in New Issue
Block a user