Skip to content

pod!: Standardize on PodOption<Address>#183

Open
grod220 wants to merge 1 commit intomainfrom
pod-option-updates
Open

pod!: Standardize on PodOption<Address>#183
grod220 wants to merge 1 commit intomainfrom
pod-option-updates

Conversation

@grod220
Copy link
Member

@grod220 grod220 commented Feb 26, 2026

Part of #175

spl-pod currently has two ways to represent optional addresses:

  • optional_keys::OptionalNonZeroPubkey
  • option::PodOption<Address>

This PR reduces this duplication and aligns on PodOption<Address> and extends PodOption to fully cover what was deleted in optional_keys:

  • From<PodOption> for Option
  • From<PodOption> for COption
  • borsh derives
  • serde impl for PodOption<Address>

Comment on lines +9 to +10
#[cfg(feature = "borsh")]
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
Copy link
Member Author

@grod220 grod220 Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OptionalNonZeroPubkey had borsh support fyi. Though, not sure if this serialization method is still blessed or if we should remove it in this breaking change. Noticed about half of the primitives have it and half don't.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably needed it for one of the token-2022 extensions, so we'd be in a tough position if it got removed

@grod220 grod220 mentioned this pull request Feb 26, 2026
11 tasks
@grod220 grod220 requested review from febo and joncinque February 26, 2026 10:19
Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few comments to make this a bit more general

Comment on lines +9 to +10
#[cfg(feature = "borsh")]
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably needed it for one of the token-2022 extensions, so we'd be in a tough position if it got removed

Comment on lines +49 to +52
#[cfg_attr(
feature = "borsh",
derive(BorshDeserialize, BorshSerialize, BorshSchema)
)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm just having a brain fart, but does this only work if T: BorshSerialize + BorshDeserialize + BorshSchema? Will it fail to compile if T doesn't implement those and the borsh feature is enabled in the crate?

We'll probably need to implement each trait conditionally

Comment on lines +157 to +158
#[cfg(feature = "serde")]
impl Serialize for PodOption<Address> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about implementing this generically for all T: Serialize?


#[cfg(feature = "serde")]
impl<'de> Deserialize<'de> for PodOption<Address> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with this, let's implement it generically using https://docs.rs/serde_core/latest/src/serde_core/de/impls.rs.html#916-934 as inspiration 😄

assert_eq!(def, None.try_into().unwrap());
}

#[cfg(feature = "borsh")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also enable the borsh feature in spl-pod to be sure that these tests run, since I don't see the feature being enabled on main currently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants