Создание абстрактного и конкретного потока в Corda - PullRequest
0 голосов
/ 07 ноября 2018

Я пишу поток Corda на Java, используя абстрактный класс в качестве исходного потока, но имею конкретную реализацию этого. Я получаю журнал, который сообщает мне, что абстрактный поток зарегистрирован, чтобы инициировать поток респондента, и я не вижу никаких ошибок в журналах. Тем не менее, когда я делаю список потоков, я не вижу этот поток в списке и ни один, когда я пытаюсь сделать список rpcOps.registeredFlows. В чем может быть причина этого несоответствия?

   @InitiatingFlow
   @StartableByRPC
   public abstract class AbstractExampleFlow extends 
   FlowLogic<SignedTransaction> {
   private final int iouValue;
   private final Party otherParty;

   public AbstractExampleFlow(int iouValue, Party otherParty) {
        this.iouValue = iouValue;
        this.otherParty = otherParty;
   }


   protected SignedTransaction verifyAndSignQuoteRequest (TransactionBuilder txBuilder) throws FlowException {

        txBuilder.verify(getServiceHub());

       // Sign the transaction.
        final SignedTransaction partSignedTx = getServiceHub().signInitialTransaction(txBuilder);
        return partSignedTx;
    }

   @Suspendable
   protected SignedTransaction collectQuotePartySignatures
   (SignedTransaction partSignedTx) throws FlowException {
    FlowSession otherPartySession = initiateFlow(otherParty);
     final SignedTransaction fullySignedTx = subFlow(
                new CollectSignaturesFlow(partSignedTx,
                        ImmutableSet.of(otherPartySession), CollectSignaturesFlow.Companion.tracker()));
        return fullySignedTx;
    };

    protected Party obtainNotary () {
        return getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);
    }

    protected abstract SignedTransaction performAction () throws FlowException;

    protected TransactionBuilder buildQuoteRequestTransaction() {
        Party me = getServiceHub().getMyInfo().getLegalIdentities().get(0);
        IOUState iouState = new IOUState(iouValue, me, otherParty, new UniqueIdentifier());
        final Command<IOUContract.Commands.Create> txCommand = new Command<>(
                new IOUContract.Commands.Create(),
                ImmutableList.of(iouState.getLender().getOwningKey(), iouState.getBorrower().getOwningKey()));
        final TransactionBuilder txBuilder = new TransactionBuilder(obtainNotary())
                .addOutputState(iouState, IOU_CONTRACT_ID)
                .addCommand(txCommand);
        return txBuilder;
    } ;

    /**
     * The flow logic is encapsulated within the call() method.
     */
    @Suspendable
    @Override
    public SignedTransaction call() throws FlowException {
        return performAction();

    } .      

Бетон (реализация по умолчанию) выглядит следующим образом.

    public class ConcreteDefaultExampleFlow extends AbstractExampleFlow {
public ConcreteDefaultExampleFlow(int iouValue, Party otherParty) {
        super (iouValue, otherParty);
    }
    /**
     * The flow logic is encapsulated within the performAction() method.
     */
    @Suspendable
    @Override
    public SignedTransaction performAction () throws FlowException {
        System.out.println ("In the concrete default flow");
        return collectQuotePartySignatures(verifyAndSignQuoteRequest(buildQuoteRequestTransaction()));


    }


} .   

1 Ответ

0 голосов
/ 07 ноября 2018

Вам нужно добавить аннотацию @StartableByRPC к конкретной реализации, а не к абстрактному суперклассу. Например:

@InitiatingFlow
abstract class AbstractInitiator : FlowLogic<Unit>()

@StartableByRPC
class Initiator(val party: Party) : AbstractInitiator() {
    override val progressTracker = ProgressTracker()

    @Suspendable
    override fun call() {
        val session = initiateFlow(party)
        val string = session.receive<String>().unwrap { it -> it }
        logger.info(string)
    }
}

@InitiatedBy(AbstractInitiator::class)
class Responder(val counterpartySession: FlowSession) : FlowLogic<Unit>() {
    @Suspendable
    override fun call() {
        counterpartySession.send("Joel1234")
    }
}
...