mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-25 11:05:10 +00:00
Nov 11/2022 Update
This commit is contained in:
parent
ed74286f4d
commit
5e3e50fd37
2 changed files with 99 additions and 71 deletions
|
|
@ -7,10 +7,9 @@ import (
|
||||||
"github.com/hyperledger/fabric-contract-api-go/contractapi"
|
"github.com/hyperledger/fabric-contract-api-go/contractapi"
|
||||||
"github.com/xeipuuv/gojsonschema"
|
"github.com/xeipuuv/gojsonschema"
|
||||||
|
|
||||||
"log"
|
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"reflect"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SmartContract provides functions for managing an Asset
|
// SmartContract provides functions for managing an Asset
|
||||||
|
|
@ -49,16 +48,16 @@ type SmartContract struct {
|
||||||
var lastSchemaHash string
|
var lastSchemaHash string
|
||||||
|
|
||||||
type Data struct {
|
type Data struct {
|
||||||
Contributor string `json:"Contributor"`
|
Contributor string `json:"Contributor"`
|
||||||
ContributorId string `json:"ContributorId"`
|
ContributorId string `json:"ContributorId"`
|
||||||
ContentHash string `json:"ContentHash"`
|
ContentHash string `json:"ContentHash"`
|
||||||
Id string `json:"Id"`
|
Id string `json:"Id"`
|
||||||
Owners []string `json:"Owners"`
|
Owner string `json:"Owners"`
|
||||||
JsonFileContent map[string]interface{}
|
JsonFileContent map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Schema struct {
|
type Schema struct {
|
||||||
Version int `json:"Version"`
|
Version int `json:"Version"`
|
||||||
Hash string `json:"Hash"`
|
Hash string `json:"Hash"`
|
||||||
JsonSchemaContent map[string]interface{}
|
JsonSchemaContent map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
@ -84,14 +83,14 @@ func (s *SmartContract) InitLedger(ctx contractapi.TransactionContextInterface,
|
||||||
return fmt.Errorf("failed to calculate 1st json file hash: %v", initDataHashError)
|
return fmt.Errorf("failed to calculate 1st json file hash: %v", initDataHashError)
|
||||||
} else if schemaHashError != nil {
|
} else if schemaHashError != nil {
|
||||||
return fmt.Errorf("failed to calculate schema hash: %v", schemaHashError)
|
return fmt.Errorf("failed to calculate schema hash: %v", schemaHashError)
|
||||||
} else{
|
} else {
|
||||||
data := Data{
|
data := Data{
|
||||||
Contributor: "pepitoperes@email.com",
|
Contributor: "pepitoperes@email.com",
|
||||||
ContributorId: "ABC123",
|
ContributorId: "ABC123",
|
||||||
ContentHash: firstJsonFileHash,
|
ContentHash: firstJsonFileHash,
|
||||||
Id: "00000",
|
Id: "00000",
|
||||||
Owners: []string{"CIA", "DEA", "FBI"},
|
Owner: "CIA",
|
||||||
JsonFileContent: firstJsonFileContent,
|
JsonFileContent: firstJsonFileContent,
|
||||||
}
|
}
|
||||||
|
|
||||||
assetJSON, err := json.Marshal(data)
|
assetJSON, err := json.Marshal(data)
|
||||||
|
|
@ -102,13 +101,15 @@ func (s *SmartContract) InitLedger(ctx contractapi.TransactionContextInterface,
|
||||||
err = ctx.GetStub().PutState(data.ContentHash, assetJSON)
|
err = ctx.GetStub().PutState(data.ContentHash, assetJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to put to world state. %v", err)
|
return fmt.Errorf("failed to put to world state. %v", err)
|
||||||
|
} else {
|
||||||
|
fmt.Print("A new Data Struct has been created with the hash %v", firstJsonFileHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
//This is the definition of the Schema that we should use for validate all the JSON files from now on.
|
//This is the definition of the Schema that we should use for validate all the JSON files from now on.
|
||||||
|
|
||||||
initSchema := Schema{
|
initSchema := Schema{
|
||||||
Version: 1,
|
Version: 1,
|
||||||
Hash: schemaJsonFileHash,
|
Hash: schemaJsonFileHash,
|
||||||
JsonSchemaContent: schemaJsonFileContent,
|
JsonSchemaContent: schemaJsonFileContent,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,13 +121,15 @@ func (s *SmartContract) InitLedger(ctx contractapi.TransactionContextInterface,
|
||||||
err = ctx.GetStub().PutState(initSchema.Hash, assetJSON)
|
err = ctx.GetStub().PutState(initSchema.Hash, assetJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to put to world state. %v", err)
|
return fmt.Errorf("failed to put to world state. %v", err)
|
||||||
|
} else {
|
||||||
|
fmt.Print("A new Schema has been created with the hash %v", schemaJsonFileHash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SmartContract) LastSchemaHash(ctx contractapi.TransactionContextInterface) (string) {
|
func (s *SmartContract) LastSchemaHash(ctx contractapi.TransactionContextInterface) string {
|
||||||
return lastSchemaHash
|
return lastSchemaHash
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -134,20 +137,19 @@ func (s *SmartContract) Hash(ctx contractapi.TransactionContextInterface, doc st
|
||||||
|
|
||||||
var v interface{}
|
var v interface{}
|
||||||
err := json.Unmarshal([]byte(doc), &v)
|
err := json.Unmarshal([]byte(doc), &v)
|
||||||
if err != nil{
|
if err != nil {
|
||||||
return "HASH CRASH", fmt.Errorf("Unable to unmarshal Json String passed as parameter. No hash calculation can be completed: %v", err)
|
return "HASH CRASH", fmt.Errorf("Unable to unmarshal Json String passed as parameter. No hash calculation can be completed: %v", err)
|
||||||
} else {
|
} else {
|
||||||
cdoc, err := json.Marshal(v)
|
cdoc, err := json.Marshal(v)
|
||||||
if err != nil{
|
if err != nil {
|
||||||
return "HASH CRASH", fmt.Errorf("Unable to re-marshal interface into json format. No hash calculation can be completed: %v", err)
|
return "HASH CRASH", fmt.Errorf("Unable to re-marshal interface into json format. No hash calculation can be completed: %v", err)
|
||||||
} else{
|
} else {
|
||||||
sum := sha256.Sum256(cdoc)
|
sum := sha256.Sum256(cdoc)
|
||||||
return hex.EncodeToString(sum[0:]), nil
|
return hex.EncodeToString(sum[0:]), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (s *SmartContract) JsonReader(ctx contractapi.TransactionContextInterface, content string) (map[string]interface{}, error) {
|
func (s *SmartContract) JsonReader(ctx contractapi.TransactionContextInterface, content string) (map[string]interface{}, error) {
|
||||||
|
|
||||||
var payload map[string]interface{}
|
var payload map[string]interface{}
|
||||||
|
|
@ -161,7 +163,7 @@ func (s *SmartContract) JsonReader(ctx contractapi.TransactionContextInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllAssets returns all assets found in world state
|
// GetAllAssets returns all assets found in world state
|
||||||
func (s *SmartContract) GetAllAssets(ctx contractapi.TransactionContextInterface) ([]*Data, error) {
|
/*func (s *SmartContract) GetAllAssets(ctx contractapi.TransactionContextInterface) ([]*Data, error) {
|
||||||
// range query with empty string for startKey and endKey does an
|
// range query with empty string for startKey and endKey does an
|
||||||
// open-ended query of all assets in the chaincode namespace.
|
// open-ended query of all assets in the chaincode namespace.
|
||||||
resultsIterator, err := ctx.GetStub().GetStateByRange("", "")
|
resultsIterator, err := ctx.GetStub().GetStateByRange("", "")
|
||||||
|
|
@ -197,6 +199,7 @@ func (s *SmartContract) GetAllAssets(ctx contractapi.TransactionContextInterface
|
||||||
|
|
||||||
return dataSamples, nil
|
return dataSamples, nil
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
func (s *SmartContract) SchemaExists(ctx contractapi.TransactionContextInterface, Hash string) (bool, error) {
|
func (s *SmartContract) SchemaExists(ctx contractapi.TransactionContextInterface, Hash string) (bool, error) {
|
||||||
assetJSON, err := ctx.GetStub().GetState(Hash)
|
assetJSON, err := ctx.GetStub().GetState(Hash)
|
||||||
|
|
@ -226,7 +229,7 @@ func (s *SmartContract) CreateNewSchema(ctx contractapi.TransactionContextInterf
|
||||||
// Verify that an schema with exact same structure doesn't exist yet.
|
// Verify that an schema with exact same structure doesn't exist yet.
|
||||||
hashContent, _ := s.Hash(ctx, newSchemaContent)
|
hashContent, _ := s.Hash(ctx, newSchemaContent)
|
||||||
exists, err := s.SchemaExists(ctx, hashContent)
|
exists, err := s.SchemaExists(ctx, hashContent)
|
||||||
if exists{
|
if exists {
|
||||||
return fmt.Errorf("Schema already exists: %v", err)
|
return fmt.Errorf("Schema already exists: %v", err)
|
||||||
} else {
|
} else {
|
||||||
lastSchemaHash = hashContent
|
lastSchemaHash = hashContent
|
||||||
|
|
@ -248,37 +251,36 @@ func (s *SmartContract) CreateNewSchema(ctx contractapi.TransactionContextInterf
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetAllSchemas returns all schemas found in world state
|
// GetAllSchemas returns all schemas found in world state
|
||||||
|
|
||||||
//func (s *SmartContract) GetAllSchemas(ctx contractapi.TransactionContextInterface) ([]Schema, error) {
|
//func (s *SmartContract) GetAllSchemas(ctx contractapi.TransactionContextInterface) ([]Schema, error) {
|
||||||
// range query with empty string for startKey and endKey does an
|
// range query with empty string for startKey and endKey does an
|
||||||
// open-ended query of all schemas in the chaincode namespace.
|
// open-ended query of all schemas in the chaincode namespace.
|
||||||
//resultsIterator, err := ctx.GetStub().GetStateByRange("", "")
|
//resultsIterator, err := ctx.GetStub().GetStateByRange("", "")
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// return nil, err
|
// return nil, err
|
||||||
//}
|
//}
|
||||||
//defer resultsIterator.Close()
|
//defer resultsIterator.Close()
|
||||||
|
|
||||||
//var schemaSamples []*Schema
|
//var schemaSamples []*Schema
|
||||||
//for resultsIterator.HasNext() {
|
//for resultsIterator.HasNext() {
|
||||||
// queryResponse, err := resultsIterator.Next()
|
// queryResponse, err := resultsIterator.Next()
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// return nil, err
|
// return nil, err
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// var schm Schema
|
// var schm Schema
|
||||||
// err = json.Unmarshal(queryResponse.Value, &schm)
|
// err = json.Unmarshal(queryResponse.Value, &schm)
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// return nil, err
|
// return nil, err
|
||||||
// }
|
// }
|
||||||
// schemaSamples = append(schemaSamples, &schm)
|
// schemaSamples = append(schemaSamples, &schm)
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//return schemas, nil
|
//return schemas, nil
|
||||||
//}
|
//}
|
||||||
|
|
||||||
// AssetExists returns true when asset with given ID exists in world state
|
// AssetExists returns true when asset with given ID exists in world state
|
||||||
|
|
@ -330,7 +332,7 @@ func (s *SmartContract) ValidJson(ctx contractapi.TransactionContextInterface, J
|
||||||
|
|
||||||
// CreateDataSample issues a new Data Sample to the world state with given details.
|
// CreateDataSample issues a new Data Sample to the world state with given details.
|
||||||
func (s *SmartContract) CreateDataSample(ctx contractapi.TransactionContextInterface,
|
func (s *SmartContract) CreateDataSample(ctx contractapi.TransactionContextInterface,
|
||||||
Contributor string, ContributorId string, Id string, JsonFileContent string) error {
|
Contributor string, ContributorId string, Id string, Owner string, JsonFileContent string) error {
|
||||||
|
|
||||||
ContentHash, err := s.Hash(ctx, JsonFileContent)
|
ContentHash, err := s.Hash(ctx, JsonFileContent)
|
||||||
exists, err := s.AssetExists(ctx, ContentHash)
|
exists, err := s.AssetExists(ctx, ContentHash)
|
||||||
|
|
@ -338,7 +340,7 @@ func (s *SmartContract) CreateDataSample(ctx contractapi.TransactionContextInter
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if exists {
|
if exists {
|
||||||
return fmt.Errorf("the asset %s already exists", Id)
|
return fmt.Errorf("the asset %s already exists", ContentHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
valid, err := s.ValidJson(ctx, JsonFileContent)
|
valid, err := s.ValidJson(ctx, JsonFileContent)
|
||||||
|
|
@ -357,7 +359,7 @@ func (s *SmartContract) CreateDataSample(ctx contractapi.TransactionContextInter
|
||||||
ContributorId: ContributorId,
|
ContributorId: ContributorId,
|
||||||
ContentHash: ContentHash,
|
ContentHash: ContentHash,
|
||||||
Id: Id,
|
Id: Id,
|
||||||
Owners: []string{"DOE", "DOS", "DOJ"},
|
Owner: Owner,
|
||||||
JsonFileContent: jsonFileContent,
|
JsonFileContent: jsonFileContent,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -367,10 +369,11 @@ func (s *SmartContract) CreateDataSample(ctx contractapi.TransactionContextInter
|
||||||
|
|
||||||
}
|
}
|
||||||
return ctx.GetStub().PutState(ContentHash, assetJSON)
|
return ctx.GetStub().PutState(ContentHash, assetJSON)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateAsset updates an existing asset in the world state with provided parameters.
|
// UpdateAsset updates an existing asset in the world state with provided parameters.
|
||||||
func (s *SmartContract) UpdateAsset(ctx contractapi.TransactionContextInterface,
|
func (s *SmartContract) UpdateAsset(ctx contractapi.TransactionContextInterface,
|
||||||
Contributor string, ContributorId string, ContentHash string, Id string) error {
|
Contributor string, ContributorId string, ContentHash string, Id string) error {
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,6 @@ echo "========= Approving ChainCode ORG2 ==========="
|
||||||
|
|
||||||
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name basic --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
|
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name basic --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
|
||||||
|
|
||||||
|
|
||||||
echo "========= Approving ChainCode ORG1 ==========="
|
echo "========= Approving ChainCode ORG1 ==========="
|
||||||
|
|
||||||
export CORE_PEER_LOCALMSPID="Org1MSP"
|
export CORE_PEER_LOCALMSPID="Org1MSP"
|
||||||
|
|
@ -68,21 +67,47 @@ peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride o
|
||||||
peer lifecycle chaincode querycommitted --channelID mychannel --name basic --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
|
peer lifecycle chaincode querycommitted --channelID mychannel --name basic --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
|
||||||
|
|
||||||
|
|
||||||
|
echo "========= CC Test of jsonRead Function ==========="
|
||||||
|
|
||||||
|
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"JsonReader","Args":["/home/chaincode/schema.json"]}'
|
||||||
|
|
||||||
|
|
||||||
echo "========= CC Invoke: Inizialitation ==========="
|
echo "========= CC Invoke: Inizialitation ==========="
|
||||||
|
|
||||||
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"InitLedger","Args":[]}'
|
#peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"InitLedger","Args":[]}'
|
||||||
|
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"InitLedger","Args":["/home/chaincode/schema.json", "/home/chaincode/firstJson.json"]}'
|
||||||
|
|
||||||
echo "========= CC Query: Get all DataSamples ==========="
|
echo "========= CC Query: Get all DataSamples ==========="
|
||||||
|
|
||||||
peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}'
|
peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}'
|
||||||
|
|
||||||
|
echo "========= CC Query: Get all Schemas ==========="
|
||||||
|
|
||||||
|
peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllSchemas"]}'
|
||||||
|
|
||||||
echo "========= Check if sample with id = '00000' Exists ==========="
|
echo "========= Check if sample with id = '00000' Exists ==========="
|
||||||
|
|
||||||
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"AssetExists","Args":["00000"]}'
|
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"AssetExists","Args":["00000"]}'
|
||||||
|
|
||||||
echo "========= Check creation of a new sample wit id = '00001' ==========="
|
echo "========= Check creation of a new sample wit id = '00001' ==========="
|
||||||
|
|
||||||
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"CreateDataSample","Args":["docTypeTest2","00001","TestTitle2","Desc2","Neuroscience","TestDOI","www.ncis.edu","TestManifest","TestFootPrint", "Neuroscience, brain", "None", "None", "None","None","None","None","None", "None"]}'
|
# peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"CreateDataSample","Args":["docTypeTest2","00001","TestTitle2","Desc2","Neuroscience","TestDOI","www.ncis.edu","TestManifest","TestFootPrint", "Neuroscience, brain", "None", "None", "None","None","None","None","None", "None"]}'
|
||||||
|
|
||||||
|
#peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"CreateDataSample","Args":["UCSD-SDSC", "Contributor123", "PhonyHash!@#$$%#@", "00001", ["DOE FER"]]}'
|
||||||
|
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"CreateDataSample","Args":["UCSD-SDSC", "Contributor123", "PhonyHash!@#$$%#@", "00001", "/home/chaincode/testFileNewSample.json"]}'
|
||||||
|
|
||||||
|
#peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile \
|
||||||
|
|
||||||
|
echo "========= Check creation of a new Schema ==========="
|
||||||
|
|
||||||
|
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"CreateNewSchema","Args":["UCSD-SDSC", "Contributor123", "PhonyHash!@#$$%#@", "00001", "/home/chaincode/NewSchema.json"]}'
|
||||||
|
|
||||||
|
echo "========= Check creation of a new sample wit id = '00002' based on New Schema ==========="
|
||||||
|
|
||||||
|
# peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"CreateDataSample","Args":["docTypeTest2","00001","TestTitle2","Desc2","Neuroscience","TestDOI","www.ncis.edu","TestManifest","TestFootPrint", "Neuroscience, brain", "None", "None", "None","None","None","None","None", "None"]}'
|
||||||
|
|
||||||
|
#peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"CreateDataSample","Args":["UCSD-SDSC", "Contributor123", "PhonyHash!@#$$%#@", "00001", ["DOE FER"]]}'
|
||||||
|
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"CreateDataSample","Args":["UCSD-SDSC", "Contributor123", "PhonyHash!@#$$%#@", "00002", "/home/chaincode/testFileNewSample.json"]}'
|
||||||
|
|
||||||
echo "========= The code below will upgrade an existing ChainCode ==========="
|
echo "========= The code below will upgrade an existing ChainCode ==========="
|
||||||
|
|
||||||
|
|
@ -108,7 +133,7 @@ var2=$(echo $var | tail -n 1 | cut -f 3 -d ' ')
|
||||||
export NEW_CC_PACKAGE_ID=$(echo $var2 | sed 's/.$//')
|
export NEW_CC_PACKAGE_ID=$(echo $var2 | sed 's/.$//')
|
||||||
echo $NEW_CC_PACKAGE_ID
|
echo $NEW_CC_PACKAGE_ID
|
||||||
|
|
||||||
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name basic --version 3.0 --package-id $NEW_CC_PACKAGE_ID --sequence 3 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
|
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name basic --version 3.0 --package-id $NEW_CC_PACKAGE_ID --sequence 2 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
|
||||||
|
|
||||||
export CORE_PEER_LOCALMSPID="Org2MSP"
|
export CORE_PEER_LOCALMSPID="Org2MSP"
|
||||||
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
|
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
|
||||||
|
|
@ -117,11 +142,11 @@ export CORE_PEER_ADDRESS=localhost:9051
|
||||||
|
|
||||||
peer lifecycle chaincode install basic_3.tar.gz
|
peer lifecycle chaincode install basic_3.tar.gz
|
||||||
|
|
||||||
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name basic --version 3.0 --package-id $NEW_CC_PACKAGE_ID --sequence 3 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
|
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name basic --version 3.0 --package-id $NEW_CC_PACKAGE_ID --sequence 2 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
|
||||||
|
|
||||||
peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 3.0 --sequence 3 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --output json
|
peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 3.0 --sequence 2 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --output json
|
||||||
|
|
||||||
peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name basic --version 3.0 --sequence 3 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt"
|
peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name basic --version 3.0 --sequence 2 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt"
|
||||||
|
|
||||||
echo "========= Update of Sample 00001 ==========="
|
echo "========= Update of Sample 00001 ==========="
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue