From c4bdc68e1b8a74792a3af9f35f647a87010e9203 Mon Sep 17 00:00:00 2001 From: susmita Date: Fri, 23 Feb 2018 12:06:53 -0500 Subject: [PATCH] [FAB-8479] Added Endorsement policy for balance transfer app in node-sdk samples. Added Endorsement policy in instantiate-chaincode. Change-Id: Ie7344353a8febf0f1e76f6a4edcb3035ab2d00e2 Signed-off-by: susmita --- balance-transfer/README.md | 32 +++++++++++++++++-- balance-transfer/app/instantiate-chaincode.js | 14 +++++++- balance-transfer/testAPIs.sh | 6 ++-- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/balance-transfer/README.md b/balance-transfer/README.md index 553c67d376..7d551d25ba 100644 --- a/balance-transfer/README.md +++ b/balance-transfer/README.md @@ -173,13 +173,40 @@ curl -s -X POST \ ### Instantiate chaincode +This is the endorsement policy defined during instantiation. +This policy can be fulfilled when members from both orgs sign the transaction proposal. + +``` +{ + identities: [{ + role: { + name: 'member', + mspId: 'Org1MSP' + } + }, + { + role: { + name: 'member', + mspId: 'Org2MSP' + } + } + ], + policy: { + '2-of': [{ + 'signed-by': 0 + }, { + 'signed-by': 1 + }] + } +} +``` + ``` curl -s -X POST \ http://localhost:4000/channels/mychannel/chaincodes \ -H "authorization: Bearer " \ -H "content-type: application/json" \ -d '{ - "peers": ["peer0.org1.example.com","peer1.org1.example.com"], "chaincodeName":"mycc", "chaincodeVersion":"v0", "chaincodeType": "golang", @@ -190,13 +217,14 @@ curl -s -X POST \ ### Invoke request +This invoke request is signed by peers from both orgs, *org1* & *org2*. ``` curl -s -X POST \ http://localhost:4000/channels/mychannel/chaincodes/mycc \ -H "authorization: Bearer " \ -H "content-type: application/json" \ -d '{ - "peers": ["peer0.org1.example.com","peer1.org1.example.com"], + "peers": ["peer0.org1.example.com","peer0.org2.example.com"], "fcn":"move", "args":["a","b","10"] }' diff --git a/balance-transfer/app/instantiate-chaincode.js b/balance-transfer/app/instantiate-chaincode.js index 923be6b8c8..1c6455a570 100644 --- a/balance-transfer/app/instantiate-chaincode.js +++ b/balance-transfer/app/instantiate-chaincode.js @@ -50,7 +50,19 @@ var instantiateChaincode = async function(peers, channelName, chaincodeName, cha chaincodeType: chaincodeType, chaincodeVersion: chaincodeVersion, args: args, - txId: tx_id + txId: tx_id, + + // Use this to demonstrate the following policy: + // The policy can be fulfilled when members from both orgs signed. + 'endorsement-policy': { + identities: [ + { role: { name: 'member', mspId: 'Org1MSP' }}, + { role: { name: 'member', mspId: 'Org2MSP' }} + ], + policy: { + '2-of':[{ 'signed-by': 0 }, { 'signed-by': 1 }] + } + } }; if (functionName) diff --git a/balance-transfer/testAPIs.sh b/balance-transfer/testAPIs.sh index e83a672e6d..8528924c32 100755 --- a/balance-transfer/testAPIs.sh +++ b/balance-transfer/testAPIs.sh @@ -144,7 +144,7 @@ curl -s -X POST \ echo echo -echo "POST instantiate chaincode on peer1 of Org1" +echo "POST instantiate chaincode on Org1" echo curl -s -X POST \ http://localhost:4000/channels/mychannel/chaincodes \ @@ -159,14 +159,14 @@ curl -s -X POST \ echo echo -echo "POST invoke chaincode on peers of Org1" +echo "POST invoke chaincode on peers of Org1 and Org2" 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"], + "peers": ["peer0.org1.example.com","peer0.org2.example.com"], "fcn":"move", "args":["a","b","10"] }')