我有这段代码,我想触发另一个节点在流内部运行特定的流。当请求者节点运行IssuanceFlow时,当它触发Approver以运行ApproverIssuanceFlow时,我希望在该流中有一些代码。我想使用ApproverIssuanceFlow的输出作为IssuanceFlow下一步的输入。
公共类IssuanceFlow {
@InitiatingFlow
@StartableByRPC
public static class IssuanceInitiator extends FlowLogic<SignedTransaction> {
private Amount<Currency> amount;
public IssuanceInitiator(Amount<Currency> amount) {
this.amount = amount;
}
//STEP GENERATOR
private final ProgressTracker.Step GENERATE_TRX = new ProgressTracker.Step("Generating trx.");
private final ProgressTracker.Step VERIFY_TRX = new ProgressTracker.Step("Verify trx.");
private final ProgressTracker.Step SIGN_TRX = new ProgressTracker.Step("Sign trx.");
private final ProgressTracker.Step GATHER_SIGN = new ProgressTracker.Step("Collecting other sign.") {
@Override
public ProgressTracker childProgressTracker() {
return CollectSignaturesFlow.Companion.tracker();
}
};
private final ProgressTracker.Step FINALIZE_TRX = new ProgressTracker.Step("Notarize and record.") {
@Override
public ProgressTracker childProgressTracker() {
return FinalityFlow.Companion.tracker();
}
};
public ProgressTracker progressTracker = new ProgressTracker(
GENERATE_TRX,
VERIFY_TRX,
SIGN_TRX,
GATHER_SIGN,
FINALIZE_TRX
);
@Override
public ProgressTracker getProgressTracker() {
return progressTracker;
}
@Suspendable
@Override
public SignedTransaction call() throws FlowException {
//obtain notary
final Party notary =getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);
progressTracker.setCurrentStep(GENERATE_TRX);
UniqueIdentifier linearID = new UniqueIdentifier();
Date issuanceDate = new Date();
Party approver = getServiceHub().getNetworkMapCache().getPeerByLegalName(CordaX500Name.parse("O=Approver,L=Jakarta,C=ID")); //always choose Central Bank as approver
**// I want to trigger another node to run another flow, and use the output in this flow**
//build output
IssuanceState newIssuance = new IssuanceState(linearID, this.amount, this.getOurIdentity(), approver, issuanceDate);
//build transaction
TransactionBuilder transactionBuilder = new TransactionBuilder(notary)
.addOutputState(newIssuance)
.addCommand(new IssuanceContract.Commands.Issue(), Arrays.asList(getOurIdentity().getOwningKey(), approver.getOwningKey()));
progressTracker.setCurrentStep(VERIFY_TRX);
//verify transaction
transactionBuilder.verify(getServiceHub());
progressTracker.setCurrentStep(SIGN_TRX);
//sign transaction
final SignedTransaction partiallySign = getServiceHub().signInitialTransaction(transactionBuilder);
progressTracker.setCurrentStep(GATHER_SIGN);
//send to counterparty, back with signature
FlowSession otherPartySession = initiateFlow(approver);
final SignedTransaction fullySign = subFlow(new CollectSignaturesFlow(partiallySign,Arrays.asList(otherPartySession)));
progressTracker.setCurrentStep(FINALIZE_TRX);
//notarize, record transaction
final SignedTransaction finalityFlow = subFlow(new FinalityFlow(fullySign, Arrays.asList(otherPartySession)));
return finalityFlow;
}
}
@InitiatedBy(IssuanceInitiator.class)
public static class IssuanceResponder extends FlowLogic<Void> {
private FlowSession otherPartySession;
public IssuanceResponder(FlowSession otherPartySession) {
this.otherPartySession = otherPartySession;
}
@Override
@Suspendable
public Void call() throws FlowException {
SignedTransaction signedTransaction = subFlow(new SignTransactionFlow(otherPartySession) {
@Override
@Suspendable
protected void checkTransaction(@NotNull SignedTransaction stx) throws FlowException {
}
});
//stored to db
subFlow(new ReceiveFinalityFlow(otherPartySession,signedTransaction.getId()));
return null;
}
}发布于 2022-10-11 23:44:47
您不能在其他节点中触发任何东西,如果一方能够在其他各方的节点中触发意外行为,则这将是对安全性的重大破坏。记住,其他节点一般都是其他公司、竞争对手、法律实体。
您想要做的事情可以通过使用p2p或sendAndReceive在各方之间进行简单的sendAndReceive通信来实现(文档是这里)。它们允许启动器流向接收方发送消息,接收方可以发送回另一条消息。这个响应可能是您下一步需要做的任何事情的输入。无论如何,所有这些都需要在流中的会话中完成,因此在PartyA (发起者)和接收方( PartyB )之间的事务中。
https://stackoverflow.com/questions/74024280
复制相似问题