mirror of
https://github.com/corda/corda.git
synced 2025-03-23 12:35:23 +00:00
RatesFixProtocol: add an empty, overridable beforeSigning method that lets you customise the logic of the protocol.
This commit is contained in:
parent
2c20c8745b
commit
4e15755883
@ -27,11 +27,11 @@ import java.util.*
|
|||||||
*
|
*
|
||||||
* @throws FixOutOfRange if the returned fix was further away from the expected rate by the given amount.
|
* @throws FixOutOfRange if the returned fix was further away from the expected rate by the given amount.
|
||||||
*/
|
*/
|
||||||
class RatesFixProtocol(private val tx: TransactionBuilder,
|
open class RatesFixProtocol(protected val tx: TransactionBuilder,
|
||||||
private val oracle: LegallyIdentifiableNode,
|
private val oracle: LegallyIdentifiableNode,
|
||||||
private val fixOf: FixOf,
|
private val fixOf: FixOf,
|
||||||
private val expectedRate: BigDecimal,
|
private val expectedRate: BigDecimal,
|
||||||
private val rateTolerance: BigDecimal) : ProtocolLogic<Unit>() {
|
private val rateTolerance: BigDecimal) : ProtocolLogic<Unit>() {
|
||||||
companion object {
|
companion object {
|
||||||
val TOPIC = "platform.rates.interest.fix"
|
val TOPIC = "platform.rates.interest.fix"
|
||||||
}
|
}
|
||||||
@ -46,9 +46,18 @@ class RatesFixProtocol(private val tx: TransactionBuilder,
|
|||||||
val fix = query()
|
val fix = query()
|
||||||
checkFixIsNearExpected(fix)
|
checkFixIsNearExpected(fix)
|
||||||
tx.addCommand(fix, oracle.identity.owningKey)
|
tx.addCommand(fix, oracle.identity.owningKey)
|
||||||
|
beforeSigning(fix)
|
||||||
tx.addSignatureUnchecked(sign())
|
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) {
|
private fun checkFixIsNearExpected(fix: Fix) {
|
||||||
val delta = (fix.value - expectedRate).abs()
|
val delta = (fix.value - expectedRate).abs()
|
||||||
if (delta > rateTolerance) {
|
if (delta > rateTolerance) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user