aboutsummaryrefslogtreecommitdiff
path: root/src/script.h
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-05-14 23:44:52 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2012-05-24 20:26:19 +0200
commit1025440184ef100a22d07c7bb543ee45cf169d64 (patch)
treecd85ae7d981820189e506167e518adaf820aa638 /src/script.h
parentfd61d6f5068cf92d34569862b4225f177049a4f0 (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/script.h')
-rw-r--r--src/script.h38
1 files changed, 27 insertions, 11 deletions
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 <string>
#include <vector>
#include <boost/foreach.hpp>
+#include <boost/variant.hpp>
+
+#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<CNoDestination, CKeyID, CScriptID> CTxDestination;
+
const char* GetTxnOutputType(txnouttype t);
/** Script opcodes */
@@ -521,13 +536,8 @@ public:
}
- void SetBitcoinAddress(const CBitcoinAddress& address);
- void SetBitcoinAddress(const std::vector<unsigned char>& vchPubKey)
- {
- SetBitcoinAddress(CBitcoinAddress(vchPubKey));
- }
+ void SetDestination(const CTxDestination& address);
void SetMultisig(int nRequired, const std::vector<CKey>& 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<std::v
int ScriptSigArgsExpected(txnouttype t, const std::vector<std::vector<unsigned char> >& 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<CBitcoinAddress>& 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<CTxDestination>& 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);