mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-23 01:55:10 +00:00
IPDC Testings
This commit is contained in:
parent
dc1deb4bc9
commit
67e44ce293
1 changed files with 36 additions and 18 deletions
|
|
@ -55,11 +55,9 @@ type PrivateProjectsContent struct {
|
||||||
ProjectName string `json:ProjectName`
|
ProjectName string `json:ProjectName`
|
||||||
AdmninGroup []User `json:AdminGroup`
|
AdmninGroup []User `json:AdminGroup`
|
||||||
UsersGroup []User `json:UsersGroup`
|
UsersGroup []User `json:UsersGroup`
|
||||||
ProjectID string `json:ProjectID`
|
ProjectID string `json:ProjectID`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Not being persisted
|
// Not being persisted
|
||||||
type Schema struct {
|
type Schema struct {
|
||||||
JsonSchemaContent map[string]interface{} `json:"JsonSchemaContent"`
|
JsonSchemaContent map[string]interface{} `json:"JsonSchemaContent"`
|
||||||
|
|
@ -354,6 +352,10 @@ func (s *SmartContract) ValidJson(ctx contractapi.TransactionContextInterface, J
|
||||||
|
|
||||||
schema, err := s.ReadSchemaFromPDC(ctx, SchemaID)
|
schema, err := s.ReadSchemaFromPDC(ctx, SchemaID)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
schemaLoader := gojsonschema.NewGoLoader(schema.JsonSchemaContent)
|
schemaLoader := gojsonschema.NewGoLoader(schema.JsonSchemaContent)
|
||||||
documentLoader := gojsonschema.NewStringLoader(JsonContent)
|
documentLoader := gojsonschema.NewStringLoader(JsonContent)
|
||||||
|
|
||||||
|
|
@ -845,8 +847,8 @@ func (s *SmartContract) WriteSchemaToPDC(ctx contractapi.TransactionContextInter
|
||||||
|
|
||||||
type transientInput struct {
|
type transientInput struct {
|
||||||
JsonSchemaContent map[string]interface{} `json:"JsonSchemaContent"`
|
JsonSchemaContent map[string]interface{} `json:"JsonSchemaContent"`
|
||||||
SchemaId string `json:"SchemaId"`
|
SchemaId string `json:"SchemaId"`
|
||||||
Project string `json:"Project`
|
Project string `json:"Project`
|
||||||
}
|
}
|
||||||
|
|
||||||
// So far, we've taken what's on the transient dictionary and unmarshal it into the transientInput Struct
|
// So far, we've taken what's on the transient dictionary and unmarshal it into the transientInput Struct
|
||||||
|
|
@ -861,7 +863,13 @@ func (s *SmartContract) WriteSchemaToPDC(ctx contractapi.TransactionContextInter
|
||||||
//return err
|
//return err
|
||||||
//}
|
//}
|
||||||
// Check if Schema already exists
|
// Check if Schema already exists
|
||||||
assetAsBytes, err := ctx.GetStub().GetPrivateData(PDC1, assetInput.SchemaId)
|
|
||||||
|
MSP, err := shim.GetMSPID()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get MSPID: %v", err)
|
||||||
|
}
|
||||||
|
PDC := "_implicit_org_" + MSP
|
||||||
|
assetAsBytes, err := ctx.GetStub().GetPrivateData(PDC, assetInput.SchemaId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get Schema: %v", err)
|
return fmt.Errorf("failed to get Schema: %v", err)
|
||||||
} else if assetAsBytes != nil {
|
} else if assetAsBytes != nil {
|
||||||
|
|
@ -896,9 +904,9 @@ func (s *SmartContract) WriteSchemaToPDC(ctx contractapi.TransactionContextInter
|
||||||
// Save asset to private data collection
|
// Save asset to private data collection
|
||||||
// Typical logger, logs to stdout/file in the fabric managed docker container, running this chaincode
|
// Typical logger, logs to stdout/file in the fabric managed docker container, running this chaincode
|
||||||
// Look for container name like dev-peer0.org1.example.com-{chaincodename_version}-xyz
|
// Look for container name like dev-peer0.org1.example.com-{chaincodename_version}-xyz
|
||||||
log.Printf("WriteSchemaToPDC Put: collection %v, ID %v, owner %v", PDC1, assetInput.SchemaId, clientID)
|
log.Printf("WriteSchemaToPDC Put: collection %v, ID %v, owner %v", PDC, assetInput.SchemaId, clientID)
|
||||||
|
|
||||||
err = ctx.GetStub().PutPrivateData(PDC1, assetInput.SchemaId, assetJSONasBytes)
|
err = ctx.GetStub().PutPrivateData(PDC, assetInput.SchemaId, assetJSONasBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to put asset into private data collection: %v", err)
|
return fmt.Errorf("failed to put asset into private data collection: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -908,17 +916,21 @@ func (s *SmartContract) WriteSchemaToPDC(ctx contractapi.TransactionContextInter
|
||||||
|
|
||||||
// ReadAsset reads the information from collection
|
// ReadAsset reads the information from collection
|
||||||
func (s *SmartContract) ReadSchemaFromPDC(ctx contractapi.TransactionContextInterface, SchemaID string) (*Schema, error) {
|
func (s *SmartContract) ReadSchemaFromPDC(ctx contractapi.TransactionContextInterface, SchemaID string) (*Schema, error) {
|
||||||
|
MSP, err := shim.GetMSPID()
|
||||||
log.Printf("ReadSchemaFromPDC: collection %v, ID %v", PDC1, SchemaID)
|
if err != nil {
|
||||||
assetJSON, err := ctx.GetStub().GetPrivateData(PDC1, SchemaID) //get the asset from chaincode state
|
return nil, fmt.Errorf("failed to get MSPID: %v", err)
|
||||||
|
}
|
||||||
|
PDC := "_implicit_org_" + MSP
|
||||||
|
log.Printf("ReadSchemaFromPDC: collection %v, ID %v", PDC, SchemaID)
|
||||||
|
assetJSON, err := ctx.GetStub().GetPrivateData(PDC, SchemaID) //get the asset from chaincode state
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read Schema: %v", err)
|
return nil, fmt.Errorf("failed to read Schema: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//No Asset found, return empty response
|
//No Asset found, return empty response
|
||||||
if assetJSON == nil {
|
if assetJSON == nil {
|
||||||
log.Printf("%v does not exist in collection %v", SchemaID, PDC1)
|
log.Printf("%v does not exist in collection %v", SchemaID, PDC)
|
||||||
return nil, fmt.Errorf("%v does not exist in collection %v", SchemaID, PDC1)
|
return nil, fmt.Errorf("%v does not exist in collection %v", SchemaID, PDC)
|
||||||
}
|
}
|
||||||
|
|
||||||
var schema *Schema
|
var schema *Schema
|
||||||
|
|
@ -932,9 +944,15 @@ func (s *SmartContract) ReadSchemaFromPDC(ctx contractapi.TransactionContextInte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SmartContract) GetAllPDCSchemas(ctx contractapi.TransactionContextInterface) ([]*Schema, error) {
|
func (s *SmartContract) GetAllPDCSchemas(ctx contractapi.TransactionContextInterface) ([]*Schema, error) {
|
||||||
log.Printf("GetAllPDCSchemas: collection %v ", PDC1)
|
|
||||||
|
|
||||||
resultsIterator, err := ctx.GetStub().GetPrivateDataByRange(PDC1, "", "")
|
MSP, err := shim.GetMSPID()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to get MSPID: %v", err)
|
||||||
|
}
|
||||||
|
PDC := "_implicit_org_" + MSP
|
||||||
|
log.Printf("GetAllPDCSchemas: collection %v ", PDC)
|
||||||
|
|
||||||
|
resultsIterator, err := ctx.GetStub().GetPrivateDataByRange(PDC, "", "")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -970,7 +988,7 @@ func (s *SmartContract) GetAllPDCSchemas(ctx contractapi.TransactionContextInter
|
||||||
}
|
}
|
||||||
|
|
||||||
// Could also be called "Create Project"
|
// Could also be called "Create Project"
|
||||||
func (s *SmartContract) writeProjectToPDC(ctx contractapi.TransactionContextInterface) error{
|
func (s *SmartContract) writeProjectToPDC(ctx contractapi.TransactionContextInterface) error {
|
||||||
// Get new asset from transient map
|
// Get new asset from transient map
|
||||||
transientMap, err := ctx.GetStub().GetTransient()
|
transientMap, err := ctx.GetStub().GetTransient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -989,7 +1007,7 @@ func (s *SmartContract) writeProjectToPDC(ctx contractapi.TransactionContextInte
|
||||||
ProjectName string `json:ProjectName`
|
ProjectName string `json:ProjectName`
|
||||||
AdmninGroup []User `json:AdminGroup`
|
AdmninGroup []User `json:AdminGroup`
|
||||||
UsersGroup []User `json:UsersGroup`
|
UsersGroup []User `json:UsersGroup`
|
||||||
ProjectID string `json:ProjectID`
|
ProjectID string `json:ProjectID`
|
||||||
}
|
}
|
||||||
|
|
||||||
var assetInput transientInput
|
var assetInput transientInput
|
||||||
|
|
@ -1021,7 +1039,7 @@ func (s *SmartContract) writeProjectToPDC(ctx contractapi.TransactionContextInte
|
||||||
}
|
}
|
||||||
|
|
||||||
Project := PrivateProjectsContent{
|
Project := PrivateProjectsContent{
|
||||||
OrgName: assetInput.OrgName,
|
OrgName: assetInput.OrgName,
|
||||||
ProjectName: assetInput.ProjectName,
|
ProjectName: assetInput.ProjectName,
|
||||||
//AdminGroup: ,
|
//AdminGroup: ,
|
||||||
//UsersGroup: ,
|
//UsersGroup: ,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue