-
Couldn't load subscription status.
- Fork 120
deps: Upgrade the rest of the repo to sdk v3 #797
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
Conversation
#### Problem The program / client / cli crates are still on SDK v2. #### Summary of changes Mostly straightforward, but upgrade everything to SDK v3! Intra-repo dependencies are restored for the most part, and breaking changes are dealt with as needed. The most noteworthy change is the addition of a `TryFrom<u32>` implementation for `TokenError`, which allows us to print the error appropriately.
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.
Looks great on the whole, but the manual error matching looks like overkill, since we're already using num_traits/num_derive and can take advantage of it.
| }; | ||
|
|
||
| /// Errors that may be returned by the Token program. | ||
| #[cfg_attr(test, derive(strum_macros::FromRepr, strum_macros::EnumIter))] |
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.
As part of the reduced try_from:
| #[cfg_attr(test, derive(strum_macros::FromRepr, strum_macros::EnumIter))] | |
| #[repr(u32)] | |
| #[cfg_attr(test, derive(strum_macros::FromRepr, strum_macros::EnumIter))] |
interface/src/error.rs
Outdated
| fn try_from(error: u32) -> Result<Self, Self::Error> { | ||
| match error { | ||
| 0 => Ok(Self::NotRentExempt), | ||
| 1 => Ok(Self::InsufficientFunds), | ||
| 2 => Ok(Self::InvalidMint), | ||
| 3 => Ok(Self::MintMismatch), | ||
| 4 => Ok(Self::OwnerMismatch), | ||
| 5 => Ok(Self::FixedSupply), | ||
| 6 => Ok(Self::AlreadyInUse), | ||
| 7 => Ok(Self::InvalidNumberOfProvidedSigners), | ||
| 8 => Ok(Self::InvalidNumberOfRequiredSigners), | ||
| 9 => Ok(Self::UninitializedState), | ||
| 10 => Ok(Self::NativeNotSupported), | ||
| 11 => Ok(Self::NonNativeHasBalance), | ||
| 12 => Ok(Self::InvalidInstruction), | ||
| 13 => Ok(Self::InvalidState), | ||
| 14 => Ok(Self::Overflow), | ||
| 15 => Ok(Self::AuthorityTypeNotSupported), | ||
| 16 => Ok(Self::MintCannotFreeze), | ||
| 17 => Ok(Self::AccountFrozen), | ||
| 18 => Ok(Self::MintDecimalsMismatch), | ||
| 19 => Ok(Self::NonNativeNotSupported), | ||
| 20 => Ok(Self::ExtensionTypeMismatch), | ||
| 21 => Ok(Self::ExtensionBaseMismatch), | ||
| 22 => Ok(Self::ExtensionAlreadyInitialized), | ||
| 23 => Ok(Self::ConfidentialTransferAccountHasBalance), | ||
| 24 => Ok(Self::ConfidentialTransferAccountNotApproved), | ||
| 25 => Ok(Self::ConfidentialTransferDepositsAndTransfersDisabled), | ||
| 26 => Ok(Self::ConfidentialTransferElGamalPubkeyMismatch), | ||
| 27 => Ok(Self::ConfidentialTransferBalanceMismatch), | ||
| 28 => Ok(Self::MintHasSupply), | ||
| 29 => Ok(Self::NoAuthorityExists), | ||
| 30 => Ok(Self::TransferFeeExceedsMaximum), | ||
| 31 => Ok(Self::MintRequiredForTransfer), | ||
| 32 => Ok(Self::FeeMismatch), | ||
| 33 => Ok(Self::FeeParametersMismatch), | ||
| 34 => Ok(Self::ImmutableOwner), | ||
| 35 => Ok(Self::AccountHasWithheldTransferFees), | ||
| 36 => Ok(Self::NoMemo), | ||
| 37 => Ok(Self::NonTransferable), | ||
| 38 => Ok(Self::NonTransferableNeedsImmutableOwnership), | ||
| 39 => Ok(Self::MaximumPendingBalanceCreditCounterExceeded), | ||
| 40 => Ok(Self::MaximumDepositAmountExceeded), | ||
| 41 => Ok(Self::CpiGuardSettingsLocked), | ||
| 42 => Ok(Self::CpiGuardTransferBlocked), | ||
| 43 => Ok(Self::CpiGuardBurnBlocked), | ||
| 44 => Ok(Self::CpiGuardCloseAccountBlocked), | ||
| 45 => Ok(Self::CpiGuardApproveBlocked), | ||
| 46 => Ok(Self::CpiGuardSetAuthorityBlocked), | ||
| 47 => Ok(Self::CpiGuardOwnerChangeBlocked), | ||
| 48 => Ok(Self::ExtensionNotFound), | ||
| 49 => Ok(Self::NonConfidentialTransfersDisabled), | ||
| 50 => Ok(Self::ConfidentialTransferFeeAccountHasWithheldFee), | ||
| 51 => Ok(Self::InvalidExtensionCombination), | ||
| 52 => Ok(Self::InvalidLengthForAlloc), | ||
| 53 => Ok(Self::AccountDecryption), | ||
| 54 => Ok(Self::ProofGeneration), | ||
| 55 => Ok(Self::InvalidProofInstructionOffset), | ||
| 56 => Ok(Self::HarvestToMintDisabled), | ||
| 57 => Ok(Self::SplitProofContextStateAccountsNotSupported), | ||
| 58 => Ok(Self::NotEnoughProofContextStateAccounts), | ||
| 59 => Ok(Self::MalformedCiphertext), | ||
| 60 => Ok(Self::CiphertextArithmeticFailed), | ||
| 61 => Ok(Self::PedersenCommitmentMismatch), | ||
| 62 => Ok(Self::RangeProofLengthMismatch), | ||
| 63 => Ok(Self::IllegalBitLength), | ||
| 64 => Ok(Self::FeeCalculation), | ||
| 65 => Ok(Self::IllegalMintBurnConversion), | ||
| 66 => Ok(Self::InvalidScale), | ||
| 67 => Ok(Self::MintPaused), | ||
| 68 => Ok(Self::PendingBalanceNonZero), | ||
| _ => Err(ProgramError::InvalidArgument), | ||
| } | ||
| } |
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 can avoid the huge match section (and make it future-proof) by using #[repr(u32)] and taking advantage of num_derive::FromPrimitive, which is already derived and provides from_u32() -> Option
| fn try_from(error: u32) -> Result<Self, Self::Error> { | |
| match error { | |
| 0 => Ok(Self::NotRentExempt), | |
| 1 => Ok(Self::InsufficientFunds), | |
| 2 => Ok(Self::InvalidMint), | |
| 3 => Ok(Self::MintMismatch), | |
| 4 => Ok(Self::OwnerMismatch), | |
| 5 => Ok(Self::FixedSupply), | |
| 6 => Ok(Self::AlreadyInUse), | |
| 7 => Ok(Self::InvalidNumberOfProvidedSigners), | |
| 8 => Ok(Self::InvalidNumberOfRequiredSigners), | |
| 9 => Ok(Self::UninitializedState), | |
| 10 => Ok(Self::NativeNotSupported), | |
| 11 => Ok(Self::NonNativeHasBalance), | |
| 12 => Ok(Self::InvalidInstruction), | |
| 13 => Ok(Self::InvalidState), | |
| 14 => Ok(Self::Overflow), | |
| 15 => Ok(Self::AuthorityTypeNotSupported), | |
| 16 => Ok(Self::MintCannotFreeze), | |
| 17 => Ok(Self::AccountFrozen), | |
| 18 => Ok(Self::MintDecimalsMismatch), | |
| 19 => Ok(Self::NonNativeNotSupported), | |
| 20 => Ok(Self::ExtensionTypeMismatch), | |
| 21 => Ok(Self::ExtensionBaseMismatch), | |
| 22 => Ok(Self::ExtensionAlreadyInitialized), | |
| 23 => Ok(Self::ConfidentialTransferAccountHasBalance), | |
| 24 => Ok(Self::ConfidentialTransferAccountNotApproved), | |
| 25 => Ok(Self::ConfidentialTransferDepositsAndTransfersDisabled), | |
| 26 => Ok(Self::ConfidentialTransferElGamalPubkeyMismatch), | |
| 27 => Ok(Self::ConfidentialTransferBalanceMismatch), | |
| 28 => Ok(Self::MintHasSupply), | |
| 29 => Ok(Self::NoAuthorityExists), | |
| 30 => Ok(Self::TransferFeeExceedsMaximum), | |
| 31 => Ok(Self::MintRequiredForTransfer), | |
| 32 => Ok(Self::FeeMismatch), | |
| 33 => Ok(Self::FeeParametersMismatch), | |
| 34 => Ok(Self::ImmutableOwner), | |
| 35 => Ok(Self::AccountHasWithheldTransferFees), | |
| 36 => Ok(Self::NoMemo), | |
| 37 => Ok(Self::NonTransferable), | |
| 38 => Ok(Self::NonTransferableNeedsImmutableOwnership), | |
| 39 => Ok(Self::MaximumPendingBalanceCreditCounterExceeded), | |
| 40 => Ok(Self::MaximumDepositAmountExceeded), | |
| 41 => Ok(Self::CpiGuardSettingsLocked), | |
| 42 => Ok(Self::CpiGuardTransferBlocked), | |
| 43 => Ok(Self::CpiGuardBurnBlocked), | |
| 44 => Ok(Self::CpiGuardCloseAccountBlocked), | |
| 45 => Ok(Self::CpiGuardApproveBlocked), | |
| 46 => Ok(Self::CpiGuardSetAuthorityBlocked), | |
| 47 => Ok(Self::CpiGuardOwnerChangeBlocked), | |
| 48 => Ok(Self::ExtensionNotFound), | |
| 49 => Ok(Self::NonConfidentialTransfersDisabled), | |
| 50 => Ok(Self::ConfidentialTransferFeeAccountHasWithheldFee), | |
| 51 => Ok(Self::InvalidExtensionCombination), | |
| 52 => Ok(Self::InvalidLengthForAlloc), | |
| 53 => Ok(Self::AccountDecryption), | |
| 54 => Ok(Self::ProofGeneration), | |
| 55 => Ok(Self::InvalidProofInstructionOffset), | |
| 56 => Ok(Self::HarvestToMintDisabled), | |
| 57 => Ok(Self::SplitProofContextStateAccountsNotSupported), | |
| 58 => Ok(Self::NotEnoughProofContextStateAccounts), | |
| 59 => Ok(Self::MalformedCiphertext), | |
| 60 => Ok(Self::CiphertextArithmeticFailed), | |
| 61 => Ok(Self::PedersenCommitmentMismatch), | |
| 62 => Ok(Self::RangeProofLengthMismatch), | |
| 63 => Ok(Self::IllegalBitLength), | |
| 64 => Ok(Self::FeeCalculation), | |
| 65 => Ok(Self::IllegalMintBurnConversion), | |
| 66 => Ok(Self::InvalidScale), | |
| 67 => Ok(Self::MintPaused), | |
| 68 => Ok(Self::PendingBalanceNonZero), | |
| _ => Err(ProgramError::InvalidArgument), | |
| } | |
| } | |
| #[inline] | |
| fn try_from(code: u32) -> Result<Self, Self::Error> { | |
| num_traits::FromPrimitive::from_u32(code).ok_or(ProgramError::InvalidArgument) | |
| } |
|
Beautiful, thanks for the suggestion! I completely forgot that we were using num-traits in this crate 😅 |
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.
🙌
Problem
The program / client / cli crates are still on SDK v2.
Summary of changes
Mostly straightforward, but upgrade everything to SDK v3! Intra-repodependencies are restored for the most part, and breaking changes are dealt with as needed.
The most noteworthy change is the addition of a
TryFrom<u32>implementation forTokenError, which allows us to print the error appropriately.Otherwise, most of the changes are similar to other sdkv3 upgrades.
Fixes #711