From 463ec990f26cc6239d25fd75871eaf01095b1116 Mon Sep 17 00:00:00 2001 From: Gari Singh Date: Sun, 19 Feb 2017 06:38:49 -0500 Subject: [PATCH] Remove sdk example The sdk example is no longer relevant nor does it belong in this repo so this simply deletes it Change-Id: I021af7a23bce898a3dc32d4166a6f4ee68bf7ac4 Signed-off-by: Gari Singh --- examples/sdk/node/Dockerfile | 7 -- examples/sdk/node/app.js | 163 --------------------------- examples/sdk/node/docker-compose.yml | 50 -------- examples/sdk/node/web-app.js | 118 ------------------- 4 files changed, 338 deletions(-) delete mode 100644 examples/sdk/node/Dockerfile delete mode 100644 examples/sdk/node/app.js delete mode 100644 examples/sdk/node/docker-compose.yml delete mode 100644 examples/sdk/node/web-app.js diff --git a/examples/sdk/node/Dockerfile b/examples/sdk/node/Dockerfile deleted file mode 100644 index 1688edc2d72..00000000000 --- a/examples/sdk/node/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM hyperledger/fabric-peer:latest -# setup the chaincode sample -WORKDIR $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -RUN go build -WORKDIR $GOPATH/src/github.com/hyperledger/fabric/examples/sdk/node -# install the hfc locally for use by the application -RUN npm install hfc diff --git a/examples/sdk/node/app.js b/examples/sdk/node/app.js deleted file mode 100644 index dfc5f401025..00000000000 --- a/examples/sdk/node/app.js +++ /dev/null @@ -1,163 +0,0 @@ -/* - Copyright IBM Corp 2016 All Rights Reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -/* - * A simple application utilizing the Node.js Client SDK to: - * 1) Enroll a user - * 2) User deploys chaincode - * 3) User queries chaincode - */ -// "HFC" stands for "Hyperledger Fabric Client" -var hfc = require("hfc"); - -console.log(" **** starting HFC sample ****"); - - -// get the addresses from the docker-compose environment -var PEER_ADDRESS = process.env.CORE_PEER_ADDRESS; -var MEMBERSRVC_ADDRESS = process.env.MEMBERSRVC_ADDRESS; - -var chain, chaincodeID; - -// Create a chain object used to interact with the chain. -// You can name it anything you want as it is only used by client. -chain = hfc.newChain("mychain"); -// Initialize the place to store sensitive private key information -chain.setKeyValStore( hfc.newFileKeyValStore('/tmp/keyValStore') ); -// Set the URL to membership services and to the peer -console.log("member services address ="+MEMBERSRVC_ADDRESS); -console.log("peer address ="+PEER_ADDRESS); -chain.setMemberServicesUrl("grpc://"+MEMBERSRVC_ADDRESS); -chain.addPeer("grpc://"+PEER_ADDRESS); - -// The following is required when the peer is started in dev mode -// (i.e. with the '--peer-chaincodedev' option) -var mode = process.env['DEPLOY_MODE']; -console.log("DEPLOY_MODE=" + mode); -if (mode === 'dev') { - chain.setDevMode(true); - //Deploy will not take long as the chain should already be running - chain.setDeployWaitTime(10); -} else { - chain.setDevMode(false); - //Deploy will take much longer in network mode - chain.setDeployWaitTime(120); -} - - -chain.setInvokeWaitTime(10); - -// Begin by enrolling the user -enroll(); - -// Enroll a user. -function enroll() { - console.log("enrolling user admin ..."); - // Enroll "admin" which is preregistered in the membersrvc.yaml - chain.enroll("admin", "Xurw3yU9zI0l", function(err, admin) { - if (err) { - console.log("ERROR: failed to register admin: %s",err); - process.exit(1); - } - // Set this user as the chain's registrar which is authorized to register other users. - chain.setRegistrar(admin); - - var userName = "JohnDoe"; - // registrationRequest - var registrationRequest = { - enrollmentID: userName, - affiliation: "bank_a" - }; - chain.registerAndEnroll(registrationRequest, function(error, user) { - if (error) throw Error(" Failed to register and enroll " + userName + ": " + error); - console.log("Enrolled %s successfully\n", userName); - deploy(user); - }); - }); -} - -// Deploy chaincode -function deploy(user) { - console.log("deploying chaincode; please wait ..."); - // Construct the deploy request - var deployRequest = { - chaincodeName: process.env.CORE_CHAINCODE_ID_NAME, - fcn: "init", - args: ["a", "100", "b", "200"] - }; - // where is the chain code, ignored in dev mode - deployRequest.chaincodePath = "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"; - - // Issue the deploy request and listen for events - var tx = user.deploy(deployRequest); - tx.on('complete', function(results) { - // Deploy request completed successfully - console.log("deploy complete; results: %j",results); - // Set the testChaincodeID for subsequent tests - chaincodeID = results.chaincodeID; - invoke(user); - }); - tx.on('error', function(error) { - console.log("Failed to deploy chaincode: request=%j, error=%k",deployRequest,error); - process.exit(1); - }); - -} - -// Query chaincode -function query(user) { - console.log("querying chaincode ..."); - // Construct a query request - var queryRequest = { - chaincodeID: chaincodeID, - fcn: "query", - args: ["a"] - }; - // Issue the query request and listen for events - var tx = user.query(queryRequest); - tx.on('complete', function (results) { - console.log("query completed successfully; results=%j",results); - process.exit(0); - }); - tx.on('error', function (error) { - console.log("Failed to query chaincode: request=%j, error=%k",queryRequest,error); - process.exit(1); - }); -} - -//Invoke chaincode -function invoke(user) { - console.log("invoke chaincode ..."); - // Construct a query request - var invokeRequest = { - chaincodeID: chaincodeID, - fcn: "invoke", - args: ["a", "b", "1"] - }; - // Issue the invoke request and listen for events - var tx = user.invoke(invokeRequest); - tx.on('submitted', function (results) { - console.log("invoke submitted successfully; results=%j",results); - }); - tx.on('complete', function (results) { - console.log("invoke completed successfully; results=%j",results); - query(user); - }); - tx.on('error', function (error) { - console.log("Failed to invoke chaincode: request=%j, error=%k",invokeRequest,error); - process.exit(1); - }); -} diff --git a/examples/sdk/node/docker-compose.yml b/examples/sdk/node/docker-compose.yml deleted file mode 100644 index 64302ade722..00000000000 --- a/examples/sdk/node/docker-compose.yml +++ /dev/null @@ -1,50 +0,0 @@ -membersrvc: - # try 'docker ps' to see the container status after starting this compose - container_name: membersrvc - image: hyperledger/fabric-membersrvc - command: membersrvc - -peer: - container_name: peer - image: hyperledger/fabric-peer - environment: - - CORE_PEER_ADDRESSAUTODETECT=true - - CORE_VM_ENDPOINT=unix:///var/run/docker.sock - - CORE_LOGGING_LEVEL=DEBUG - - CORE_PEER_ID=vp0 - - CORE_SECURITY_ENABLED=true - - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054 - - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054 - - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054 - - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=noops - # this gives access to the docker host daemon to deploy chain code in network mode - volumes: - - /var/run/docker.sock:/var/run/docker.sock - # have the peer wait 10 sec for membersrvc to start - # the following is to run the peer in Developer mode - also set sample DEPLOY_MODE=dev - command: sh -c "sleep 10; peer node start --peer-chaincodedev" - #command: sh -c "sleep 10; peer node start" - links: - - membersrvc - -starter: - container_name: starter - image: hyperledger/fabric-starter-kit - volumes: - # tweak this to map a local developmnt directory tree into the container - - ~/mytest:/user/mytest - environment: - - MEMBERSRVC_ADDRESS=membersrvc:7054 - - PEER_ADDRESS=peer:7051 - - KEY_VALUE_STORE=/tmp/hl_sdk_node_key_value_store - # set to following to 'dev' if peer running in Developer mode - - DEPLOY_MODE=dev - - CORE_CHAINCODE_ID_NAME=mycc - - CORE_PEER_ADDRESS=peer:7051 - # the following command will start the chain code when this container starts and ready it for deployment by the app - command: sh -c "sleep 20; /opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02/chaincode_example02" - stdin_open: true - tty: true - links: - - membersrvc - - peer diff --git a/examples/sdk/node/web-app.js b/examples/sdk/node/web-app.js deleted file mode 100644 index 6dff8f41719..00000000000 --- a/examples/sdk/node/web-app.js +++ /dev/null @@ -1,118 +0,0 @@ -/* - Copyright IBM Corp 2016 All Rights Reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -/** - * This example shows how to do the following in a web app. - * 1) At initialization time, enroll the web app with the blockchain. - * The identity must have already been registered. - * 2) At run time, after a user has authenticated with the web app: - * a) register and enroll an identity for the user; - * b) use this identity to deploy, query, and invoke a chaincode. - */ -var hfc = require('hfc'); - -//get the addresses from the docker-compose environment -var PEER_ADDRESS = process.env.PEER_ADDRESS; -var MEMBERSRVC_ADDRESS = process.env.MEMBERSRVC_ADDRESS; - -// Create a client chain. -// The name can be anything as it is only used internally. -var chain = hfc.newChain("targetChain"); - -// Configure the KeyValStore which is used to store sensitive keys -// as so it is important to secure this storage. -// The FileKeyValStore is a simple file-based KeyValStore, but you -// can easily implement your own to store whereever you want. -// To work correctly in a cluster, the file-based KeyValStore must -// either be on a shared file system shared by all members of the cluster -// or you must implement you own KeyValStore which all members of the -// cluster can share. -chain.setKeyValStore( hfc.newFileKeyValStore('/tmp/keyValStore') ); - -// Set the URL for membership services -chain.setMemberServicesUrl("grpc://MEMBERSRVC_ADDRESS"); - -// Add at least one peer's URL. If you add multiple peers, it will failover -// to the 2nd if the 1st fails, to the 3rd if both the 1st and 2nd fails, etc. -chain.addPeer("grpc://PEER_ADDRESS"); - -// Enroll "WebAppAdmin" which is already registered because it is -// listed in fabric/membersrvc/membersrvc.yaml with its one time password. -// If "WebAppAdmin" has already been registered, this will still succeed -// because it stores the state in the KeyValStore -// (i.e. in '/tmp/keyValStore' in this sample). -chain.enroll("WebAppAdmin", "DJY27pEnl16d", function(err, webAppAdmin) { - if (err) return console.log("ERROR: failed to register %s: %s",err); - // Successfully enrolled WebAppAdmin during initialization. - // Set this user as the chain's registrar which is authorized to register other users. - chain.setRegistrar(webAppAdmin); - // Now begin listening for web app requests - listenForUserRequests(); -}); - -// Main web app function to listen for and handle requests. This is specific to -// your application but is provided here to demonstrate the pattern. -function listenForUserRequests() { - for (;;) { - // WebApp-specific logic goes here to await the next request. - // ... - // Assume that we received a request from an authenticated user - // and have 'userName' and 'userAccount'. - // Then determined that we need to invoke the chaincode - // with 'chaincodeID' and function named 'fcn' with arguments 'args'. - handleUserRequest(userName,userAccount,chaincodeID,fcn,args); - } -} - -// Handle a user request -function handleUserRequest(userName, userAccount, chaincodeID, fcn, args) { - // Register and enroll this user. - // If this user has already been registered and/or enrolled, this will - // still succeed because the state is kept in the KeyValStore - // (i.e. in '/tmp/keyValStore' in this sample). - var registrationRequest = { - roles: [ 'client' ], - enrollmentID: userName, - affiliation: "bank_a", - attributes: [{name:'role',value:'client'},{name:'account',value:userAccount}] - }; - chain.registerAndEnroll( registrationRequest, function(err, user) { - if (err) return console.log("ERROR: %s",err); - // Issue an invoke request - var invokeRequest = { - // Name (hash) required for invoke - chaincodeID: chaincodeID, - // Function to trigger - fcn: fcn, - // Parameters for the invoke function - args: args - }; - // Invoke the request from the user object and wait for events to occur. - var tx = user.invoke(invokeRequest); - // Listen for the 'submitted' event - tx.on('submitted', function(results) { - console.log("submitted invoke: %j",results); - }); - // Listen for the 'complete' event. - tx.on('complete', function(results) { - console.log("completed invoke: %j",results); - }); - // Listen for the 'error' event. - tx.on('error', function(err) { - console.log("error on invoke: %j",err); - }); - }); -} \ No newline at end of file