【问题标题】:Can you create flow sessions for multiple participants in Corda您可以在 Corda 中为多个参与者创建流程会话吗
【发布时间】:2020-06-11 17:20:15
【问题描述】:

我一直在尝试学习 Corda,并且我有一个涉及多个参与者的合同的特定用例。 如果我的理解不正确,请原谅我,如果我错了,请纠正我! :)

据我了解,合约是我们为调用所述合约的交易实施验证功能的地方。 状态可以保存当前交易的“状态”以及有关交易的任何数据。 流程是与状态/合同相关的业务逻辑。

我有一个想要在合同中解决的特定用例,这涉及共享相同合同/交易信息的多方。 我希望一个状态能够容纳多个参与者。

据我所知,我为一个状态编写了以下代码:

@BelongsToContract(MasterContract.class)
public class MasterState implements ContractState {

    private final List<Party> employers = emptyList();
    private final List<Party> contractors = emptyList();
    private final String projectName;

    public MasterState(String projectName, List<Party> employers, List<Party> contractors) {
        this.projectName = projectName;
        this.employers.addAll(employers);
        this.contractors.addAll(contractors);
    }

    public String getProjectName() {
        return projectName;
    }

    public List<Party> getEmployers() {
        return employers;
    }

    public List<Party> getContractors() {
        return contractors;
    }

    @Override
    public List<AbstractParty> getParticipants() {
        List<AbstractParty> allParts = new ArrayList<>();
        allParts.addAll(employers);
        allParts.addAll(contractors);
        return allParts;
    }
}

我希望能够通过提供多个“雇主”或“承包商”来创建(通过命令)MasterContract 的新实例。 我正在尝试定义:MasterCreationFlow.call() 如下:

@Suspendable
    @Override
    public Void call() throws FlowException {
        Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);

        // Create the transaction components
        JCTMasterState outputState = new JCTMasterState(projectName, Arrays.asList(getOurIdentity()), contractors);

        //List of required signers:
        List<PublicKey> requiredSigners = Arrays.asList(getOurIdentity().getOwningKey());
        requiredSigners.addAll(getOwningKeys(contractors));

        Command createCommand = new Command<>(new JCTMasterContract.Create(), requiredSigners);
...

但是,我坚持InitiateFlow() 的想法。看来您只能在两方之间执行此操作。我知道 Corda 是点对点的。但我想了解FlowSession 到底是做什么的?到目前为止,我已经读到FlowSessions 只是两方之间的一个通道,然后由一些 SubFlow 使用。有没有办法扩展FlowSession 以在多个交易对手之间创建共享会话?还是我必须启动多个流程?

提前致谢!

【问题讨论】:

    标签: corda


    【解决方案1】:

    你说得对,FlowSession 在两方之间,即调用initiateFlow(someParty) 方法和someParty 的一方。

    因此,为了让您在流程发起人和承包商之间创建多个会话,您可以这样做:

    Set<FlowSession> sessions = contractors.stream().map(it -> 
                                initiateFlow(it)).collect(Collectors.toSet());
    

    然后,例如,您可以通过会话来收集承包商的签名:

    final SignedTransaction fullySignedTx = subFlow(new CollectSignaturesFlow(partSignedTx, 
                                        sessions, CollectSignaturesFlow.Companion.tracker()));
    

    【讨论】:

    • 感谢您的回答!就像对您的代码的后续问题,以澄清我的误解: 1. partSignedTx 是通过签署初始交易创建的吗? final SignedTransaction partSignedTx = getServiceHub().signInitialTransaction(txBuilder); 2. 要使用fullySignedTx 并完成交易,我是否这样做...? subFlow(new FinalityFlow(fullySignedTx, sessions));
    • 是的,流程的发起者总是对交易进行签名;然后将其发送给其他方。您添加的代码是正确的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-02
    • 1970-01-01
    • 2010-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多