From e1169e061eff0e89c2a140a201c6b3cdd191907c Mon Sep 17 00:00:00 2001 From: Fernando Garzon Date: Tue, 21 Feb 2023 17:08:41 -0800 Subject: [PATCH] PDC Testing ongoing --- .../chaincode-go/chaincode/asset_transfer.go | 14 +++++++++----- test-network/QuickCCTest.sh | 9 +++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/asset-transfer-private-data/chaincode-go/chaincode/asset_transfer.go b/asset-transfer-private-data/chaincode-go/chaincode/asset_transfer.go index eb69f097..ae005e70 100644 --- a/asset-transfer-private-data/chaincode-go/chaincode/asset_transfer.go +++ b/asset-transfer-private-data/chaincode-go/chaincode/asset_transfer.go @@ -850,9 +850,10 @@ func (s *SmartContract) WriteSchemaToPDC(ctx contractapi.TransactionContextInter } type transientInput struct { - JsonSchemaContent map[string]interface{} `json:"JsonSchemaContent"` - SchemaId string `json:"SchemaId"` - Project string `json:"Project` + //JsonSchemaContent map[string]interface{} `json:"JsonSchemaContent"` + JsonSchemaContent string `json:"JsonSchemaContent"` + SchemaId string `json:"SchemaId"` + Project string `json:"Project` } // So far, we've taken what's on the transient dictionary and unmarshal it into the transientInput Struct @@ -861,7 +862,10 @@ func (s *SmartContract) WriteSchemaToPDC(ctx contractapi.TransactionContextInter if err != nil { return fmt.Errorf("failed to unmarshal JSON: %v", err) } - + jsonFileContent, err := s.JsonReader(ctx, assetInput.JsonSchemaContent) + if err != nil { + return err + } // Check if Schema already exists assetAsBytes, err := ctx.GetStub().GetPrivateData(PDC1, assetInput.SchemaId) if err != nil { @@ -887,7 +891,7 @@ func (s *SmartContract) WriteSchemaToPDC(ctx contractapi.TransactionContextInter // Make submitting client the owner Schema := PrivateSchemaContent{ - JsonSchemaContent: assetInput.JsonSchemaContent, + JsonSchemaContent: jsonFileContent, SchemaId: assetInput.SchemaId, Project: assetInput.Project, } diff --git a/test-network/QuickCCTest.sh b/test-network/QuickCCTest.sh index f630637d..ae7504df 100644 --- a/test-network/QuickCCTest.sh +++ b/test-network/QuickCCTest.sh @@ -210,3 +210,12 @@ peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.exa echo "========= CC Query: Get all DataSamples ===========" peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}' + + + +echo "========= CC Invoke: Creation of Schema in PDC ===========" + +export ASSET_PROPERTIES=$(echo -n "{\"SchemaId\":\"Project1.Schema1\",\"Project\":\"Project1\",\"JsonSchemaContent\":"{\"type\": \"object\", \"properties\": { \"number\": { \"type\": \"number\" }, \"street_name\": { \"type\": \"string\" }, \"street_type\": { \"enum\": [\"Street\", \"Avenue\",\"Boulevard\"] }}, \"additionalProperties\": false, \"required\": [ \"number\", \"street_name\"]}", "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\" }"]}"}" | base64 | tr -d \\n) +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 private -c '{"function":"WriteSchemaToPDC","Args":[]}' --transient "{\"asset_properties\":\"$ASSET_PROPERTIES\"}" + +'{\"type\": \"object\", \"properties\": { \"number\": { \"type\": \"number\" }, \"street_name\": { \"type\": \"string\" }, \"street_type\": { \"enum\": [\"Street\", \"Avenue\",\"Boulevard\"] }}, \"additionalProperties\": false, \"required\": [ \"number\", \"street_name\"]}", "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\" }"]}' \ No newline at end of file