diff --git a/src/main/kotlin/protocols/RatesFixProtocol.kt b/src/main/kotlin/protocols/RatesFixProtocol.kt index 227b0a8b34..ad955983d8 100644 --- a/src/main/kotlin/protocols/RatesFixProtocol.kt +++ b/src/main/kotlin/protocols/RatesFixProtocol.kt @@ -27,11 +27,11 @@ import java.util.* * * @throws FixOutOfRange if the returned fix was further away from the expected rate by the given amount. */ -class RatesFixProtocol(private val tx: TransactionBuilder, - private val oracle: LegallyIdentifiableNode, - private val fixOf: FixOf, - private val expectedRate: BigDecimal, - private val rateTolerance: BigDecimal) : ProtocolLogic() { +open class RatesFixProtocol(protected val tx: TransactionBuilder, + private val oracle: LegallyIdentifiableNode, + private val fixOf: FixOf, + private val expectedRate: BigDecimal, + private val rateTolerance: BigDecimal) : ProtocolLogic() { companion object { val TOPIC = "platform.rates.interest.fix" } @@ -46,9 +46,18 @@ class RatesFixProtocol(private val tx: TransactionBuilder, val fix = query() checkFixIsNearExpected(fix) tx.addCommand(fix, oracle.identity.owningKey) + beforeSigning(fix) tx.addSignatureUnchecked(sign()) } + /** + * You can override this to perform any additional work needed after the fix is added to the transaction but + * before it's sent back to the oracle for signing (for example, adding output states that depend on the fix). + */ + @Suspendable + protected open fun beforeSigning(fix: Fix) { + } + private fun checkFixIsNearExpected(fix: Fix) { val delta = (fix.value - expectedRate).abs() if (delta > rateTolerance) {