是否可以从其他节点的vaultservice中检索状态?

时间:2018-04-16 11:20:40

标签: corda

我正在尝试从PartyA查询其他节点(PartyB)的保险库,其中流应由PartyA的RPC发起。如果PartyB同意分享结果,PartyA应该能够看到结果。可能吗?

1 个答案:

答案 0 :(得分:1)

没有。节点操作员只能查询自己节点的保管库。

但是,如果PartyB愿意与PartyA分享他们的保险库内容,您可以编写一个流量对,允许PartyA向PartyB的保险库申请状态。

例如,如果您想要请求具有特定ID的LinearState,您可以写:

@InitiatingFlow
@StartableByRPC
public static class RequestStateFlow extends FlowLogic<StateAndRef> {

    private final UniqueIdentifier stateLinearId;
    private final Party otherParty;

    public RequestStateFlow(UniqueIdentifier stateLinearId, Party otherParty) {
        this.stateLinearId = stateLinearId;
        this.otherParty = otherParty;
    }

    @Suspendable
    @Override
    public StateAndRef call() throws FlowException {
        FlowSession session = initiateFlow(otherParty);
        return session.sendAndReceive(StateAndRef.class, stateLinearId).unwrap(it -> it);
    }
}

@InitiatedBy(RequestStateFlow.class)
public static class SendStateFlow extends FlowLogic<Void> {

    private final FlowSession otherPartySession;

    public SendStateFlow(FlowSession otherPartySession) {
        this.otherPartySession = otherPartySession;
    }

    @Suspendable
    @Override
    public Void call() throws FlowException {
        UniqueIdentifier stateLinearId = otherPartySession.receive(UniqueIdentifier.class).unwrap(it -> it);

        QueryCriteria.LinearStateQueryCriteria criteria = new QueryCriteria.LinearStateQueryCriteria(
                null,
                ImmutableList.of(stateLinearId),
                Vault.StateStatus.UNCONSUMED,
                null);
        Vault.Page<LinearState> results = getServiceHub().getVaultService().queryBy(LinearState.class, criteria);
        StateAndRef state = results.getStates().get(0);

        otherPartySession.send(state);

        return null;
    }
}