Skip to content
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

Implement Deserialize for PublicKey, Algorithm, UnlockConditions, SiacoinOutputID, SiacoinInputID, SiacoinOutput, SiacoinInput, SiafundOutput and SiafundInput #32

Merged
merged 11 commits into from
Jul 15, 2024

Conversation

ChrisSchinnerl
Copy link
Member

@ChrisSchinnerl ChrisSchinnerl commented Jul 9, 2024

This includes a test that verifies both the binary and json encoding against actual output from core.


/// An ed25519 public key that can be used to verify a signature
#[derive(Debug, PartialEq, Clone, Copy)]
pub struct PublicKey([u8; 32]);

impl PublicKey {
const PREFIX: &'static str = "ed25519:";
Copy link
Member Author

Choose a reason for hiding this comment

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

I'd like to draw some attention to this. Strictly speaking types.PublicKey in core adds this prefix when json marshaling. Unfortunately though, UnlockKey with specifier ed25519 doesn't serialize the same as PublicKey so UnlockKey can't replace PublicKey.

@ChrisSchinnerl ChrisSchinnerl changed the title Implement Deserialize for SiacoinOutput and SiacoinInput Implement Deserialize for PublicKey, UnlockKey, Algorithm, SiacoinOutput and SiacoinInput Jul 10, 2024
@ChrisSchinnerl ChrisSchinnerl changed the title Implement Deserialize for PublicKey, UnlockKey, Algorithm, SiacoinOutput and SiacoinInput Implement Deserialize for PublicKey, Algorithm, UnlockConditions, SiacoinOutput and SiacoinInput Jul 10, 2024
@ChrisSchinnerl ChrisSchinnerl changed the title Implement Deserialize for PublicKey, Algorithm, UnlockConditions, SiacoinOutput and SiacoinInput Implement Deserialize for PublicKey, Algorithm, UnlockConditions, SiacoinOutput, SiacoinInput, SiafundOutput and SiafundInput Jul 10, 2024
@@ -31,9 +31,9 @@ pub struct Hash256([u8; 32]);
impl Serialize for Hash256 {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
if serializer.is_human_readable() {
serializer.serialize_str(&self.to_string())
String::serialize(&self.to_string(), serializer)
Copy link
Member Author

Choose a reason for hiding this comment

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

FYI: these renames are for consistency rather than functionality. In theory &self.to_string().serialize(&serializer) might also work but specifying the intended type first and then calling serialize on it seemed like the most readable option to me.

@ChrisSchinnerl ChrisSchinnerl changed the title Implement Deserialize for PublicKey, Algorithm, UnlockConditions, SiacoinOutput, SiacoinInput, SiafundOutput and SiafundInput Implement Deserialize for PublicKey, Algorithm, UnlockConditions, SiacoinOutputID, SiacoinInputID, SiacoinOutput, SiacoinInput, SiafundOutput and SiafundInput Jul 10, 2024
@ChrisSchinnerl ChrisSchinnerl self-assigned this Jul 10, 2024
@ChrisSchinnerl ChrisSchinnerl marked this pull request as ready for review July 10, 2024 12:59
@n8maninger n8maninger merged commit d1c4a4e into master Jul 15, 2024
1 check passed
@n8maninger n8maninger deleted the chris/deserialize-common branch July 15, 2024 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants