Status Constraints

To verify the Status constraints, you must obtain all of the Primary states (i.e. the AgreementStates). You can then apply a different set of tests based on the status of the AgreementState in question:

AgreementContract.kt:

    fun verifyStatusConstraints(tx: LedgerTransaction){
        val allStates = tx.inputsOfType<AgreementState>() + tx.outputsOfType<AgreementState>()

        // Note, in kotlin non-nullable properties must be populated, hence only need to check the nullable properties of the AgreementState
        for (s in allStates) {

            when(s.status){
                PROPOSED -> {
                    requireThat {
                        "When status is Proposed rejectionReason must be null." using (s.rejectionReason == null)
                        "When status is Rejected rejectedBy must be null." using (s.rejectedBy == null)
                    }
                }
                REJECTED -> {
                    requireThat {
                        "When status is Rejected rejectionReason must not be null." using (s.rejectionReason != null)
                        "When status is Rejected rejectedBy must not be null." using (s.rejectedBy != null)
                        "When the Status is Rejected rejectedBy must be the buyer or seller." using (listOf(s.buyer, s.seller).contains(s.rejectedBy))
                    }
                }
                AGREED -> {}
            }
        }
    }