-
Notifications
You must be signed in to change notification settings - Fork 207
Rename Pubkey to Address
#243
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
a7e1843
21912e2
e12b72a
63da4e7
6584f1c
9e46026
6dea6d5
3037122
d9f6d8c
8856c2c
7ea4e7d
b42b9de
6bafa2c
e420509
dbd425d
83ee358
ea66a64
8f8815a
38cb711
aad17f8
290970f
9e2a36b
f70a7cb
369baaf
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 |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| [package] | ||
| name = "solana-address" | ||
| description = "Solana account addresses" | ||
| documentation = "https://docs.rs/solana-address" | ||
| version = "0.1.0" | ||
| rust-version = "1.81.0" | ||
| authors = { workspace = true } | ||
| repository = { workspace = true } | ||
| homepage = { workspace = true } | ||
| license = { workspace = true } | ||
| edition = { workspace = true } | ||
|
|
||
| [features] | ||
| atomic = ["dep:solana-atomic-u64"] | ||
| borsh = ["dep:borsh", "std"] | ||
| bytemuck = ["dep:bytemuck", "dep:bytemuck_derive"] | ||
| curve25519 = ["dep:curve25519-dalek", "error", "sha2"] | ||
| decode = ["dep:five8", "dep:five8_const", "error"] | ||
| dev-context-only-utils = ["dep:arbitrary", "rand"] | ||
| error = ["dep:num-traits", "dep:solana-program-error"] | ||
| frozen-abi = [ | ||
| "dep:solana-frozen-abi", | ||
| "dep:solana-frozen-abi-macro", | ||
| "dep:solana-program-error", | ||
| "std", | ||
| ] | ||
| rand = ["dep:rand", "atomic", "std"] | ||
| sanitize = ["dep:solana-sanitize"] | ||
| serde = ["dep:serde", "dep:serde_derive"] | ||
| sha2 = ["dep:solana-sha256-hasher", "error"] | ||
| std = ["decode"] | ||
| syscalls = ["dep:solana-define-syscall", "error"] | ||
|
Contributor
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. The "error" feature is needed for syscalls since the helpers return an |
||
|
|
||
| [dependencies] | ||
| arbitrary = { workspace = true, features = ["derive"], optional = true } | ||
| borsh = { workspace = true, optional = true } | ||
| bytemuck = { workspace = true, optional = true } | ||
| bytemuck_derive = { workspace = true, optional = true } | ||
| five8 = { workspace = true, optional = true } | ||
| five8_const = { workspace = true, optional = true } | ||
| num-traits = { workspace = true, optional = true } | ||
| rand = { workspace = true, optional = true } | ||
| serde = { workspace = true, optional = true } | ||
| serde_derive = { workspace = true, optional = true } | ||
| solana-atomic-u64 = { workspace = true, optional = true } | ||
| solana-frozen-abi = { workspace = true, features = ["frozen-abi"], optional = true } | ||
| solana-frozen-abi-macro = { workspace = true, features = ["frozen-abi"], optional = true } | ||
| solana-program-error = { workspace = true, optional = true } | ||
| solana-sanitize = { workspace = true, optional = true } | ||
|
|
||
| [target.'cfg(not(target_os = "solana"))'.dependencies] | ||
| curve25519-dalek = { workspace = true, optional = true } | ||
| solana-sha256-hasher = { workspace = true, features = ["sha2"], optional = true } | ||
|
|
||
| [target.'cfg(target_os = "solana")'.dependencies] | ||
| solana-define-syscall = { workspace = true, optional = true } | ||
| solana-sha256-hasher = { workspace = true, optional = true } | ||
|
|
||
| [dev-dependencies] | ||
| anyhow = { workspace = true } | ||
| solana-account-info = { path = "../account-info" } | ||
| solana-address = { path = ".", features = [ | ||
| "atomic", | ||
| "borsh", | ||
| "curve25519", | ||
| "decode", | ||
| "dev-context-only-utils", | ||
| "error", | ||
| "sanitize", | ||
| "std", | ||
| "syscalls" | ||
| ] } | ||
| solana-cpi = { path = "../cpi" } | ||
| solana-example-mocks = { path = "../example-mocks" } | ||
| solana-hash = { workspace = true } | ||
| solana-instruction = { path = "../instruction", features = ["borsh"] } | ||
| solana-program-error = { workspace = true, features = ["borsh"] } | ||
| solana-system-interface = { workspace = true, features = ["bincode"] } | ||
| strum = { workspace = true } | ||
| strum_macros = { workspace = true } | ||
|
|
||
| [lints] | ||
| workspace = true | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| #[cfg(feature = "serde")] | ||
| use serde_derive::Serialize; | ||
| use { | ||
| core::{convert::Infallible, fmt}, | ||
| num_traits::{FromPrimitive, ToPrimitive}, | ||
| solana_program_error::ProgramError, | ||
| }; | ||
|
|
||
| // Use strum when testing to ensure our FromPrimitive | ||
| // impl is exhaustive | ||
| #[cfg_attr(test, derive(strum_macros::FromRepr, strum_macros::EnumIter))] | ||
| #[cfg_attr(feature = "serde", derive(serde_derive::Serialize))] | ||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| pub enum AddressError { | ||
| /// Length of the seed is too long for address generation | ||
| MaxSeedLengthExceeded, | ||
| InvalidSeeds, | ||
| IllegalOwner, | ||
| } | ||
|
|
||
| impl ToPrimitive for AddressError { | ||
| #[inline] | ||
| fn to_i64(&self) -> Option<i64> { | ||
| Some(match *self { | ||
| AddressError::MaxSeedLengthExceeded => AddressError::MaxSeedLengthExceeded as i64, | ||
| AddressError::InvalidSeeds => AddressError::InvalidSeeds as i64, | ||
| AddressError::IllegalOwner => AddressError::IllegalOwner as i64, | ||
| }) | ||
| } | ||
| #[inline] | ||
| fn to_u64(&self) -> Option<u64> { | ||
| self.to_i64().map(|x| x as u64) | ||
| } | ||
| } | ||
|
|
||
| impl FromPrimitive for AddressError { | ||
| #[inline] | ||
| fn from_i64(n: i64) -> Option<Self> { | ||
| if n == AddressError::MaxSeedLengthExceeded as i64 { | ||
| Some(AddressError::MaxSeedLengthExceeded) | ||
| } else if n == AddressError::InvalidSeeds as i64 { | ||
| Some(AddressError::InvalidSeeds) | ||
| } else if n == AddressError::IllegalOwner as i64 { | ||
| Some(AddressError::IllegalOwner) | ||
| } else { | ||
| None | ||
| } | ||
| } | ||
| #[inline] | ||
| fn from_u64(n: u64) -> Option<Self> { | ||
| Self::from_i64(n as i64) | ||
| } | ||
| } | ||
|
|
||
| impl core::error::Error for AddressError {} | ||
|
|
||
| impl fmt::Display for AddressError { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| match self { | ||
| AddressError::MaxSeedLengthExceeded => { | ||
| f.write_str("Length of the seed is too long for address generation") | ||
| } | ||
| AddressError::InvalidSeeds => { | ||
| f.write_str("Provided seeds do not result in a valid address") | ||
| } | ||
| AddressError::IllegalOwner => f.write_str("Provided owner is not allowed"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<u64> for AddressError { | ||
| fn from(error: u64) -> Self { | ||
| match error { | ||
| 0 => AddressError::MaxSeedLengthExceeded, | ||
| 1 => AddressError::InvalidSeeds, | ||
| 2 => AddressError::IllegalOwner, | ||
| _ => panic!("Unsupported AddressError"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<AddressError> for ProgramError { | ||
| fn from(error: AddressError) -> Self { | ||
| match error { | ||
| AddressError::MaxSeedLengthExceeded => Self::MaxSeedLengthExceeded, | ||
| AddressError::InvalidSeeds => Self::InvalidSeeds, | ||
| AddressError::IllegalOwner => Self::IllegalOwner, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Use strum when testing to ensure our FromPrimitive | ||
| // impl is exhaustive | ||
| #[cfg_attr(test, derive(strum_macros::FromRepr, strum_macros::EnumIter))] | ||
| #[cfg_attr(feature = "serde", derive(Serialize))] | ||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| pub enum ParseAddressError { | ||
| WrongSize, | ||
| Invalid, | ||
| } | ||
|
|
||
| impl ToPrimitive for ParseAddressError { | ||
| #[inline] | ||
| fn to_i64(&self) -> Option<i64> { | ||
| Some(match *self { | ||
| ParseAddressError::WrongSize => ParseAddressError::WrongSize as i64, | ||
| ParseAddressError::Invalid => ParseAddressError::Invalid as i64, | ||
| }) | ||
| } | ||
| #[inline] | ||
| fn to_u64(&self) -> Option<u64> { | ||
| self.to_i64().map(|x| x as u64) | ||
| } | ||
| } | ||
|
|
||
| impl FromPrimitive for ParseAddressError { | ||
| #[inline] | ||
| fn from_i64(n: i64) -> Option<Self> { | ||
| if n == ParseAddressError::WrongSize as i64 { | ||
| Some(ParseAddressError::WrongSize) | ||
| } else if n == ParseAddressError::Invalid as i64 { | ||
| Some(ParseAddressError::Invalid) | ||
| } else { | ||
| None | ||
| } | ||
| } | ||
| #[inline] | ||
| fn from_u64(n: u64) -> Option<Self> { | ||
| Self::from_i64(n as i64) | ||
| } | ||
| } | ||
|
|
||
| impl core::error::Error for ParseAddressError {} | ||
|
|
||
| impl fmt::Display for ParseAddressError { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| match self { | ||
| ParseAddressError::WrongSize => f.write_str("String is the wrong size"), | ||
| ParseAddressError::Invalid => f.write_str("Invalid Base58 string"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<Infallible> for ParseAddressError { | ||
| fn from(_: Infallible) -> Self { | ||
| unreachable!("Infallible uninhabited"); | ||
| } | ||
| } |
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.
Cool! I like how every dependency is optional! However I think you're going to annoy a lot of developers if you don't include a default. I recommend at least
decode, but you could also make a case forstd.We can build hyper-modular tooling to empower devs who want to optimize their programs, but that doesn't mean we need to increase the burden on the majority of developers.
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.
Yeah that's a good point. My thinking was that most people will use
solana-pubkeyfor a while, so that'll act like the "default" feature as people port over.Since it's a breaking change to remove features from the default, I'd prefer to keep this lean for now. We can always add default features later as people struggle. What do you think?
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.
I guess I'll leave it up to you, but if you have a small set of sensible defaults, and power users aren't happy with those, what's the reason you'd ever have to remove a default feature because someone couldn't get around it with
default-features = false?