如何解决#hyperledger-Composer V0.14解组错误

时间:2017-11-10 16:30:43

标签: node.js hyperledger-composer

我刚刚从V0.13.2移动到V0.14.2,现在在事件处理中遇到以下错误。错误似乎出现在作曲家 - 客户端代码中,而不是我的。关于解决的任何想法?我的应用程序仍在发布和处理事件,因此我的代码仍然可以正常工作,但是这些错误消息的存在令人不安,并且它们的音量超出了我的控制台窗口。

error: [EventHub.js]: on.data - Error unmarshalling transaction= TypeError: Cannot read property 'getSerializer' of null
    at events.forEach (<path>Z2B_Master/Chapter12/node_modules/composer-client/lib/businessnetworkconnection.js:483:73)
    at Array.forEach (native)
    at HLFConnection.connection.on (<path>Z2B_Master/Chapter12/node_modules/composer-client/lib/businessnetworkconnection.js:482:29)
    at emitOne (events.js:96:13)
    at HLFConnection.emit (events.js:188:7)
    at ChainCodeCBE.ccEvent.eventHubs.(anonymous function).registerChaincodeEvent [as onEvent] (<path>Z2B_Master/Chapter12/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:231:22)
    at <path>Z2B_Master/Chapter12/node_modules/fabric-client/lib/EventHub.js:810:12
    at Set.forEach (native)
    at EventHub._processChainCodeOnEvents (<path>Z2B_Master/Chapter12/node_modules/fabric-client/lib/EventHub.js:808:14)
    at ClientDuplexStream.<anonymous> (<path>Z2B_Master/Chapter12/node_modules/fabric-client/lib/EventHub.js:311:10)

使用V0.13中的相同代码不存在此错误。

所有事件都是通过sample.js文件中的单个函数发出的。事务调用函数,如以下示例所示:

/**
 * create an order to purchase
 * @param {org.acme.Z2BTestNetwork.CreateOrder} purchase - the order to be processed
 * @transaction
 */
function CreateOrder(purchase) {
    purchase.order.buyer = purchase.buyer;
    purchase.order.amount = purchase.amount;
    purchase.order.financeCo = purchase.financeCo;
    purchase.order.created = new Date().toISOString();
    purchase.order.status = JSON.stringify(orderStatus.Created);
    return getAssetRegistry('org.acme.Z2BTestNetwork.Order')
        .then(function (assetRegistry) {
            return assetRegistry.update(purchase.order)
            .then (function (_res) 
            {
                z2bEmit('Created', purchase.order);
                return (_res);
            }).catch(function(error){return(error);});
        });
}

每个事务都使用唯一的_event字符串调用z2bEmit函数。

function z2bEmit(_event, _order)
{
    var method = 'z2bEmit';
    var factory = getFactory();
    var z2bEvent = factory.newEvent(ns, _event);
    z2bEvent.orderID = _order.$identifier;
    z2bEvent.buyerID = _order.buyer.$identifier;
    emit(z2bEvent);
    return
}

_order是cto文件中已定义的资产,_event是cto文件中已定义的事件。

客户端代码有一个例程,执行一次,以设置监控:

/**
 * Register for all of the available Z2BEvents
 * @param {express.req} req - the inbound request object from the client
 * @param {express.res} res - the outbound response object for communicating back to client
 * @param {express.next} next - an express service to enable post processing prior to responding to the client
*/
exports.init_z2bEvents = function (req, res, next)
{
    var method = 'init_z2bEvents';
    if (bRegistered) {res.send('Already Registered');}
    else{
        bRegistered = true;
        let _conn = svc.createAlertSocket();
        let businessNetworkConnection;
        businessNetworkConnection = new BusinessNetworkConnection();
        // following line added to deal with eventListener error message that more eventListeners needed to be added
        businessNetworkConnection.setMaxListeners(50);
        return businessNetworkConnection.connect(config.composer.connectionProfile, config.composer.network, config.composer.adminID, config.composer.adminPW)
        .then(() => {
            businessNetworkConnection.on('event', (event) => {_monitor(svc.al_connection, svc.f_connection, event); });
            res.send('event registration complete');
        }).catch((error) => {
            console.log(method+' business network connection failed'+error.message); 
            res.send(method+' business network connection failed'+error.message);
        });
    }
}

connectionProfile是&#39; hlfv1&#39;

和一个监视程序,它可以确定发布了什么类型的事件,然后使用Web套接字将该信息发送到浏览器,以便发布或更新警报图标。该函数的缩短版本如下。 _conn _f_conn继续正常工作。 _event信息正在传入并继续正确解析。无论程序运行多长时间,都会在每个警报上显示eventhub.js消息。

/**
 * _monitor
 * @param {web.socket} _conn - web socket connection for general alerts
 * @param {web.socket} _f_conn - web socket for finance alerts
 * @param {org.acme.z2bNetwork.Event} _event - the event just emitted
 * 
 */
function _monitor(_conn, _f_conn, _event)
{
    var method = '_monitor';
    console.log(method+ ' _event received: '+_event.$type+' for Order: '+_event.orderID);
    var event = {};
    event.type = _event.$type;
    event.orderID = _event.orderID;
    event.ID = _event.buyerID;
    _conn.sendUTF(JSON.stringify(event));

    switch (_event.$type)
    {
        case 'Created':
        break;
        case 'Bought':
        case 'PaymentRequested':
            event.ID = _event.sellerID;
            _conn.sendUTF(JSON.stringify(event));
            event.ID = _event.financeCoID;
            _f_conn.sendUTF(JSON.stringify(event));
        break;
        case 'Ordered':
        case 'Cancelled':
        case 'Backordered':
            event.ID = _event.sellerID;
            _conn.sendUTF(JSON.stringify(event));
            event.ID = _event.providerID;
            _conn.sendUTF(JSON.stringify(event));
        break;
        default:
        break;
    }

}

1 个答案:

答案 0 :(得分:1)

虽然无法确定此问题的根本原因,但它已经消失了(并升级到)hyperledger-composer V0.15.2。