Merge "[FAB-7160] Samples - readme sample commands"

This commit is contained in:
Keith Smith 2018-01-02 19:47:15 +00:00 committed by Gerrit Code Review
commit cd18887f4b
7 changed files with 78 additions and 64 deletions

View file

@ -108,7 +108,7 @@ cd fabric-samples/balance-transfer
"success": true,
"secret": "RaxhMgevgJcm",
"message": "Jim enrolled Successfully",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTQ4NjU1OTEsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTQ4NjE5OTF9.yWaJhFDuTvMQRaZIqg20Is5t-JJ_1BP58yrNLOKxtNI"
"token": "<put JSON Web Token here>"
}
```
@ -119,7 +119,7 @@ The response contains the success/failure status, an **enrollment Secret** and a
```
curl -s -X POST \
http://localhost:4000/channels \
-H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTQ4NjU1OTEsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTQ4NjE5OTF9.yWaJhFDuTvMQRaZIqg20Is5t-JJ_1BP58yrNLOKxtNI" \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json" \
-d '{
"channelName":"mychannel",
@ -134,7 +134,7 @@ Please note that the Header **authorization** must contain the JWT returned from
```
curl -s -X POST \
http://localhost:4000/channels/mychannel/peers \
-H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTQ4NjU1OTEsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTQ4NjE5OTF9.yWaJhFDuTvMQRaZIqg20Is5t-JJ_1BP58yrNLOKxtNI" \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json" \
-d '{
"peers": ["peer0.org1.example.com","peer1.org1.example.com"]
@ -145,30 +145,30 @@ curl -s -X POST \
```
curl -s -X POST \
http://localhost:4000/chaincodes \
-H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTQ4NjU1OTEsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTQ4NjE5OTF9.yWaJhFDuTvMQRaZIqg20Is5t-JJ_1BP58yrNLOKxtNI" \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json" \
-d '{
"peers": ["peer0.org1.example.com","peer1.org1.example.com"],
"chaincodeName":"mycc",
"chaincodePath":"github.com/example_cc",
"chaincodePath":"github.com/example_cc/go",
"chaincodeType": "golang",
"chaincodeVersion":"v0"
}'
```
**NOTE:** *chaincodeType* must be set to **node** when node.js chaincode is used and *chaincodePath* must be set to the location of the node.js chaincode.
**NOTE:** *chaincodeType* must be set to **node** when node.js chaincode is used and *chaincodePath* must be set to the location of the node.js chaincode. Also put in the $PWD
```
ex:
curl -s -X POST \
http://localhost:4000/chaincodes \
-H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTQ4NjU1OTEsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTQ4NjE5OTF9.yWaJhFDuTvMQRaZIqg20Is5t-JJ_1BP58yrNLOKxtNI" \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json" \
-d "{
\"peers\": [\"peer0.org1.example.com\",\"peer1.org1.example.com\"],
\"chaincodeName\":\"mycc\",
\"chaincodePath\":\"$PWD/artifacts/src/github.com/example_cc/node\",
\"chaincodeType\": \"node\",
\"chaincodeVersion\":\"v0\"
}"
-d '{
"peers": ["peer0.org1.example.com","peer1.org1.example.com"],
"chaincodeName":"mycc",
"chaincodePath":"$PWD/artifacts/src/github.com/example_cc/node",
"chaincodeType": "node",
"chaincodeVersion":"v0"
}'
```
### Instantiate chaincode
@ -176,9 +176,10 @@ curl -s -X POST \
```
curl -s -X POST \
http://localhost:4000/channels/mychannel/chaincodes \
-H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTQ4NjU1OTEsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTQ4NjE5OTF9.yWaJhFDuTvMQRaZIqg20Is5t-JJ_1BP58yrNLOKxtNI" \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json" \
-d '{
"peers": ["peer0.org1.example.com","peer1.org1.example.com"],
"chaincodeName":"mycc",
"chaincodeVersion":"v0",
"chaincodeType": "golang",
@ -192,9 +193,10 @@ curl -s -X POST \
```
curl -s -X POST \
http://localhost:4000/channels/mychannel/chaincodes/mycc \
-H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTQ4NjU1OTEsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTQ4NjE5OTF9.yWaJhFDuTvMQRaZIqg20Is5t-JJ_1BP58yrNLOKxtNI" \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json" \
-d '{
"peers": ["peer0.org1.example.com","peer1.org1.example.com"],
"fcn":"move",
"args":["a","b","10"]
}'
@ -206,7 +208,7 @@ curl -s -X POST \
```
curl -s -X GET \
"http://localhost:4000/channels/mychannel/chaincodes/mycc?peer=peer0.org1.example.com&fcn=query&args=%5B%22a%22%5D" \
-H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTQ4NjU1OTEsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTQ4NjE5OTF9.yWaJhFDuTvMQRaZIqg20Is5t-JJ_1BP58yrNLOKxtNI" \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json"
```
@ -215,18 +217,18 @@ curl -s -X GET \
```
curl -s -X GET \
"http://localhost:4000/channels/mychannel/blocks/1?peer=peer0.org1.example.com" \
-H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTQ4NjU1OTEsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTQ4NjE5OTF9.yWaJhFDuTvMQRaZIqg20Is5t-JJ_1BP58yrNLOKxtNI" \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json"
```
### Query Transaction by TransactionID
```
curl -s -X GET http://localhost:4000/channels/mychannel/transactions/TRX_ID?peer=peer0.org1.example.com \
-H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTQ4NjU1OTEsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTQ4NjE5OTF9.yWaJhFDuTvMQRaZIqg20Is5t-JJ_1BP58yrNLOKxtNI" \
curl -s -X GET http://localhost:4000/channels/mychannel/transactions/<put transaction id here>?peer=peer0.org1.example.com \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json"
```
**NOTE**: Here the TRX_ID can be from any previous invoke transaction, see results of the invoke request, will look something like `8a95b1794cb17e7772164c3f1292f8410fcfdc1943955a35c9764a21fcd1d1b3`.
**NOTE**: The transaction id can be from any previous invoke transaction, see results of the invoke request, will look something like `8a95b1794cb17e7772164c3f1292f8410fcfdc1943955a35c9764a21fcd1d1b3`.
### Query ChainInfo
@ -234,7 +236,7 @@ curl -s -X GET http://localhost:4000/channels/mychannel/transactions/TRX_ID?peer
```
curl -s -X GET \
"http://localhost:4000/channels/mychannel?peer=peer0.org1.example.com" \
-H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTQ4NjU1OTEsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTQ4NjE5OTF9.yWaJhFDuTvMQRaZIqg20Is5t-JJ_1BP58yrNLOKxtNI" \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json"
```
@ -243,7 +245,7 @@ curl -s -X GET \
```
curl -s -X GET \
"http://localhost:4000/chaincodes?peer=peer0.org1.example.com&type=installed" \
-H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTQ4NjU1OTEsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTQ4NjE5OTF9.yWaJhFDuTvMQRaZIqg20Is5t-JJ_1BP58yrNLOKxtNI" \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json"
```
@ -252,7 +254,7 @@ curl -s -X GET \
```
curl -s -X GET \
"http://localhost:4000/chaincodes?peer=peer0.org1.example.com&type=instantiated" \
-H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTQ4NjU1OTEsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTQ4NjE5OTF9.yWaJhFDuTvMQRaZIqg20Is5t-JJ_1BP58yrNLOKxtNI" \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json"
```
@ -261,7 +263,7 @@ curl -s -X GET \
```
curl -s -X GET \
"http://localhost:4000/channels?peer=peer0.org1.example.com" \
-H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTQ4NjU1OTEsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTQ4NjE5OTF9.yWaJhFDuTvMQRaZIqg20Is5t-JJ_1BP58yrNLOKxtNI" \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json"
```

View file

@ -126,11 +126,13 @@ app.post('/users', async function(req, res) {
orgName: orgName
}, app.get('secret'));
let response = await helper.getRegisteredUser(username, orgName, true);
logger.debug('Successfully returned from registering the username %s for organization %s',username,orgName);
logger.debug('-- returned from registering the username %s for organization %s',username,orgName);
if (response && typeof response !== 'string') {
logger.debug('Successfully registered the username %s for organization %s',username,orgName);
response.token = token;
res.json(response);
} else {
logger.debug('Failed to register the username %s for organization %s with::%s',username,orgName,response);
res.json({success: false, message: response});
}
@ -215,12 +217,14 @@ app.post('/chaincodes', async function(req, res) {
// Instantiate chaincode on target peers
app.post('/channels/:channelName/chaincodes', async function(req, res) {
logger.debug('==================== INSTANTIATE CHAINCODE ==================');
var peers = req.body.peers;
var chaincodeName = req.body.chaincodeName;
var chaincodeVersion = req.body.chaincodeVersion;
var channelName = req.params.channelName;
var chaincodeType = req.body.chaincodeType;
var fcn = req.body.fcn;
var args = req.body.args;
logger.debug('peers : ' + peers);
logger.debug('channelName : ' + channelName);
logger.debug('chaincodeName : ' + chaincodeName);
logger.debug('chaincodeVersion : ' + chaincodeVersion);
@ -248,7 +252,7 @@ app.post('/channels/:channelName/chaincodes', async function(req, res) {
return;
}
let message = await instantiate.instantiateChaincode(channelName, chaincodeName, chaincodeVersion, chaincodeType, fcn, args, req.username, req.orgname);
let message = await instantiate.instantiateChaincode(peers, channelName, chaincodeName, chaincodeVersion, chaincodeType, fcn, args, req.username, req.orgname);
res.send(message);
});
// Invoke transaction on chaincode on target peers

View file

@ -20,9 +20,6 @@ logger.setLevel('DEBUG');
var path = require('path');
var util = require('util');
var fs = require('fs-extra');
var User = require('fabric-client/lib/User.js');
var crypto = require('crypto');
var copService = require('fabric-ca-client');
var hfc = require('fabric-client');
@ -85,6 +82,7 @@ var getRegisteredUser = async function(username, userOrg, isJson) {
logger.info('Successfully loaded member from persistence');
} else {
// user was not enrolled, so we will need an admin user object to register
logger.info('User %s was not enrolled, so we will need an admin user object to register',username);
var admins = hfc.getConfigSetting('admins');
let adminUserObj = await client.setUserContext({username: admins[0].username, password: admins[0].secret});
let caClient = client.getCertificateAuthority();

View file

@ -21,7 +21,7 @@ var hfc = require('fabric-client');
var helper = require('./helper.js');
var logger = helper.getLogger('instantiate-chaincode');
var instantiateChaincode = async function(channelName, chaincodeName, chaincodeVersion, functionName, chaincodeType, args, username, org_name) {
var instantiateChaincode = async function(peers, channelName, chaincodeName, chaincodeVersion, functionName, chaincodeType, args, username, org_name) {
logger.debug('\n\n============ Instantiate chaincode on channel ' + channelName +
' ============\n');
var error_message = null;
@ -45,6 +45,7 @@ var instantiateChaincode = async function(channelName, chaincodeName, chaincodeV
// send proposal to endorser
var request = {
targets : peers,
chaincodeId: chaincodeName,
chaincodeType: chaincodeType,
chaincodeVersion: chaincodeVersion,
@ -128,10 +129,11 @@ var instantiateChaincode = async function(channelName, chaincodeName, chaincodeV
});
var orderer_request = {
txId: tx_id, //must includethe transaction id so that the outbound
txId: tx_id, // must include the transaction id so that the outbound
// transaction to the orderer will be signed by the admin
// id as was the proposal above, notice that transactionID
// generated above was based on the admin id not userContext.
// generated above was based on the admin id not the current
// user assigned to the 'client' instance.
proposalResponses: proposalResponses,
proposal: proposal
};

View file

@ -42,6 +42,7 @@ var invokeChaincode = async function(peerNames, channelName, chaincodeName, fcn,
// send proposal to endorser
var request = {
targets: peerNames,
chaincodeId: chaincodeName,
fcn: fcn,
args: args,
@ -167,9 +168,10 @@ var invokeChaincode = async function(peerNames, channelName, chaincodeName, fcn,
if (!error_message) {
let message = util.format(
'Successfully invoked the chaincode %s to the channel \'%s\'',
org_name, channelName);
'Successfully invoked the chaincode %s to the channel \'%s\' for transaction ID: %s',
org_name, channelName, tx_id_string);
logger.info(message);
return tx_id_string;
} else {
let message = util.format('Failed to invoke chaincode. cause:%s',error_message);

View file

@ -553,9 +553,9 @@
"integrity": "sha1-Ys8SAjTGg3hdkCNIqADvPgzCC8A="
},
"fabric-ca-client": {
"version": "1.1.0-snapshot.25",
"resolved": "https://registry.npmjs.org/fabric-ca-client/-/fabric-ca-client-1.1.0-snapshot.25.tgz",
"integrity": "sha512-mhMasJ/y7pkzF4EJi4zk4mjKu/DGy6NyRCzmX9bV2SW0Kyqz4UMFmOe5iV9P0BXTDm31peplp2XCvRNyH3MV+g==",
"version": "1.1.0-snapshot.39",
"resolved": "https://registry.npmjs.org/fabric-ca-client/-/fabric-ca-client-1.1.0-snapshot.39.tgz",
"integrity": "sha512-6aG5Y2+ZcVOxEyTdY/AJpJ/hJbJT6NL9mQh8NfigfAy9ywZjWJfr5B5EAYT0eD0YBbu8b5JspytbPVMm4qPxwA==",
"requires": {
"bn.js": "4.11.8",
"elliptic": "6.4.0",
@ -564,7 +564,7 @@
"jsrsasign": "6.2.2",
"jssha": "2.3.1",
"nconf": "0.8.5",
"sjcl": "1.0.3",
"sjcl": "1.0.7",
"sjcl-codec": "0.1.1",
"url": "0.11.0",
"util": "0.10.3",
@ -582,13 +582,18 @@
"path-is-absolute": "1.0.1",
"rimraf": "2.6.2"
}
},
"sjcl": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/sjcl/-/sjcl-1.0.7.tgz",
"integrity": "sha1-MrNlpQ3Ju6JriLo8nfjqNCF9n0U="
}
}
},
"fabric-client": {
"version": "1.1.0-snapshot.25",
"resolved": "https://registry.npmjs.org/fabric-client/-/fabric-client-1.1.0-snapshot.25.tgz",
"integrity": "sha512-gZYoVvs1Q1BzIY8HZZi6adl7OerDaqxiCbCErivv6s23vgHYmcvulFIvhQZQt3IdBiT25yOnhfdpcjlj5d4O7w==",
"version": "1.1.0-snapshot.39",
"resolved": "https://registry.npmjs.org/fabric-client/-/fabric-client-1.1.0-snapshot.39.tgz",
"integrity": "sha512-NKgtVdDI8GuWseUXJVMb528+31bueb0aPKeXps1eyEkZu/bX0JmkSw5/YypWoMPeMlk2x6iiFl5WhTWd2ThXHA==",
"requires": {
"bn.js": "4.11.8",
"callsite": "1.0.0",
@ -607,7 +612,7 @@
"path": "0.12.7",
"pkcs11js": "1.0.10",
"promise-settle": "0.3.0",
"sjcl": "1.0.3",
"sjcl": "1.0.7",
"sjcl-codec": "0.1.1",
"stream-buffers": "3.0.1",
"tar-stream": "1.5.2",
@ -627,6 +632,11 @@
"path-is-absolute": "1.0.1",
"rimraf": "2.6.2"
}
},
"sjcl": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/sjcl/-/sjcl-1.0.7.tgz",
"integrity": "sha1-MrNlpQ3Ju6JriLo8nfjqNCF9n0U="
}
}
},
@ -1333,13 +1343,6 @@
}
}
},
"string_decoder": {
"version": "1.0.3",
"bundled": true,
"requires": {
"safe-buffer": "5.1.1"
}
},
"string-width": {
"version": "1.0.2",
"bundled": true,
@ -1349,6 +1352,13 @@
"strip-ansi": "3.0.1"
}
},
"string_decoder": {
"version": "1.0.3",
"bundled": true,
"requires": {
"safe-buffer": "5.1.1"
}
},
"stringstream": {
"version": "0.0.5",
"bundled": true
@ -2247,11 +2257,6 @@
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz",
"integrity": "sha1-ZlZ+NwQ+608E2RvWWMDL77VbjgQ="
},
"sjcl": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/sjcl/-/sjcl-1.0.3.tgz",
"integrity": "sha1-TtSGSY7Wt0K11KIZAiaBFvBUpwk="
},
"sjcl-codec": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/sjcl-codec/-/sjcl-codec-0.1.1.tgz",
@ -2307,14 +2312,6 @@
"resolved": "https://registry.npmjs.org/stream-buffers/-/stream-buffers-3.0.1.tgz",
"integrity": "sha1-aKOMX6re3tef95mI02jj+xMl7wY="
},
"string_decoder": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
"integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
"requires": {
"safe-buffer": "5.1.1"
}
},
"string-width": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
@ -2325,6 +2322,14 @@
"strip-ansi": "3.0.1"
}
},
"string_decoder": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
"integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
"requires": {
"safe-buffer": "5.1.1"
}
},
"stringstream": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz",

View file

@ -159,13 +159,14 @@ curl -s -X POST \
echo
echo
echo "POST invoke chaincode on peers of Org1 and Org2"
echo "POST invoke chaincode on peers of Org1"
echo
TRX_ID=$(curl -s -X POST \
http://localhost:4000/channels/mychannel/chaincodes/mycc \
-H "authorization: Bearer $ORG1_TOKEN" \
-H "content-type: application/json" \
-d '{
"peers": ["peer0.org1.example.com","peer1.org1.example.com"],
"fcn":"move",
"args":["a","b","10"]
}')