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としてアクセスできる。
AssetRegistry
や ParticipantRegistry
と勘違いして toJSON
メソッドを使ったらエラーになったため覚書き。
注意点
composer-client@0.13.0
の段階のもの。現在は変更あり。
Writing a Node.js application | Hyperledger Composer