-
Notifications
You must be signed in to change notification settings - Fork 98
Add rust native implementation of product #99
Add rust native implementation of product #99
Conversation
5b16eb1
to
0d8376e
Compare
0d8376e
to
be60569
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not compile. You need to add pub mod product;
to src/protocol/mod.rs and fix the compilation errors.
Why didn't that compilation failure get caught by Jenkins? |
Since product is not added the protocol mod.rs file the product protocols are not being included. |
beb928e
to
7b0e197
Compare
Looks like adding in the rust native implementations for grid product is causing some sections of the product smart contract code to error out; will update the product smart contract in this PR to fix the Jenkins build. Apologies for the large PR - didn't foresee this issue |
e7ccc8c
to
8305ab4
Compare
This open issue is causing the Jenkins build to break: rust-lang/rust#62562 TL;DR: serde does not build with the latest version of nightly |
@pa3ng It seems the issue was fixed in the newest nightly. I restarted your build in Jenkins and it passed :) |
|
8305ab4
to
6870729
Compare
78b56cb
to
c128cb7
Compare
After talking with @peterschwarz about not creating a central, shared test package to reduce test code redundancy, I plan on adding the smart contract unit tests in this PR instead of a separate PR. Let me know if this is desired or not. TODO:
|
sdk/src/protocol/product/state.rs
Outdated
} | ||
} | ||
|
||
fn cause(&self) -> Option<&StdError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cause
is deprecated - you should use source
for these: https://doc.rust-lang.org/std/error/trait.Error.html#method.source
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ✅
sdk/src/protocol/product/state.rs
Outdated
impl std::fmt::Display for ProductBuildError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
match *self { | ||
ProductBuildError::MissingField(ref s) => write!(f, "MissingField: {}", s), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Display message should be Human-readable, this is no better than just Debug
. Something like "missing field \"{}\""
would be appropriate here. Or with the EmptyVec error: "\"{}\" must not be empty"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ✅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the unit tests in the protocol files are still missing. There are two set of unit tests that still need to be added the protocol unit tests and the smart contract unit tests. The protocol unit tests should be add in this PR, while the smart contract unit tests could be added in a future PR.
sdk/src/protocol/product/payload.rs
Outdated
), | ||
ProductPayload_Action::UNSET_ACTION => { | ||
return Err(ProtoConversionError::InvalidTypeError( | ||
"Cannot convert ProductPayload_Action with type unset.".to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove period at the end of the error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ✅
sdk/src/protocol/product/payload.rs
Outdated
} | ||
} | ||
|
||
/// Builder used to create a ProductPayload |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ProductPaylaod -> ProductCreateBuilder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ✅
sdk/src/protocol/product/payload.rs
Outdated
pub fn build(self) -> Result<ProductCreateAction, BuilderError> { | ||
let product_type = self | ||
.product_type | ||
.ok_or_else(|| BuilderError::MissingField("product_type".into()))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you make these match the other errors " 'product_type' field is required" etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ✅
sdk/src/protocol/product/payload.rs
Outdated
|
||
pub fn build(self) -> Result<ProductUpdateAction, ProductUpdateBuildError> { | ||
let product_type = self.product_type.ok_or_else(|| { | ||
ProductUpdateBuildError::MissingField("'product_type field is required".to_string()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing second ' after product_type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same in identifier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ✅
sdk/src/protocol/product/payload.rs
Outdated
|
||
pub fn build(self) -> Result<ProductDeleteAction, ProductDeleteBuildError> { | ||
let product_type = self.product_type.ok_or_else(|| { | ||
ProductDeleteBuildError::MissingField("'product_type field is required".to_string()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing second ' after product type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for identifier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ✅
@@ -26,7 +26,7 @@ message Product { | |||
string identifier = 1; | |||
|
|||
// What type of product is this (GS1) | |||
ProductType type = 2; | |||
ProductType product_type = 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you leave a comment on the associated RFC mentioning this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ✅
e5d96de
to
7b6aa62
Compare
7b6aa62
to
b85691d
Compare
sdk/src/protocol/product/payload.rs
Outdated
impl IntoProto<protos::product_payload::ProductUpdateAction> for ProductUpdateAction {} | ||
impl IntoNative<ProductUpdateAction> for protos::product_payload::ProductUpdateAction {} | ||
|
||
/// Builder used to create a ProductUpdateActionBuilder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to "Builder used to create a ProductUpdateAction"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ✅
sdk/src/protocol/product/payload.rs
Outdated
impl IntoProto<protos::product_payload::ProductDeleteAction> for ProductDeleteAction {} | ||
impl IntoNative<ProductDeleteAction> for protos::product_payload::ProductDeleteAction {} | ||
|
||
/// Builder used to create a ProductDeleteActionBuilder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to "Builder used to create a ProductDeleteAction"
b85691d
to
a639567
Compare
Other changes - Removed enum ProductType declarations in each Product action message (see protos/product_payload.proto) - Renamed 'product_values' field to 'properties' field for coherency (see protos/product_state.proto) - Renamed 'type' field to 'product_type' because 'type' is a reserved key word - Renamed 'identifier field to 'product_id' field because 'identifier' is a rust error descriptor - Replaced deprecated StdError 'cause' function with new 'source' function (see protocol/product/state.rs) Signed-off-by: Raphael Santo Domingo <raphael.santodomingo@target.com>
Other changes - Moved the 'check_permission' function call before checking for an agent's associated org - Renamed 'identifier field to 'product_id' field because 'identifier' is a rust error descriptor Signed-off-by: Raphael Santo Domingo <raphael.santodomingo@target.com>
a639567
to
d612486
Compare
sdk/protos/product_state.proto
Outdated
@@ -26,13 +26,13 @@ message Product { | |||
string identifier = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should refactor this to "product_id" -- Some error messages in rust use the word "identifier" to convey the meaning of a variables name i.e.
error: expected identifier, found keyword `type`
--> src/actions/products.rs:31:9
|
31 | pub type: String,
| ^^^^ expected identifier, found keyword
help: you can escape reserved keywords to use them as identifiers
|
31 | pub r#type: String,
| ^^^^^^
It's not a reserved word, but best to avoid any chance of confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ This change has already been made (see sdk/protos/product_state.proto
)
This PR contains rust native implementations of the data models and functions associated, in product