diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2012-05-14 23:44:52 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2012-05-24 20:26:19 +0200 |
commit | 1025440184ef100a22d07c7bb543ee45cf169d64 (patch) | |
tree | cd85ae7d981820189e506167e518adaf820aa638 /src/key.h | |
parent | fd61d6f5068cf92d34569862b4225f177049a4f0 (diff) |
Refactor: split CKeyID/CScriptID/CTxDestination from CBitcoinAddress
This introduces internal types:
* CKeyID: reference (hash160) of a key
* CScriptID: reference (hash160) of a script
* CTxDestination: a boost::variant of the former two
CBitcoinAddress is retrofitted to be a Base58 encoding of a
CTxDestination. This allows all internal code to only use the
internal types, and only have RPC and GUI depend on the base58 code.
Furthermore, the header dependencies are a lot saner now. base58.h is
at the top (right below rpc and gui) instead of at the bottom. For the
rest: wallet -> script -> keystore -> key. Only keystore still requires
a forward declaration of CScript. Solving that would require splitting
script into two layers.
Diffstat (limited to 'src/key.h')
-rw-r--r-- | src/key.h | 25 |
1 files changed, 23 insertions, 2 deletions
@@ -44,6 +44,23 @@ public: explicit key_error(const std::string& str) : std::runtime_error(str) {} }; +/** A reference to a CKey: the Hash160 of its serialized public key */ +class CKeyID : public uint160 +{ +public: + CKeyID() : uint160(0) { } + CKeyID(const uint160 &in) : uint160(in) { } +}; + +/** A reference to a CScript: the Hash160 of its serialization (see script.h) */ +class CScriptID : public uint160 +{ +public: + CScriptID() : uint160(0) { } + CScriptID(const uint160 &in) : uint160(in) { } +}; + +/** An encapsulated public key. */ class CPubKey { private: std::vector<unsigned char> vchPubKey; @@ -60,8 +77,8 @@ public: READWRITE(vchPubKey); ) - uint160 GetID() const { - return Hash160(vchPubKey); + CKeyID GetID() const { + return CKeyID(Hash160(vchPubKey)); } uint256 GetHash() const { @@ -72,6 +89,10 @@ public: return vchPubKey.size() == 33 || vchPubKey.size() == 65; } + bool IsCompressed() const { + return vchPubKey.size() == 33; + } + std::vector<unsigned char> Raw() const { return vchPubKey; } |