Implement kernel and output features as enums#2312
Implement kernel and output features as enums#2312antiochp merged 3 commits intomimblewimble:masterfrom
Conversation
|
@tromp Rust enums matching must be exhaustive (it won't compile otherwise). We don't need a fallback here because we have covered all the possibilities. In fact if we try and add a fallback clause here then the rust compiler will complain - It is now impossible to construct a TxKernel with a KernelFeatures outside of the range 0-2. |
|
Then what happens if the deserializer reads a value 3? Is that guaranteed to result in error? |
Yes we will catch this during deserialization here - https://github.com/mimblewimble/grin/pull/2312/files#diff-404c77cf79ebda67cdbd58c1c99daa8cR63 Edit: let me add a test to demonstrate/verify this, so we have something to refer to in the code. |
|
So the KernelFeatures::from_u8 throws an error given a value of 3? |
Longer term we may want to consider being able to maintain the various feature specific data (lock heights for a height locked kernel, fee for coinbase kernel etc.) on the enum itself.
But to do this we would need to implement per enum type serialization and we would no longer be able to represent the enum as a simple u8.
This PR gets us 90% of the way there in terms of simplifying how we deal with features.
TODO -
floonet(nothing should change)