From a6812d002e246633e60c8bca4f0b838cb22d4f84 Mon Sep 17 00:00:00 2001 From: Andrea Gunderson Date: Tue, 19 Mar 2019 09:10:59 -0500 Subject: [PATCH 1/3] Rename PropertyValue to TrackAndTracePropertyValue Schema and Track and Trace both have a protobuf message called PropertyValue. This causes an issue when generating the protobufs. Since Track and Trace will be updated to use Grid Schema once it is complete, this commit temporarily renames Track and Trace's PropertyValue to TrackAndTracePropertyValue so they can both build at the same time. Signed-off-by: Andrea Gunderson --- contracts/track_and_trace/src/handler.rs | 11 +++++------ sdk/protos/track_and_trace_payload.proto | 4 ++-- sdk/protos/track_and_trace_property.proto | 6 +++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/contracts/track_and_trace/src/handler.rs b/contracts/track_and_trace/src/handler.rs index dae7cabd48..35cb464006 100644 --- a/contracts/track_and_trace/src/handler.rs +++ b/contracts/track_and_trace/src/handler.rs @@ -25,9 +25,8 @@ use grid_sdk::protos::track_and_trace_payload::{ RevokeReporterAction, SCPayload, UpdatePropertiesAction, SCPayload_Action }; use grid_sdk::protos::track_and_trace_property::{ - Property, PropertyContainer, PropertyPage, PropertyPageContainer, - PropertyPage_ReportedValue, PropertySchema, PropertySchema_DataType, PropertyValue, - Property_Reporter, + Property, PropertyContainer, PropertyPage, PropertyPageContainer, PropertyPage_ReportedValue, + PropertySchema, PropertySchema_DataType, Property_Reporter, TrackAndTracePropertyValue, }; use grid_sdk::protos::track_and_trace_proposal::{ Proposal, ProposalContainer, Proposal_Role, Proposal_Status, @@ -670,7 +669,7 @@ impl SupplyChainTransactionHandler { let mut type_schemata: HashMap<&str, PropertySchema> = HashMap::new(); let mut required_properties: HashMap<&str, PropertySchema> = HashMap::new(); - let mut provided_properties: HashMap<&str, PropertyValue> = HashMap::new(); + let mut provided_properties: HashMap<&str, TrackAndTracePropertyValue> = HashMap::new(); for property in record_type.get_properties() { type_schemata.insert(property.get_name(), property.clone()); if property.get_required() { @@ -1505,7 +1504,7 @@ impl SupplyChainTransactionHandler { &self, reporter_index: u32, timestamp: u64, - value: &PropertyValue, + value: &TrackAndTracePropertyValue, property: &Property, ) -> Result { let mut reported_value = PropertyPage_ReportedValue::new(); @@ -1567,7 +1566,7 @@ impl SupplyChainTransactionHandler { fn _validate_struct_values( &self, - struct_values: &RepeatedField, + struct_values: &RepeatedField, schema_values: &RepeatedField, ) -> Result<(), ApplyError> { if struct_values.len() != schema_values.len() { diff --git a/sdk/protos/track_and_trace_payload.proto b/sdk/protos/track_and_trace_payload.proto index 2187221e92..973ba1ac0f 100644 --- a/sdk/protos/track_and_trace_payload.proto +++ b/sdk/protos/track_and_trace_payload.proto @@ -64,7 +64,7 @@ message CreateRecordAction { // The name of the RecordType this Record belongs to string record_type = 2; - repeated PropertyValue properties = 3; + repeated TrackAndTracePropertyValue properties = 3; } @@ -85,7 +85,7 @@ message UpdatePropertiesAction { // The natural key of the Record string record_id = 1; - repeated PropertyValue properties = 2; + repeated TrackAndTracePropertyValue properties = 2; } diff --git a/sdk/protos/track_and_trace_property.proto b/sdk/protos/track_and_trace_property.proto index 13c7ecad69..0fc891e182 100644 --- a/sdk/protos/track_and_trace_property.proto +++ b/sdk/protos/track_and_trace_property.proto @@ -129,7 +129,7 @@ message PropertySchema { } -message PropertyValue { +message TrackAndTracePropertyValue { // The name of the property being set string name = 1; @@ -144,7 +144,7 @@ message PropertyValue { sint64 number_value = 13; string string_value = 14; string enum_value = 15; - repeated PropertyValue struct_values = 16; + repeated TrackAndTracePropertyValue struct_values = 16; Location location_value = 17; } @@ -165,7 +165,7 @@ message PropertyPage { sint64 number_value = 13; string string_value = 14; uint32 enum_value = 15; - repeated PropertyValue struct_values = 16; + repeated TrackAndTracePropertyValue struct_values = 16; Location location_value = 17; } From 0daad3730ece50712b435930214344bffd2a5dc8 Mon Sep 17 00:00:00 2001 From: Andrea Gunderson Date: Tue, 19 Mar 2019 09:14:50 -0500 Subject: [PATCH 2/3] Fixup some missed rustfmt issues in Track and Trace Signed-off-by: Andrea Gunderson --- contracts/track_and_trace/src/handler.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/contracts/track_and_trace/src/handler.rs b/contracts/track_and_trace/src/handler.rs index 35cb464006..a8a6232fa6 100644 --- a/contracts/track_and_trace/src/handler.rs +++ b/contracts/track_and_trace/src/handler.rs @@ -20,9 +20,9 @@ use std::collections::HashMap; use grid_sdk::protos::track_and_trace_agent::{Agent, AgentContainer}; use grid_sdk::protos::track_and_trace_payload::{ - AnswerProposalAction, AnswerProposalAction_Response, CreateAgentAction, - CreateProposalAction, CreateRecordAction, CreateRecordTypeAction, FinalizeRecordAction, - RevokeReporterAction, SCPayload, UpdatePropertiesAction, SCPayload_Action + AnswerProposalAction, AnswerProposalAction_Response, CreateAgentAction, CreateProposalAction, + CreateRecordAction, CreateRecordTypeAction, FinalizeRecordAction, RevokeReporterAction, + SCPayload, SCPayload_Action, UpdatePropertiesAction, }; use grid_sdk::protos::track_and_trace_property::{ Property, PropertyContainer, PropertyPage, PropertyPageContainer, PropertyPage_ReportedValue, @@ -308,15 +308,14 @@ impl<'a> SupplyChainState<'a> { let d = self.context.get_state(vec![address])?; match d { Some(packed) => { - let agents: AgentContainer = - match protobuf::parse_from_bytes(packed.as_slice()) { - Ok(agents) => agents, - Err(_) => { - return Err(ApplyError::InternalError(String::from( - "Cannot deserialize agent container", - ))); - } - }; + let agents: AgentContainer = match protobuf::parse_from_bytes(packed.as_slice()) { + Ok(agents) => agents, + Err(_) => { + return Err(ApplyError::InternalError(String::from( + "Cannot deserialize agent container", + ))); + } + }; for agent in agents.get_entries() { if agent.public_key == agent_id { From b7ae6f66922bb080063b86c3fcb926b49a7dc55e Mon Sep 17 00:00:00 2001 From: Andrea Gunderson Date: Tue, 19 Mar 2019 09:17:28 -0500 Subject: [PATCH 3/3] Add initial Grid Schema protos Signed-off-by: Andrea Gunderson --- sdk/protos/schema_payload.proto | 55 +++++++++++++++++++++++++ sdk/protos/schema_state.proto | 73 +++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 sdk/protos/schema_payload.proto create mode 100644 sdk/protos/schema_state.proto diff --git a/sdk/protos/schema_payload.proto b/sdk/protos/schema_payload.proto new file mode 100644 index 0000000000..96ab2d7162 --- /dev/null +++ b/sdk/protos/schema_payload.proto @@ -0,0 +1,55 @@ +// Copyright 2019 Cargill Incorporated +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ----------------------------------------------------------------------------- + +syntax = "proto3"; + +import "schema_state.proto"; + +// SchemaPayload contains an action enum and the associated action payload. +message SchemaPayload { + enum Action { + UNSET_ACTION = 0; + SCHEMA_CREATE = 1; + SCHEMA_UPDATE = 2; + } + + Action action = 1; + + // The smart contract will read from just one of these fields + // according to the Action. Only one of these should be set and must match + // the corresponding Action. + SchemaCreateAction schema_create = 2; + SchemaUpdateAction schema_update = 3; +} + +// SchemaCreateAction adds a new Schema to state. +message SchemaCreateAction { + // The name of the Schema. This is also the unique identifier for the + // new Schema. + string schema_name = 1; + // An optional description of the schema. + string description = 2; + // The property definitions that make up the Schema; must not be empty. + repeated PropertyDefinition properties = 10; +} + +// SchemaUpdateAction updates an existing Schema. The new properties will +// be added to the Schema definitions. +message SchemaUpdateAction { + // The name of the Schema to be updated. + string schema_name = 1; + // The property definitions to be added to the Schema; must not be empty. + repeated PropertyDefinition properties = 2; +} diff --git a/sdk/protos/schema_state.proto b/sdk/protos/schema_state.proto new file mode 100644 index 0000000000..b48ff993cc --- /dev/null +++ b/sdk/protos/schema_state.proto @@ -0,0 +1,73 @@ +// Copyright 2019 Cargill Incorporated +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ----------------------------------------------------------------------------- + +syntax = "proto3"; + +message PropertyDefinition { + enum DataType { + UNSET_DATA_TYPE = 0; + BYTES = 1; + BOOLEAN = 2; + NUMBER = 3; + STRING = 4; + ENUM = 5; + STRUCT = 6; + } + // The name of the property + string name = 1; + // The data type of the value; must not be set to UNSET_DATA_TYPE. + DataType data_type = 2; + // Indicates that this is a required property in the Schema + bool required = 3; + // An optional description of the field. + string description = 4; + // The exponent for a NUMBER property + sint32 number_exponent = 10; + // The list of values for an ENUM property; must not be empty/ for + // properties of that type. + repeated string enum_options = 11; + // The list of property definitions for a STRUCT property; must not be + // empty for properties of that type. + repeated PropertyDefinition struct_properties = 12; +} + +message Schema { + // The name of the Schema. This is also the unique identifier for the + // Schema. + string name = 1; + // An optional description of the schema. + string description = 2; + // The Pike organization that has rights to modify the schema. + string owner = 3; + // The property definitions that make up the Schema; must not be empty. + repeated PropertyDefinition properties = 10; +} + +message PropertyValue { + // The name of the property value. Used to validate the property against a + // Schema. + string name = 1; + // The data type of the property. Indicates which value field the actual + // value may be found. Must not be set to `UNSET_DATA_TYPE`. + PropertyDefinition.DataType data_type = 2; + // The value fields for the possible data types. Only one of these will + // contain a value, determined by the value of `data_type` + bytes bytes_value = 10; + bool boolean_value = 11; + sint64 number_value = 12; + string string_value = 13; + uint32 enum_value = 14; + repeated PropertyValue struct_values = 15; +}