答案 0 :(得分:0)
基于相同的Example CorDapp,这是一个RPC客户端,它在节点的保管库中查询值为99的IOU:
public class ExampleClientRPC {
public static void main(String[] args) {
final NetworkHostAndPort nodeAddress = NetworkHostAndPort.parse("localhost:10005");
final CordaRPCClient client = new CordaRPCClient(nodeAddress, CordaRPCClientConfiguration.DEFAULT);
final CordaRPCConnection connection = client.start("user1", "test");
final CordaRPCOps proxy = connection.getProxy();
CordaX500Name partyBName = new CordaX500Name("PartyB", "London", "GB");
Party partyB = proxy.wellKnownPartyFromX500Name(partyBName);
try {
proxy.startFlowDynamic(ExampleFlow.Initiator.class, 97, partyB).getReturnValue().get();
proxy.startFlowDynamic(ExampleFlow.Initiator.class, 98, partyB).getReturnValue().get();
proxy.startFlowDynamic(ExampleFlow.Initiator.class, 99, partyB).getReturnValue().get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
QueryCriteria generalCriteria = new QueryCriteria.VaultQueryCriteria(Vault.StateStatus.UNCONSUMED);
Field valueField = null;
try {
valueField = IOUSchemaV1.PersistentIOU.class.getDeclaredField("value");
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
QueryCriteria iouQuery = new VaultCustomQueryCriteria(Builder.equal(valueField, 99));
generalCriteria = generalCriteria.and(iouQuery);
List<StateAndRef<IOUState>> results = proxy.vaultQueryBy(generalCriteria,
new PageSpecification(1, 10),
new Sort(Collections.emptySet()),
IOUState.class).getStates();
for (StateAndRef<IOUState> result : results) {
System.out.println(result);
}
connection.notifyServerAndClose();
}
}