Skip to content

Commit

Permalink
[FAB-8479] Added Endorsement policy
Browse files Browse the repository at this point in the history
for balance transfer app in node-sdk samples.
Added Endorsement policy in instantiate-chaincode.

Change-Id: Ie7344353a8febf0f1e76f6a4edcb3035ab2d00e2
Signed-off-by: susmita <susmita.somanchi@gmail.com>
  • Loading branch information
susmitasomanchi committed Jul 12, 2018
1 parent 1745c99 commit c4bdc68
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
32 changes: 30 additions & 2 deletions balance-transfer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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 @@ -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 <put JSON Web Token here>" \
-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"]
}'
Expand Down
14 changes: 13 additions & 1 deletion balance-transfer/app/instantiate-chaincode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions balance-transfer/testAPIs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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"]
}')
Expand Down

0 comments on commit c4bdc68

Please sign in to comment.