在我的hyperledger-composer应用程序中,我有一个事务处理器:
async function doSomething(transaction) {
//some code
// the following line results in error message:
const connection = new BusinessNetworkConnection();
await connection.connect('admin@tmy-network');
const result = await connection.query(selectPatientByEmail, { inputValue: email });
//some more code
}然而,这条线
const connection = new BusinessNetworkConnection();导致以下错误消息:
ReferenceError: BusinessNetworkConnection is not defined如何定义BusinessNetworkConnection?
*******************************UPDATE**************************************
在Paul O‘’Mahony的评论之后,我在我的事务处理器函数中使用了以下代码行(为了获得电子邮件地址为‘adam@gmail.com’的患者):
let result = await query('selectPatientByEmail', {
"email": "adam@gmail.com"
});该查询在queries.qry文件中定义如下:
query selectPatientByEmail {
description: "Select the patient with the given email address"
statement:
SELECT org.comp.app.Patient
WHERE (email == _$email)
}但是,查询返回"undefined“(即变量"result”未定义)。
看在上帝的份上,代码出了什么问题?我就是看不出是什么导致了这种行为。
***************************Update2*****************************************
我得改正我自己。该查询将返回一些...但是当我想要访问返回的患者的id时,这是不可能的。那是,
result.id is "undefined"如何访问返回的患者id?
发布于 2018-07-23 21:45:26
这是因为您(上面)是在本地事务函数中编写客户端代码-您不需要设置这些代码。事务处理器函数在提交事务时由运行时自动调用(例如,在幕后使用BusinessNetworkConnection应用程序接口,但它已经是事务的一部分-您不需要指定)。有关详细信息,请参阅https://hyperledger.github.io/composer/latest/reference/js_scripts以及-> https://github.com/hyperledger/composer-sample-networks/tree/master/packages/的常见使用情形和示例的示例网络
https://stackoverflow.com/questions/51479770
复制相似问题