从corda中的给定帐户检索可观察状态时遇到问题?

从corda中的给定帐户检索可观察状态时遇到问题?,corda,Corda,我试图向一些观察者帐户广播给定的状态(一切都在帐户级别)。我面临的问题是,对于观察者来说,我无法检索我广播给它的流。广播已成功完成,我确认account_to_state_refs表以及节点本身中存在条目(我将状态从一个节点上的account广播到另一个节点上的account) 我用于检索帐户的查询如下所示: public List<StateAndRef<TradeState>> getTradeStatesByAccount(){ AccountInfo my

我试图向一些观察者帐户广播给定的状态(一切都在帐户级别)。我面临的问题是,对于观察者来说,我无法检索我广播给它的流。广播已成功完成,我确认account_to_state_refs表以及节点本身中存在条目(我将状态从一个节点上的account广播到另一个节点上的account)

我用于检索帐户的查询如下所示:

public List<StateAndRef<TradeState>> getTradeStatesByAccount(){
    AccountInfo myAccount = UtilitiesKt.getAccountService(this).accountInfo(accountName).get(0).getState().getData();
    QueryCriteria.VaultQueryCriteria criteria = new QueryCriteria.VaultQueryCriteria(Vault.StateStatus.ALL).withExternalIds(Collections.singletonList(myAccount.getIdentifier().getId()));

    List<StateAndRef<TradeState>> myOrders = getServiceHub().getVaultService().queryBy(TradeState.class,criteria).getStates();
    return myOrders;
}
在这种情况下,我如何检索我作为观察者的状态以及我作为参与方的状态?如果您需要任何其他信息,请告诉我。提前谢谢


编辑:找到了一个解决方法,添加到答案中。

通过对表本身执行JDBC查询来检索帐户作为观察者的状态的事务ID,从而解决了问题。下面是编写在corda流中的代码:

AccountInfo myAccount = UtilitiesKt.getAccountService(this).accountInfo(accountName).get(0).getState().getData();
String accId = myAccount.getLinearId().getId().toString();
String nativeQuery = "SELECT transaction_id FROM account_to_state_refs WHERE external_id=\'" + accId + "\'";
java.sql.Connection connection = getServiceHub().jdbcSession();
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(nativeQuery);

List<StateAndRef<TradeState>> result = new ArrayList<StateAndRef<TradeState>>();

// All the states related to the node
    List<StateAndRef<TradeState>> myOrders = getServiceHub().getVaultService().queryBy(TradeState.class).getStates();

// To filter out the observed states from all the states above
while ( rs.next() ) {
    String txnId = rs.getString("transaction_id");
    for (StateAndRef<TradeState> order: myOrders) {
        if(order.getRef().getTxhash().toString().equalsIgnoreCase(txnId)) {
                result.add(order);
        }
    }
}

return result;
AccountInfo myAccount=UtilitiesKt.getAccountService(this).AccountInfo(accountName).get(0).getState().getData();
字符串accId=myAccount.getLinearId().getId().toString();
String nativeQuery=“选择交易\u id从帐户\u到\u状态\u参考,其中外部\u id=\'”+accId+“\'”;
java.sql.Connection=getServiceHub().jdbcSession();
语句stmt=connection.createStatement();
结果集rs=stmt.executeQuery(nativeQuery);
列表结果=新建ArrayList();
//与节点相关的所有状态
列出myOrders=getServiceHub().getVaultService().queryBy(TradeState.class).getStates();
//从上述所有状态中筛选出观察到的状态
while(rs.next()){
String txnId=rs.getString(“事务id”);
对于(州和订单:myOrders){
if(order.getRef().getTxhash().toString().equalsIgnoreCase(txnId)){
结果。添加(订单);
}
}
}
返回结果;
这可能不是执行所需操作的最佳方式,但在我找到正确的方式之前,这对我来说是有效的

AccountInfo myAccount = UtilitiesKt.getAccountService(this).accountInfo(accountName).get(0).getState().getData();
String accId = myAccount.getLinearId().getId().toString();
String nativeQuery = "SELECT transaction_id FROM account_to_state_refs WHERE external_id=\'" + accId + "\'";
java.sql.Connection connection = getServiceHub().jdbcSession();
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(nativeQuery);

List<StateAndRef<TradeState>> result = new ArrayList<StateAndRef<TradeState>>();

// All the states related to the node
    List<StateAndRef<TradeState>> myOrders = getServiceHub().getVaultService().queryBy(TradeState.class).getStates();

// To filter out the observed states from all the states above
while ( rs.next() ) {
    String txnId = rs.getString("transaction_id");
    for (StateAndRef<TradeState> order: myOrders) {
        if(order.getRef().getTxhash().toString().equalsIgnoreCase(txnId)) {
                result.add(order);
        }
    }
}

return result;