本机API在Web运行时中不可用。 Hyperledger作曲家

时间:2018-11-14 10:41:05

标签: hyperledger-fabric hyperledger-composer

获取特定参与者的完整日志。我正在按照此answer

的说明进行操作

和下面是代码。由于 Web运行时中没有本机API

,这在Composer Playground中引发了错误
async function participantHistory(tx) {

    const partId = tx.tradeid;
    const nativeSupport = tx.nativeSupport;
    // const partRegistry = await getParticipantRegistry('org.example.trading.Trader')

    const nativeKey = getNativeAPI().createCompositeKey('Asset:org.example.trading.Trader', [partId]);
    const iterator = await getNativeAPI().getHistoryForKey(nativeKey);
    let results = [];
    let res = {done : false};
    while (!res.done) {
        res = await iterator.next();

        if (res && res.value && res.value.value) {
            let val = res.value.value.toString('utf8');
            if (val.length > 0) {
               console.log("@debug val is  " + val );
               results.push(JSON.parse(val));
            }
        }
        if (res && res.done) {
            try {
                iterator.close();
            }
            catch (err) {
            }
        }
    }
    var newArray = [];
    for (const item of results) {
            newArray.push(getSerializer().fromJSON(item));
    }
    console.log("@debug the results to be returned are as follows: ");

    return newArray; // returns something to my NodeJS client (called via REST API)
}

文档Calling Hyperledger Fabric APIs in transaction processor functions中也提到了

请帮助如何使用此getNativeAPI。

0 个答案:

没有答案