aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2011-07-11 21:48:09 +0200
committerPieter Wuille <sipa@ulyssis.org>2011-12-17 21:49:48 +0100
commit15a8590ecf6610387502be14d26657cb154d6201 (patch)
tree4b27e4231411357444dd890d5a13fbffdb67c9df
parent93db3fceac1bfe274bc0fd906428a20e709e2da5 (diff)
CBitcoinSecret added (base58 encoded privkey)
-rw-r--r--src/base58.h53
1 files changed, 49 insertions, 4 deletions
diff --git a/src/base58.h b/src/base58.h
index cace423d6e..113fa14a5e 100644
--- a/src/base58.h
+++ b/src/base58.h
@@ -18,6 +18,7 @@
#include <string>
#include <vector>
#include "bignum.h"
+#include "key.h"
static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
@@ -257,15 +258,14 @@ public:
class CBitcoinAddress : public CBase58Data
{
public:
- bool SetHash160(const uint160& hash160)
+ void SetHash160(const uint160& hash160)
{
SetData(fTestNet ? 111 : 0, &hash160, 20);
- return true;
}
- bool SetPubKey(const std::vector<unsigned char>& vchPubKey)
+ void SetPubKey(const std::vector<unsigned char>& vchPubKey)
{
- return SetHash160(Hash160(vchPubKey));
+ SetHash160(Hash160(vchPubKey));
}
bool IsValid() const
@@ -320,4 +320,49 @@ public:
}
};
+class CBitcoinSecret : public CBase58Data
+{
+public:
+ void SetSecret(const CSecret& vchSecret)
+ {
+ SetData(fTestNet ? 239 : 128, &vchSecret[0], vchSecret.size());
+ }
+
+ CSecret GetSecret()
+ {
+ CSecret vchSecret;
+ vchSecret.resize(vchData.size());
+ memcpy(&vchSecret[0], &vchData[0], vchData.size());
+ return vchSecret;
+ }
+
+ bool IsValid() const
+ {
+ int nExpectedSize = 32;
+ bool fExpectTestNet = false;
+ switch(nVersion)
+ {
+ case 128:
+ break;
+
+ case 239:
+ fExpectTestNet = true;
+ break;
+
+ default:
+ return false;
+ }
+ return fExpectTestNet == fTestNet && vchData.size() == nExpectedSize;
+ }
+
+ CBitcoinSecret(const CSecret& vchSecret)
+ {
+ SetSecret(vchSecret);
+ }
+
+ CBitcoinSecret()
+ {
+ }
+};
+
#endif