From ec6887b845ddbeca1126ebcb7fa65072b643ff78 Mon Sep 17 00:00:00 2001 From: Andymeows Date: Thu, 7 Aug 2014 17:48:28 -0500 Subject: [PATCH] Adding a Compress method to the CPubKey class to mirror the Decompress method --- src/key.cpp | 10 ++++++++++ src/key.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/key.cpp b/src/key.cpp index 2199996cf..ac05ed254 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -509,6 +509,16 @@ bool CPubKey::IsFullyValid() const { return true; } +bool CPubKey::Compress() { + if (!IsValid()) + return false; + CECKey key; + if (!key.SetPubKey(*this)) + return false; + key.GetPubKey(*this, true); + return true; +} + bool CPubKey::Decompress() { if (!IsValid()) return false; diff --git a/src/key.h b/src/key.h index 37a06810b..56a20e15f 100644 --- a/src/key.h +++ b/src/key.h @@ -163,6 +163,9 @@ public: // Recover a public key from a compact signature. bool RecoverCompact(const uint256 &hash, const std::vector& vchSig); + // Turn this public key into a compressed public key. + bool Compress(); + // Turn this public key into an uncompressed public key. bool Decompress();