如何在hyperledger-composer事务处理器中定义BusinessNetworkConnection?

时间:2018-07-23 13:17:11

标签: hyperledger-composer

在我的hyperledger-composer应用程序中,我有一个交易处理器:

az cosmosdb collection create -d stackoverflow -c test1
--name <mycosmosaccountname> --key "<mycosmosaccountkey>"
--throughput 400

az cosmosdb collection create -d stackoverflow -c test2
--name <mycosmosaccountname> --key "<mycosmosaccountkey>"
--partition-key-path "/foo" --throughput 3000

但是,行

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();

如何定义BusinessNetworkConnection?

*******************************更新*************** ***********************

在Paul O'Mahony的评论之后,我在交易处理器功能中使用了以下代码行(以使患者的电子邮件地址为“ adam@gmail.com”):

ReferenceError: BusinessNetworkConnection is not defined

查询在querys.qry文件中定义如下:

let result = await query('selectPatientByEmail', {
    "email": "adam@gmail.com"    
});

但是,查询返回“ undefined”(即变量“ result”未定义)。

看在上帝的份上,代码有什么问题?我只是看不到是什么原因引起的。

***************************更新2 ******************* **********************

我必须纠正自己……查询返回了某些内容……但是当我想访问返回的患者的ID时,这是不可能的。也就是说,

query selectPatientByEmail {
    description: "Select the patient with the given email address"
    statement:
        SELECT org.comp.app.Patient
            WHERE (email == _$email)
}

如何获取返回患者的身份证?

1 个答案:

答案 0 :(得分:1)

这是因为(上面)您正在本机事务功能内编写客户端代码-无需设置这些代码。提交事务时,运行时会自动调用事务处理器功能(例如,使用幕后的BusinessNetworkConnection API,但它已经是事务的一部分-无需指定)。有关更多信息,请参见https://hyperledger.github.io/composer/latest/reference/js_scripts-有关常见用例和示例的示例网络-> https://github.com/hyperledger/composer-sample-networks/tree/master/packages/

相关问题