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,
|
||||
override val progressTracker: ProgressTracker = tracker()) : FlowLogic<Unit>() {
|
||||
override val progressTracker: ProgressTracker = tracker()) : FlowLogic<Void?>() {
|
||||
companion object {
|
||||
object VERIFYING : ProgressTracker.Step("Verifying state replacement proposal")
|
||||
object APPROVING : ProgressTracker.Step("State replacement approved")
|
||||
@ -126,7 +128,7 @@ abstract class AbstractStateReplacementFlow {
|
||||
|
||||
@Suspendable
|
||||
@Throws(StateReplacementException::class)
|
||||
override fun call() {
|
||||
override fun call(): Void? {
|
||||
progressTracker.currentStep = VERIFYING
|
||||
val maybeProposal: UntrustworthyData<Proposal<T>> = receive(otherSide)
|
||||
val stx: SignedTransaction = maybeProposal.unwrap {
|
||||
@ -135,6 +137,7 @@ abstract class AbstractStateReplacementFlow {
|
||||
it.stx
|
||||
}
|
||||
approve(stx)
|
||||
return null
|
||||
}
|
||||
|
||||
@Suspendable
|
||||
|
@ -85,15 +85,17 @@ object NotaryFlow {
|
||||
*
|
||||
* Additional transaction validation logic can be added when implementing [receiveAndVerifyTx].
|
||||
*/
|
||||
// See AbstractStateReplacementFlow.Acceptor for why it's Void?
|
||||
abstract class Service(val otherSide: Party,
|
||||
val timestampChecker: TimestampChecker,
|
||||
val uniquenessProvider: UniquenessProvider) : FlowLogic<Unit>() {
|
||||
val uniquenessProvider: UniquenessProvider) : FlowLogic<Void?>() {
|
||||
@Suspendable
|
||||
override fun call() {
|
||||
override fun call(): Void? {
|
||||
val (id, inputs, timestamp) = receiveAndVerifyTx()
|
||||
validateTimestamp(timestamp)
|
||||
commitInputStates(inputs, 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