Hyperledger Fabric SDK例fabric-samples-『balance-transfer』の4『chaincodeのインストール』
22197 ワード
本文はすでに私の公衆番号Fabric技術でオリジナルの先発を分かち合った.転載は出典を明記してください.https://blog.csdn.net/qq_27818541/article/details/78361292出典:【BigManingのブログ】
sdkを使用してchaincodeをインストールする場合は、次のパラメータを指定する必要があります. chaincode名称 chaincodeバージョン chaincodeファイルパス 本明細書の例で伝達されるchaincodeのパスは
このルートは2つのことしかしていません必要パラメータチェック は、chaincode の実装を具体的に実現するために、パッケージ化された
Created with Raphal2.1.2 Start設定gopath環境変数admin組立request呼び出しclientインストールchaincode処理結果を取得し、すべてのインストールに成功したEnd yes no
コンソール印刷:
バックグラウンド印刷:
前言
sdkを使用してchaincodeをインストールする場合は、次のパラメータを指定する必要があります.
github.com/example_cc
であり、システムはgopath
のパスの下のsrc
ディレクトリの中のgithub.com/example_cc
の下のchaincodeファイルをロードする.gopath
の動作を設定し、具体的なインプリメンテーションで説明する.ルート
app.js
// peer chaincode
app.post('/chaincodes', function(req, res) {
//1
logger.debug('==================== INSTALL CHAINCODE ==================');
var peers = req.body.peers;
var chaincodeName = req.body.chaincodeName;
var chaincodePath = req.body.chaincodePath;
var chaincodeVersion = req.body.chaincodeVersion;
// chaincode peer
logger.debug('peers : ' + peers); // target peers list
// chaincode
logger.debug('chaincodeName : ' + chaincodeName);
//chaincode
logger.debug('chaincodePath : ' + chaincodePath);
//chaincode
logger.debug('chaincodeVersion : ' + chaincodeVersion);
if (!peers || peers.length == 0) {
res.json(getErrorMessage('\'peers\''));
return;
}
if (!chaincodeName) {
res.json(getErrorMessage('\'chaincodeName\''));
return;
}
if (!chaincodePath) {
res.json(getErrorMessage('\'chaincodePath\''));
return;
}
if (!chaincodeVersion) {
res.json(getErrorMessage('\'chaincodeVersion\''));
return;
}
// 2 install-chaincode.js
install.installChaincode(peers, chaincodeName, chaincodePath, chaincodeVersion, req.username, req.orgname)
.then(function(message) {
res.send(message);
});
});
このルートは2つのことしかしていません
installChaincode
方法を呼び出す.具体的な実装
install-chaincode.js
var path = require('path');
var fs = require('fs');
var util = require('util');
var config = require('../config.json');
var helper = require('./helper.js');
var logger = helper.getLogger('install-chaincode');
var tx_id = null;
var installChaincode = function(peers, chaincodeName, chaincodePath,
chaincodeVersion, username, org) {
logger.debug(
'
============ Install chaincode on organizations ============
');
// gopath balance-transfer/artifacts/ chaincode
helper.setupChaincodeDeploy();
var channel = helper.getChannelForOrg(org);
var client = helper.getClientForOrg(org);
//1 admin
return helper.getOrgAdmin(org).then((user) => {
//2 request
var request = {
targets: helper.newPeers(peers, org), // peer rpc
chaincodePath: chaincodePath,
chaincodeId: chaincodeName,
chaincodeVersion: chaincodeVersion
};
//3 , chaincode
return client.installChaincode(request);
}, (err) => {
logger.error('Failed to enroll user \'' + username + '\'. ' + err);
throw new Error('Failed to enroll user \'' + username + '\'. ' + err);
}).then((results) => {
var proposalResponses = results[0];
var proposal = results[1];
var all_good = true;
// 4
for (var i in proposalResponses) {
let one_good = false;
if (proposalResponses && proposalResponses[i].response &&
proposalResponses[i].response.status === 200) {
one_good = true;
logger.info('install proposal was good');
} else {
logger.error('install proposal was bad');
}
all_good = all_good & one_good;
}
//
if (all_good) {
logger.info(util.format(
'Successfully sent install Proposal and received ProposalResponse: Status - %s',
proposalResponses[0].response.status));
logger.debug('
Successfully Installed chaincode on organization ' + org +
'
');
return 'Successfully Installed chaincode on organization ' + org;
} else {
logger.error(
'Failed to send install Proposal or receive valid response. Response null or status is not 200. exiting...'
);
return 'Failed to send install Proposal or receive valid response. Response null or status is not 200. exiting...';
}
}, (err) => {
logger.error('Failed to send install proposal due to error: ' + err.stack ?
err.stack : err);
throw new Error('Failed to send install proposal due to error: ' + err.stack ?
err.stack : err);
});
};
exports.installChaincode = installChaincode;
基本プロセス
Created with Raphal2.1.2 Start設定gopath環境変数admin組立request呼び出しclientインストールchaincode処理結果を取得し、すべてのインストールに成功したEnd yes no
APIアクセス
github.com/example_cc
このパスは、gopath
環境変数から検索されます.echo "POST Install chaincode on Org1"
echo
curl -s -X POST \
http://localhost:4000/chaincodes \
-H "authorization: Bearer $ORG1_TOKEN" \
-H "content-type: application/json" \
-d '{
"peers": ["peer1", "peer2"],
"chaincodeName":"mycc",
"chaincodePath":"github.com/example_cc",
"chaincodeVersion":"v0"
}'
echo
echo
コンソール印刷:
POST Install chaincode on Org1
Successfully Installed chaincode on organization org1
バックグラウンド印刷:
[2017-10-16 11:07:12.352] [DEBUG] SampleWebApp - Decoded from JWT token: username - Jim, orgname - org1
[2017-10-16 11:07:12.352] [DEBUG] SampleWebApp - ==================== INSTALL CHAINCODE ==================
[2017-10-16 11:07:12.352] [DEBUG] SampleWebApp - peers : peer1,peer2
[2017-10-16 11:07:12.352] [DEBUG] SampleWebApp - chaincodeName : mycc
[2017-10-16 11:07:12.353] [DEBUG] SampleWebApp - chaincodePath : github.com/example_cc
[2017-10-16 11:07:12.353] [DEBUG] SampleWebApp - chaincodeVersion : v0
[2017-10-16 11:07:12.353] [DEBUG] install-chaincode -
============ Install chaincode on organizations ============
[2017-10-16 11:07:12.353] [DEBUG] Helper - [crypto_ecdsa_aes]: constructor, keySize: 256
[2017-10-16 11:07:12.354] [DEBUG] Helper - [crypto_ecdsa_aes]: Hash algorithm: SHA2, hash output size: 256
[2017-10-16 11:07:12.354] [DEBUG] Helper - [utils.CryptoKeyStore]: CryptoKeyStore, constructor - start
[2017-10-16 11:07:12.354] [DEBUG] Helper - [utils.CryptoKeyStore]: constructor, no super class specified, using config: fabric-client/lib/impl/FileKeyValueStore.js
[2017-10-16 11:07:12.354] [DEBUG] Helper - [FileKeyValueStore.js]: FileKeyValueStore.js - constructor
[2017-10-16 11:07:12.354] [DEBUG] Helper - Msp ID : Org1MSP
[2017-10-16 11:07:12.354] [DEBUG] Helper - [crypto_ecdsa_aes]: importKey - start
[2017-10-16 11:07:12.355] [DEBUG] Helper - [crypto_ecdsa_aes]: importKey - have the key [Circular]
[2017-10-16 11:07:12.355] [DEBUG] Helper - [utils.CryptoKeyStore]: This class requires a CryptoKeyStore to save keys, using the store: {"opts":{"path":"/tmp/fabric-client-kvs_peerOrg1"}}
[2017-10-16 11:07:12.355] [DEBUG] Helper - [FileKeyValueStore.js]: FileKeyValueStore.js - constructor
[2017-10-16 11:07:12.356] [DEBUG] Helper - [utils.CryptoKeyStore]: _getKeyStore returning ks
[2017-10-16 11:07:12.356] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param X: 0a66f3503a3322b2ca8e9dce03322d486ee6ec5970efaad3f153bc13aa2d942c
[2017-10-16 11:07:12.356] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param Y: 312ad05190fa592fb9e8ac2dcdb23c84df7f49e4ee295c2aa1200a50c9146c46
[2017-10-16 11:07:12.356] [DEBUG] Helper - [FileKeyValueStore.js]: FileKeyValueStore -- setValue
[2017-10-16 11:07:12.357] [DEBUG] Helper - [crypto_ecdsa_aes]: importKey - start
[2017-10-16 11:07:12.357] [DEBUG] Helper - [crypto_ecdsa_aes]: importKey - have the key [Circular]
[2017-10-16 11:07:12.358] [DEBUG] Helper - [utils.CryptoKeyStore]: _getKeyStore resolving store
[2017-10-16 11:07:12.358] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param X: 0a66f3503a3322b2ca8e9dce03322d486ee6ec5970efaad3f153bc13aa2d942c
[2017-10-16 11:07:12.359] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param Y: 312ad05190fa592fb9e8ac2dcdb23c84df7f49e4ee295c2aa1200a50c9146c46
[2017-10-16 11:07:12.360] [DEBUG] Helper - [FileKeyValueStore.js]: FileKeyValueStore -- setValue
[2017-10-16 11:07:12.363] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param X: 0a66f3503a3322b2ca8e9dce03322d486ee6ec5970efaad3f153bc13aa2d942c
[2017-10-16 11:07:12.363] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param Y: 312ad05190fa592fb9e8ac2dcdb23c84df7f49e4ee295c2aa1200a50c9146c46
[2017-10-16 11:07:12.363] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param X: 0a66f3503a3322b2ca8e9dce03322d486ee6ec5970efaad3f153bc13aa2d942c
[2017-10-16 11:07:12.363] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param Y: 312ad05190fa592fb9e8ac2dcdb23c84df7f49e4ee295c2aa1200a50c9146c46
[2017-10-16 11:07:12.363] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param X: 0a66f3503a3322b2ca8e9dce03322d486ee6ec5970efaad3f153bc13aa2d942c
[2017-10-16 11:07:12.363] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param Y: 312ad05190fa592fb9e8ac2dcdb23c84df7f49e4ee295c2aa1200a50c9146c46
[2017-10-16 11:07:12.363] [DEBUG] Helper - [FileKeyValueStore.js]: FileKeyValueStore -- setValue
info: [packager/Golang.js]: packaging GOLANG from github.com/example_cc
[2017-10-16 11:07:12.384] [DEBUG] Helper - [crypto_ecdsa_aes]: ecdsa signature: Signature {
r: 98e0e079bcad1db53e72e6e001b03f8c76c50c499bc0237a1b8db341231a6341>,
s: 23b0d0657eeaccc22def7a429c888c08a83dec55e56bc89fe34964319d6ac875>,
recoveryParam: 1 }
[2017-10-16 11:07:12.400] [INFO] install-chaincode - install proposal was good
[2017-10-16 11:07:12.400] [INFO] install-chaincode - install proposal was good
[2017-10-16 11:07:12.401] [INFO] install-chaincode - Successfully sent install Proposal and received ProposalResponse: Status - 200
[2017-10-16 11:07:12.401] [DEBUG] install-chaincode -
Successfully Installed chaincode on organization org1