Skip to content

Commit

Permalink
Merge "[FAB-7160] Samples - readme sample commands"
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith Smith authored and Gerrit Code Review committed Jan 2, 2018
2 parents 0503e75 + 7428f64 commit cd18887
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 64 deletions.
52 changes: 27 additions & 25 deletions balance-transfer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>"
}
```

Expand All @@ -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",
Expand All @@ -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"]
Expand All @@ -145,40 +145,41 @@ 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

```
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",
Expand All @@ -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"]
}'
Expand All @@ -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"
```

Expand All @@ -215,26 +217,26 @@ 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

```
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"
```

Expand All @@ -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"
```

Expand All @@ -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"
```

Expand All @@ -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"
```

Expand Down
8 changes: 6 additions & 2 deletions balance-transfer/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions balance-transfer/app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 5 additions & 3 deletions balance-transfer/app/instantiate-chaincode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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
};
Expand Down
6 changes: 4 additions & 2 deletions balance-transfer/app/invoke-transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit cd18887

Please sign in to comment.