Reputation: 128
I am trying to query a vault of other node (PartyB) from PartyA, where the flow should be initiated by RPC of PartyA. If PartyB agrees to share the result PartyA should be able to see the result. Is it possible?
Upvotes: 2
Views: 317
Reputation: 23140
No. The node operator can only query their own node's vault.
However, if PartyB is willing to share their vault's contents with PartyA, you can write a flow pair that will allow PartyA to request states from PartyB's vault.
For example, if you want to request a LinearState
with a specific ID, you could write:
@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;
}
}
Upvotes: 0