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
|
|
@ -58,8 +58,6 @@ type PrivateProjectsContent struct {
|
||||||
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)
|
||||||
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue