From 1025440184ef100a22d07c7bb543ee45cf169d64 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Mon, 14 May 2012 23:44:52 +0200 Subject: 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. --- src/script.h | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'src/script.h') diff --git a/src/script.h b/src/script.h index 163ce057d6..d490cd1824 100644 --- a/src/script.h +++ b/src/script.h @@ -5,15 +5,16 @@ #ifndef H_BITCOIN_SCRIPT #define H_BITCOIN_SCRIPT -#include "base58.h" - #include #include #include +#include + +#include "keystore.h" +#include "bignum.h" class CTransaction; -class CKeyStore; /** Signature hash types/flags */ enum @@ -35,6 +36,20 @@ enum txnouttype TX_MULTISIG, }; +class CNoDestination { +public: + friend bool operator==(const CNoDestination &a, const CNoDestination &b) { return true; } + friend bool operator<(const CNoDestination &a, const CNoDestination &b) { return true; } +}; + +/** A txout script template with a specific destination. It is either: + * * CNoDestination: no destination set + * * CKeyID: TX_PUBKEYHASH destination + * * CScriptID: TX_SCRIPTHASH destination + * A CTxDestination is the internal data type encoded in a CBitcoinAddress + */ +typedef boost::variant CTxDestination; + const char* GetTxnOutputType(txnouttype t); /** Script opcodes */ @@ -521,13 +536,8 @@ public: } - void SetBitcoinAddress(const CBitcoinAddress& address); - void SetBitcoinAddress(const std::vector& vchPubKey) - { - SetBitcoinAddress(CBitcoinAddress(vchPubKey)); - } + void SetDestination(const CTxDestination& address); void SetMultisig(int nRequired, const std::vector& keys); - void SetPayToScriptHash(const CScript& subscript); void PrintHex() const @@ -562,6 +572,11 @@ public: { printf("%s\n", ToString().c_str()); } + + CScriptID GetID() const + { + return CScriptID(Hash160(*this)); + } }; @@ -573,8 +588,9 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector >& vSolutions); bool IsStandard(const CScript& scriptPubKey); bool IsMine(const CKeyStore& keystore, const CScript& scriptPubKey); -bool ExtractAddress(const CScript& scriptPubKey, CBitcoinAddress& addressRet); -bool ExtractAddresses(const CScript& scriptPubKey, txnouttype& typeRet, std::vector& addressRet, int& nRequiredRet); +bool IsMine(const CKeyStore& keystore, const CTxDestination &dest); +bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet); +bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::vector& addressRet, int& nRequiredRet); bool SignSignature(const CKeyStore& keystore, const CTransaction& txFrom, CTransaction& txTo, unsigned int nIn, int nHashType=SIGHASH_ALL); bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, unsigned int nIn, bool fValidatePayToScriptHash, int nHashType); -- cgit v1.2.3