aboutsummaryrefslogtreecommitdiff
path: root/src/base58.h
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2011-11-21 02:46:28 +0100
committerPieter Wuille <pieter.wuille@gmail.com>2012-01-09 15:18:19 +0100
commit11529c6e4f7288d8a64c488a726ee3821c7adefe (patch)
tree0f727a647b327687eb7894d824eb47d3578dfb92 /src/base58.h
parent1684f98b27de9323d24ee4489af54dd84083956a (diff)
downloadbitcoin-11529c6e4f7288d8a64c488a726ee3821c7adefe.tar.xz
Compressed pubkeys
This patch enabled compressed pubkeys when -compressedpubkeys is passed. These are 33 bytes instead of 65, and require only marginally more CPU power when verifying. Compressed pubkeys have a different corresponding address, so it is determined at generation. When -compressedpubkeys is given, all newly generated addresses will use a compressed key, while older/other addresses keep using normal keys. Unpatched clients will relay and verify these transactions.
Diffstat (limited to 'src/base58.h')
-rw-r--r--src/base58.h21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/base58.h b/src/base58.h
index ef6493d45b..dce932b4a8 100644
--- a/src/base58.h
+++ b/src/base58.h
@@ -359,22 +359,25 @@ public:
class CBitcoinSecret : public CBase58Data
{
public:
- void SetSecret(const CSecret& vchSecret)
- {
+ void SetSecret(const CSecret& vchSecret, bool fCompressed)
+ {
+ assert(vchSecret.size() == 32);
SetData(fTestNet ? 239 : 128, &vchSecret[0], vchSecret.size());
+ if (fCompressed)
+ vchData.push_back(1);
}
- CSecret GetSecret()
+ CSecret GetSecret(bool &fCompressedOut)
{
CSecret vchSecret;
- vchSecret.resize(vchData.size());
- memcpy(&vchSecret[0], &vchData[0], vchData.size());
+ vchSecret.resize(32);
+ memcpy(&vchSecret[0], &vchData[0], 32);
+ fCompressedOut = vchData.size() == 33;
return vchSecret;
}
bool IsValid() const
{
- int nExpectedSize = 32;
bool fExpectTestNet = false;
switch(nVersion)
{
@@ -388,12 +391,12 @@ public:
default:
return false;
}
- return fExpectTestNet == fTestNet && vchData.size() == nExpectedSize;
+ return fExpectTestNet == fTestNet && (vchData.size() == 32 || (vchData.size() == 33 && vchData[32] == 1));
}
- CBitcoinSecret(const CSecret& vchSecret)
+ CBitcoinSecret(const CSecret& vchSecret, bool fCompressed)
{
- SetSecret(vchSecret);
+ SetSecret(vchSecret, fCompressed);
}
CBitcoinSecret()