Skip to content

Conversation

paahaad
Copy link

@paahaad paahaad commented Jun 10, 2025

Added Docs and testcases for pubkey crate.

@paahaad
Copy link
Author

paahaad commented Jun 16, 2025

@febo sir, is it helpfull or should I close this?

@@ -4,6 +4,17 @@ pub use five8_const::decode_32_const;
pub use pinocchio;

/// Convenience macro to define a static `Pubkey` value.
///
/// This macro validates the pubkey at compile time, ensuring it's a valid
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not always in compile time – it depends on the input. The const qualifier allows it to be done in compile time when the input is static.

@@ -48,8 +48,7 @@ pinocchio_pubkey::declare_id!("Ping111111111111111111111111111111111111111");

3) Creating a `Pubkey` from a `&str`:
```rust
let address = String::from("7qtAvP4CJuSKauWHtHZJt9wmQRgvcFeUcU3xKrFzxKf1");
let owner = pinocchio_pubkey::from_str(&address);
const OWNER: pinocchio::pubkey::Pubkey = pinocchio_pubkey::from_str("7qtAvP4CJuSKauWHtHZJt9wmQRgvcFeUcU3xKrFzxKf1");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure what is the benefit of changing this example.

/// This macro also defines a helper function to check whether a given pubkey is
/// equal to the program ID.
/// This macro also defines helper functions to check whether a given pubkey is
/// equal to the program ID, providing a complete program identity management solution.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The part of "providing a complete program identity management solution." is strange, does not read right.

/// ```rust
/// use pinocchio_pubkey::declare_id;
///
/// declare_id!("11111111111111111111111111111111");
Copy link
Collaborator

Choose a reason for hiding this comment

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

This example needs to be more complete, e.g., show how the helper functions can be used.

Copy link
Author

Choose a reason for hiding this comment

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

added more uses of helper function.

@@ -35,8 +59,51 @@ macro_rules! declare_id {
};
}

/// Create a `Pubkey` from a `&str`.
/// Create a `Pubkey` from a `&str` at compile time.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment about the "compile time".

fn test_const_pubkey_creation() {
const SYSTEM_PROGRAM: Pubkey = from_str("11111111111111111111111111111111");
// This test just ensures compilation works
assert_eq!(SYSTEM_PROGRAM.len(), 32);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs more asserts.

Copy link
Author

Choose a reason for hiding this comment

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

added more asserts with different cases

@febo
Copy link
Collaborator

febo commented Jun 19, 2025

@febo sir, is it helpfull or should I close this?

It could eventually be helpful, but needs some fixes. Left some comments.

#[inline(always)]
pub const fn from_str(value: &str) -> pinocchio::pubkey::Pubkey {
decode_32_const(value)
}

/// Type alias for the Pubkey type for convenience.
pub type Pubkey = pinocchio::pubkey::Pubkey;
Copy link
Collaborator

@febo febo Jul 16, 2025

Choose a reason for hiding this comment

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

This is strange and unnecessary. You can just import the Pubkey type if you need it. Most likely you want to import the type for your tests.

Copy link
Collaborator

@febo febo left a comment

Choose a reason for hiding this comment

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

Left a small nit. Could you please also rebase the PR since there are changes on main on the same package?

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