Skip to content

Commit

Permalink
feat: use the old serialisation as default, add some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
grumbach authored and joshuef committed Feb 21, 2024
1 parent 54b6de7 commit 505982b
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions sn_transfers/src/cashnotes/unique_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ impl DerivationIndex {
}
}

#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
// NB TODO remove Serialize impl when enough nodes have updated to support the new serialisation format!
// cf below for the new Serialize impl
/// A Unique Public Key is the unique identifier of a CashNote and its SignedSpend on the Network when it is spent.
/// It is the mechanism that makes transactions untraceable to the real owner (MainPubkey).
/// It is the equivalent to using a different key for each transaction in bitcoin.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize)]
pub struct UniquePubkey(PublicKey);

impl UniquePubkey {
Expand Down Expand Up @@ -69,14 +74,16 @@ impl UniquePubkey {
}
}

/// Custom implementation of Serialize and Deserialize for UniquePubkey to make it an actionable
/// hex string that can be copy pasted in apps, instead of a useless array of numbers
/// Caveat: this is slower than the default implementation
impl Serialize for UniquePubkey {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
serializer.serialize_str(&self.to_hex())
}
}
// NB TODO enable this when enough nodes have updated to support the new serialisation format!
// cf above (remove the derived Serialize impl and enable this one)
// /// Custom implementation of Serialize and Deserialize for UniquePubkey to make it an actionable
// /// hex string that can be copy pasted in apps, instead of a useless array of numbers
// /// Caveat: this is slower than the default implementation
// impl Serialize for UniquePubkey {
// fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// serializer.serialize_str(&self.to_hex())
// }
// }

impl<'de> Deserialize<'de> for UniquePubkey {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
Expand Down

0 comments on commit 505982b

Please sign in to comment.