【发布时间】: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