mirror of
https://github.com/corda/corda.git
synced 2025-06-06 01:11:45 +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) {
|
for ((inputs, outputs, key) in groups) {
|
||||||
when (command.value) {
|
when (command.value) {
|
||||||
is Commands.Agree -> {
|
is Commands.Agree -> verifyAgree(inputs, outputs)
|
||||||
val irs = outputs.filterIsInstance<InterestRateSwap.State>().single()
|
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 {
|
requireThat {
|
||||||
"There are no in states for an agreement" by inputs.isEmpty()
|
"There are no in states for an agreement" by inputs.isEmpty()
|
||||||
"There are events in the fix schedule" by (irs.calculation.fixedLegPaymentSchedule.size > 0)
|
"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))
|
checkLegAmounts(arrayOf(irs.fixedLeg, irs.floatingLeg))
|
||||||
checkLegDates(arrayOf(irs.fixedLeg, irs.floatingLeg))
|
checkLegDates(arrayOf(irs.fixedLeg, irs.floatingLeg))
|
||||||
}
|
}
|
||||||
is Commands.Fix -> {
|
|
||||||
val irs = outputs.filterIsInstance<InterestRateSwap.State>().single()
|
private fun verifyFix(inputs: List<State>, outputs: List<State>, tx: TransactionForContract) {
|
||||||
val prevIrs = inputs.filterIsInstance<InterestRateSwap.State>().single()
|
val irs = outputs.filterIsInstance<State>().single()
|
||||||
|
val prevIrs = inputs.filterIsInstance<State>().single()
|
||||||
val paymentDifferences = getFloatingLegPaymentsDifferences(prevIrs.calculation.floatingLegPaymentSchedule, irs.calculation.floatingLegPaymentSchedule)
|
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
|
// 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 .
|
// "The fixing is not in the future " by (fixCommand) // The oracle should not have signed this .
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is Commands.Pay -> {
|
|
||||||
|
private fun verifyPay() {
|
||||||
requireThat {
|
requireThat {
|
||||||
"Payments not supported / verifiable yet" by false
|
"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 {
|
requireThat {
|
||||||
"No more fixings to be applied" by (irs.calculation.nextFixingDate() == null)
|
"No more fixings to be applied" by (irs.calculation.nextFixingDate() == null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> throw IllegalArgumentException("Unrecognised verifiable command: ${command.value}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Commands : CommandData {
|
interface Commands : CommandData {
|
||||||
class Fix : TypeOnlyCommandData(), Commands // Receive interest rate from oracle, Both sides agree
|
class Fix : TypeOnlyCommandData(), Commands // Receive interest rate from oracle, Both sides agree
|
||||||
class Pay : TypeOnlyCommandData(), Commands // Not implemented just yet
|
class Pay : TypeOnlyCommandData(), Commands // Not implemented just yet
|
||||||
|
Loading…
x
Reference in New Issue
Block a user