如何在hyperledger-composer事务处理器中定义BusinessNetworkConnection? [英] how to define BusinessNetworkConnection in hyperledger-composer transaction processor?

查看:51
本文介绍了如何在hyperledger-composer事务处理器中定义BusinessNetworkConnection?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my hyperledger-composer app, I have a transaction processor:

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?

How can I define the BusinessNetworkConnection?

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

*******************************UPDATE**************************************

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

Following the comment by Paul O'Mahony, I used the following line of code in my transaction processor function (in order to get the patient with the email address 'adam@gmail.com'):

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

查询是在querys.qry文件中定义的,如下所示:

The query is defined in the queries.qry file as follows:

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

但是,查询返回"undefined"(即变量"result"未定义).

However, the query returns "undefined" (i.e. variable "result" is undefined) .

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

What for god's sake is wrong with the code? I just can't see what might be the causing this behaviour.

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

***************************Update2*****************************************

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

I have to correct myself ... the query returns something ... but when I want to access the id of the returned patient, this is not possible. That is,

result.id is "undefined"

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

How can I access the id of the patient returned?

推荐答案

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

this is because you are (above) writing client code inside a native transaction function - you don't need to set these. Transaction processor functions are automatically invoked by the runtime when transactions are submitted (eg using the BusinessNetworkConnection API under the covers, but it is already part of the transaction - you don't need to specify) . See https://hyperledger.github.io/composer/latest/reference/js_scripts for more info - and the sample networks for common use cases and examples -> https://github.com/hyperledger/composer-sample-networks/tree/master/packages/

这篇关于如何在hyperledger-composer事务处理器中定义BusinessNetworkConnection?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆