備忘69

個人的な備忘録です。細かいtips多め。


Hyperledger Composer Node.js SDK から Fabric Network のクエリを実行する場合の定形

コード

var bizNetworkConnection = new BusinessNetworkConnection();
bizNetworkConnection.connect(connectionProfileName, businessNetworkIdentifier, user, password)
        .then(() => {
            // exec a query
            return bizNetworkConnection.query('specificQuery',{parameter:value});
        })
        .then((results) => {
            return Promise.all(results.map( (result) => {
                    // output or substitute
                    console.log(result.specificField);               
                }));
        })
        .catch((error) => {
            throw error;
        })
        .then(() => {
            return bizNetworkConnection.disconnect();
        });;

説明

bizNetworkConnection.query()Resource クラスのアレイを返し、要素の各フィールドにpropertyとしてアクセスできる。
AssetRegistryParticipantRegistry と勘違いして toJSON メソッドを使ったらエラーになったため覚書き。

注意点

composer-client@0.13.0の段階のもの。現在は変更あり。
Writing a Node.js application | Hyperledger Composer