Skip to content

Commit

Permalink
added query.js to query chaincode
Browse files Browse the repository at this point in the history
  • Loading branch information
MCLDG committed Mar 21, 2019
1 parent faf7d1a commit f2a0c72
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
5 changes: 3 additions & 2 deletions admin-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ Ignore the following instructions, under pre-requisites:
The connection profile will not be populated as described in step 3. Populate it using the template below - just copy and paste the contents:

```bash
mkdir -p ~/non-profit-blockchain/tmp/connection-profile
vi ~/non-profit-blockchain/tmp/connection-profile/ngo-connection-profile.yaml
```

Expand All @@ -284,7 +285,7 @@ profile and the one used by Admin API, is that Admin API runs on the bastion so
```bash
name: "ngo"
x-type: "hlfv1"
description: "NGO Network"
description: "Fabric Network"
version: "1.0"

channels:
Expand All @@ -298,7 +299,7 @@ channels:
ledgerQuery: true
eventSource: true
chaincodes:
- marbles-workshop:v1
- marblescc:v1

organizations:
Org1:
Expand Down
22 changes: 12 additions & 10 deletions admin-api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ app.get('/marbles', awaitHandler(async (req, res) => {
let args = {};
let fcn = "read_everything";

logger.info('##### GET on Donor - username : ' + username);
logger.info('##### GET on Donor - userOrg : ' + orgName);
logger.info('##### GET on Donor - channelName : ' + channelName);
logger.info('##### GET on Donor - chaincodeName : ' + chaincodeName);
logger.info('##### GET on Donor - fcn : ' + fcn);
logger.info('##### GET on Donor - args : ' + JSON.stringify(args));
logger.info('##### GET on Donor - peers : ' + peers);
logger.info('##### GET on Marbles - username : ' + username);
logger.info('##### GET on Marbles - userOrg : ' + orgName);
logger.info('##### GET on Marbles - channelName : ' + channelName);
logger.info('##### GET on Marbles - chaincodeName : ' + chaincodeName);
logger.info('##### GET on Marbles - fcn : ' + fcn);
logger.info('##### GET on Marbles - args : ' + JSON.stringify(args));
logger.info('##### GET on Marbles - peers : ' + peers);

let message = await query.queryChaincode(peers, channelName, chaincodeName, args, fcn, username, orgName);
res.send(message);
Expand All @@ -236,19 +236,21 @@ app.get('/marbles', awaitHandler(async (req, res) => {
app.post('/users', awaitHandler(async (req, res) => {
logger.info('================ POST on endpoint /users');
let args = req.body;
username = req.body.username;
orgName = req.body.orgName;
logger.info('##### POST on Users- args : ' + JSON.stringify(args));
let response = await connection.getRegisteredUser(args, true);
logger.info('##### POST on Users - returned from registering the username %s for organization %s', args);
logger.info('##### POST on Users - returned from registering the username %s for organization %s', username, orgName);
logger.info('##### POST on Users - getRegisteredUser response secret %s', response.secret);
logger.info('##### POST on Users - getRegisteredUser response message %s', response.message);
if (response && typeof response !== 'string') {
logger.info('##### POST on Users - Successfully registered the username %s for organization %s', args);
logger.info('##### POST on Users - Successfully registered the username %s for organization %s', username, orgName);
logger.info('##### POST on Users - getRegisteredUser response %s', response);
// Now that we have a username & org, we can start the block listener
//await blockListener.startBlockListener(channelName, username, orgName, wss);
res.json(response);
} else {
logger.error('##### POST on Users - Failed to register the username %s for organization %s with::%s', args, response);
logger.error('##### POST on Users - Failed to register the username %s for organization %s with::%s', username, orgName, response);
res.json({success: false, message: response});
}
}));
Expand Down
9 changes: 8 additions & 1 deletion admin-api/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export PORT=3000
echo connecting to server: $ENDPOINT:$PORT

########################################################################################################################
# Optional commands - the /users functions are optional, and require a connection profile to be configured
# Optional commands - the /users functions are optional, and require a connection profile to be configured.
# The Query function below will test that the connection profile has been correctly configured, and the REST API
# is able to communicate with the Fabric network.
#
# Note, for these /users based calls to work, you must have updated the connection-profile. The Admin API needs to
# connect to the Fabric network to carry out these function calls. See the README for details.
Expand All @@ -33,6 +35,11 @@ ORG=org1
echo
response=$(curl -s -X POST http://${ENDPOINT}:${PORT}/users -H 'content-type: application/json' -d '{"username":"'"${USERID}"'","org":"'"${ORG}"'"}')
echo $response

# Query the chaincode. Uses the connection profile to connect to the Fabric network.
response=$(curl -s -X GET http://${ENDPOINT}:${PORT}/marbles)
echo $response

########################################################################################################################

# Print out the orgs and profiles contained in configtx.yaml and env.sh
Expand Down

0 comments on commit f2a0c72

Please sign in to comment.