首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >是否可以从其他节点的vaultservice中检索状态?

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

Stack Overflow用户
提问于 2018-04-16 19:20:40
回答 1查看 235关注 0票数 2

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

EN

回答 1

Stack Overflow用户

发布于 2018-04-24 23:08:25

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

但是,如果PartyB愿意与PartyA共享其vault的内容,您可以编写一个流对,允许PartyA从PartyB的vault请求状态。

例如,如果您想请求一个具有特定ID的LinearState,您可以这样写:

代码语言:javascript
运行
复制
@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;
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49856040

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档