-
Notifications
You must be signed in to change notification settings - Fork 76
Fix: include UnwrapLamports (45) in TokenInstruction::try_from #118
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| use {crate::error::TokenError, pinocchio::program_error::ProgramError}; | ||
|
|
||
|
|
||
| /// Instructions supported by the token program. | ||
| #[repr(u8)] | ||
| #[derive(Clone, Debug, PartialEq)] | ||
|
|
@@ -536,6 +537,8 @@ pub enum TokenInstruction { | |
| /// other `batch` instruction; an error will be raised when this is | ||
| /// detected. | ||
| Batch = 255, | ||
|
|
||
|
|
||
|
Comment on lines
+540
to
+541
Contributor
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. nit: Not needed. |
||
| // Any new variants also need to be added to program-2022 `TokenInstruction`, so that the | ||
| // latter remains a superset of this instruction set. New variants also need to be added to | ||
| // token/js/src/instructions/types.ts to maintain @solana/spl-token compatibility | ||
|
|
@@ -547,7 +550,7 @@ impl TryFrom<u8> for TokenInstruction { | |
| fn try_from(value: u8) -> Result<Self, Self::Error> { | ||
| match value { | ||
| // SAFETY: `value` is guaranteed to be in the range of the enum variants. | ||
| 0..=24 | 38 | 255 => Ok(unsafe { core::mem::transmute::<u8, TokenInstruction>(value) }), | ||
| 0..=24 | 38 | 45 | 255 => Ok(unsafe { core::mem::transmute::<u8, TokenInstruction>(value) }), | ||
| _ => Err(TokenError::InvalidInstruction.into()), | ||
| } | ||
| } | ||
|
|
@@ -566,6 +569,7 @@ pub enum AuthorityType { | |
| AccountOwner, | ||
| /// Authority to close a token account | ||
| CloseAccount, | ||
|
|
||
|
Contributor
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. nit: Not needed. |
||
| } | ||
|
|
||
| impl TryFrom<u8> for AuthorityType { | ||
|
|
@@ -595,10 +599,13 @@ mod tests { | |
| assert_eq!( | ||
| TokenInstruction::from_repr(variant_u8), | ||
| Some(TokenInstruction::try_from(variant_u8).unwrap()) | ||
|
|
||
|
Contributor
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. nit: Not needed. |
||
| ); | ||
| assert_eq!(TokenInstruction::try_from(variant_u8).unwrap(), variant); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
Comment on lines
+607
to
+608
Contributor
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. nit: Not needed. |
||
|
|
||
| #[test] | ||
| fn test_authority_type_from_u8_exhaustive() { | ||
|
|
||
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.
nit: Not needed.