mirror of
https://github.com/corda/corda.git
synced 2025-05-02 08:43:15 +00:00
Java code can now extend core FlowLogics which don't return anything (by using Void? instead of Unit)
This commit is contained in:
parent
24ae89db18
commit
ade32b16cb
@ -115,8 +115,10 @@ abstract class AbstractStateReplacementFlow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Type parameter should ideally be Unit but that prevents Java code from subclassing it (https://youtrack.jetbrains.com/issue/KT-15964).
|
||||||
|
// We use Void? instead of Unit? as that's what you'd use in Java.
|
||||||
abstract class Acceptor<in T>(val otherSide: Party,
|
abstract class Acceptor<in T>(val otherSide: Party,
|
||||||
override val progressTracker: ProgressTracker = tracker()) : FlowLogic<Unit>() {
|
override val progressTracker: ProgressTracker = tracker()) : FlowLogic<Void?>() {
|
||||||
companion object {
|
companion object {
|
||||||
object VERIFYING : ProgressTracker.Step("Verifying state replacement proposal")
|
object VERIFYING : ProgressTracker.Step("Verifying state replacement proposal")
|
||||||
object APPROVING : ProgressTracker.Step("State replacement approved")
|
object APPROVING : ProgressTracker.Step("State replacement approved")
|
||||||
@ -126,7 +128,7 @@ abstract class AbstractStateReplacementFlow {
|
|||||||
|
|
||||||
@Suspendable
|
@Suspendable
|
||||||
@Throws(StateReplacementException::class)
|
@Throws(StateReplacementException::class)
|
||||||
override fun call() {
|
override fun call(): Void? {
|
||||||
progressTracker.currentStep = VERIFYING
|
progressTracker.currentStep = VERIFYING
|
||||||
val maybeProposal: UntrustworthyData<Proposal<T>> = receive(otherSide)
|
val maybeProposal: UntrustworthyData<Proposal<T>> = receive(otherSide)
|
||||||
val stx: SignedTransaction = maybeProposal.unwrap {
|
val stx: SignedTransaction = maybeProposal.unwrap {
|
||||||
@ -135,6 +137,7 @@ abstract class AbstractStateReplacementFlow {
|
|||||||
it.stx
|
it.stx
|
||||||
}
|
}
|
||||||
approve(stx)
|
approve(stx)
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suspendable
|
@Suspendable
|
||||||
|
@ -85,15 +85,17 @@ object NotaryFlow {
|
|||||||
*
|
*
|
||||||
* Additional transaction validation logic can be added when implementing [receiveAndVerifyTx].
|
* Additional transaction validation logic can be added when implementing [receiveAndVerifyTx].
|
||||||
*/
|
*/
|
||||||
|
// See AbstractStateReplacementFlow.Acceptor for why it's Void?
|
||||||
abstract class Service(val otherSide: Party,
|
abstract class Service(val otherSide: Party,
|
||||||
val timestampChecker: TimestampChecker,
|
val timestampChecker: TimestampChecker,
|
||||||
val uniquenessProvider: UniquenessProvider) : FlowLogic<Unit>() {
|
val uniquenessProvider: UniquenessProvider) : FlowLogic<Void?>() {
|
||||||
@Suspendable
|
@Suspendable
|
||||||
override fun call() {
|
override fun call(): Void? {
|
||||||
val (id, inputs, timestamp) = receiveAndVerifyTx()
|
val (id, inputs, timestamp) = receiveAndVerifyTx()
|
||||||
validateTimestamp(timestamp)
|
validateTimestamp(timestamp)
|
||||||
commitInputStates(inputs, id)
|
commitInputStates(inputs, id)
|
||||||
signAndSendResponse(id)
|
signAndSendResponse(id)
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package net.corda.flows;
|
||||||
|
|
||||||
|
import net.corda.core.crypto.Party;
|
||||||
|
import net.corda.core.utilities.ProgressTracker;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class AbstractStateReplacementFlowTest {
|
||||||
|
|
||||||
|
// Acceptor used to have a type parameter of Unit which prevented Java code from subclassing it (https://youtrack.jetbrains.com/issue/KT-15964).
|
||||||
|
private static class TestAcceptorCanBeInheritedInJava extends AbstractStateReplacementFlow.Acceptor {
|
||||||
|
public TestAcceptorCanBeInheritedInJava(@NotNull Party otherSide, @NotNull ProgressTracker progressTracker) {
|
||||||
|
super(otherSide, progressTracker);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void verifyProposal(@NotNull AbstractStateReplacementFlow.Proposal proposal) {}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user