【问题标题】:Creating Abstract and Concrete Flow in Corda在 Corda 中创建抽象流和具体流
【发布时间】:2018-11-08 00:59:52
【问题描述】:

我正在用 Java 编写一个 Corda 流,使用抽象类作为启动流,但有一个具体的实现。我收到一条日志,告诉我抽象流已注册以启动响应程序流,但我在日志中看不到任何错误。然而,当我做一个流列表时,我在列表中看不到那个流,当我尝试做一个 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()));


    }


} .   

【问题讨论】:

    标签: corda


    【解决方案1】:

    您需要将@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")
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-11-04
      • 1970-01-01
      • 2021-11-13
      • 2020-06-08
      • 2016-04-25
      • 2020-03-01
      • 1970-01-01
      • 2018-08-05
      • 1970-01-01
      相关资源
      最近更新 更多