-
Notifications
You must be signed in to change notification settings - Fork 99
chore: use enum for NoteType #1594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
79462ec
3fbd4b3
82298ee
b5445cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,33 @@ use super::account::NetworkAccountId; | |
| use crate::errors::{ConversionError, MissingFieldHelper}; | ||
| use crate::generated as proto; | ||
|
|
||
| // NOTE TYPE | ||
| // ================================================================================================ | ||
|
|
||
| impl From<NoteType> for proto::note::NoteType { | ||
| fn from(note_type: NoteType) -> Self { | ||
| match note_type { | ||
| NoteType::Public => proto::note::NoteType::Public, | ||
| NoteType::Private => proto::note::NoteType::Private, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<proto::note::NoteType> for NoteType { | ||
| type Error = ConversionError; | ||
|
|
||
| fn try_from(note_type: proto::note::NoteType) -> Result<Self, Self::Error> { | ||
| match note_type { | ||
| proto::note::NoteType::Public => Ok(NoteType::Public), | ||
| proto::note::NoteType::Private => Ok(NoteType::Private), | ||
| proto::note::NoteType::Unspecified => Err(ConversionError::EnumDiscriminantOutOfRange), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // NOTE METADATA | ||
| // ================================================================================================ | ||
|
|
||
| impl TryFrom<proto::note::NoteMetadata> for NoteMetadata { | ||
| type Error = ConversionError; | ||
|
|
||
|
|
@@ -31,7 +58,9 @@ impl TryFrom<proto::note::NoteMetadata> for NoteMetadata { | |
| .sender | ||
| .ok_or_else(|| proto::note::NoteMetadata::missing_field(stringify!(sender)))? | ||
| .try_into()?; | ||
| let note_type = NoteType::try_from(u64::from(value.note_type))?; | ||
| let note_type = proto::note::NoteType::try_from(value.note_type) | ||
| .map_err(|_| ConversionError::EnumDiscriminantOutOfRange)? | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this required? Seems like its mapping from
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Man that's so weird. What's even the point of the enum if they never actually use it in the code.. |
||
| .try_into()?; | ||
| let tag = NoteTag::new(value.tag); | ||
|
|
||
| // Deserialize attachment if present | ||
|
|
@@ -77,7 +106,7 @@ impl From<NetworkNote> for proto::note::NetworkNote { | |
| impl From<NoteMetadata> for proto::note::NoteMetadata { | ||
| fn from(val: NoteMetadata) -> Self { | ||
| let sender = Some(val.sender().into()); | ||
| let note_type = val.note_type() as u32; | ||
| let note_type = proto::note::NoteType::from(val.note_type()) as i32; | ||
Mirko-von-Leipzig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let tag = val.tag().as_u32(); | ||
| let attachment = val.attachment().to_bytes(); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.