aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2014-09-11 19:15:29 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2014-09-16 19:14:32 +0200
commit0be990ba34110184c8a5a2c04094311dab5cd84c (patch)
tree2eb24931c396ae0dc0c57fee42f345c581bd58c6 /src/script
parentab3834baae2e48708de2be74217eaf9da9081fc3 (diff)
downloadbitcoin-0be990ba34110184c8a5a2c04094311dab5cd84c.tar.xz
Move CTxDestination from script/script to script/standard
Diffstat (limited to 'src/script')
-rw-r--r--src/script/script.cpp40
-rw-r--r--src/script/script.h17
-rw-r--r--src/script/standard.cpp47
-rw-r--r--src/script/standard.h17
4 files changed, 64 insertions, 57 deletions
diff --git a/src/script/script.cpp b/src/script/script.cpp
index 3c9f38dc8b..a5126e7cc2 100644
--- a/src/script/script.cpp
+++ b/src/script/script.cpp
@@ -253,43 +253,3 @@ bool CScript::HasCanonicalPushes() const
}
return true;
}
-
-class CScriptVisitor : public boost::static_visitor<bool>
-{
-private:
- CScript *script;
-public:
- CScriptVisitor(CScript *scriptin) { script = scriptin; }
-
- bool operator()(const CNoDestination &dest) const {
- script->clear();
- return false;
- }
-
- bool operator()(const CKeyID &keyID) const {
- script->clear();
- *script << OP_DUP << OP_HASH160 << keyID << OP_EQUALVERIFY << OP_CHECKSIG;
- return true;
- }
-
- bool operator()(const CScriptID &scriptID) const {
- script->clear();
- *script << OP_HASH160 << scriptID << OP_EQUAL;
- return true;
- }
-};
-
-void CScript::SetDestination(const CTxDestination& dest)
-{
- boost::apply_visitor(CScriptVisitor(this), dest);
-}
-
-void CScript::SetMultisig(int nRequired, const std::vector<CPubKey>& keys)
-{
- this->clear();
-
- *this << EncodeOP_N(nRequired);
- BOOST_FOREACH(const CPubKey& key, keys)
- *this << key;
- *this << EncodeOP_N(keys.size()) << OP_CHECKMULTISIG;
-}
diff --git a/src/script/script.h b/src/script/script.h
index 2336cafd67..07a4229f85 100644
--- a/src/script/script.h
+++ b/src/script/script.h
@@ -320,20 +320,6 @@ inline std::string ValueString(const std::vector<unsigned char>& vch)
return HexStr(vch);
}
-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;
-
/** Serialized script, used inside transaction inputs and outputs */
class CScript : public std::vector<unsigned char>
{
@@ -604,9 +590,6 @@ public:
return (size() > 0 && *begin() == OP_RETURN);
}
- void SetDestination(const CTxDestination& address);
- void SetMultisig(int nRequired, const std::vector<CPubKey>& keys);
-
std::string ToString() const
{
std::string str;
diff --git a/src/script/standard.cpp b/src/script/standard.cpp
index bda4b8b0ae..407baf621d 100644
--- a/src/script/standard.cpp
+++ b/src/script/standard.cpp
@@ -252,3 +252,50 @@ bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, vecto
return true;
}
+
+namespace
+{
+class CScriptVisitor : public boost::static_visitor<bool>
+{
+private:
+ CScript *script;
+public:
+ CScriptVisitor(CScript *scriptin) { script = scriptin; }
+
+ bool operator()(const CNoDestination &dest) const {
+ script->clear();
+ return false;
+ }
+
+ bool operator()(const CKeyID &keyID) const {
+ script->clear();
+ *script << OP_DUP << OP_HASH160 << keyID << OP_EQUALVERIFY << OP_CHECKSIG;
+ return true;
+ }
+
+ bool operator()(const CScriptID &scriptID) const {
+ script->clear();
+ *script << OP_HASH160 << scriptID << OP_EQUAL;
+ return true;
+ }
+};
+}
+
+CScript GetScriptForDestination(const CTxDestination& dest)
+{
+ CScript script;
+
+ boost::apply_visitor(CScriptVisitor(&script), dest);
+ return script;
+}
+
+CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey>& keys)
+{
+ CScript script;
+
+ script << CScript::EncodeOP_N(nRequired);
+ BOOST_FOREACH(const CPubKey& key, keys)
+ script << key;
+ script << CScript::EncodeOP_N(keys.size()) << OP_CHECKMULTISIG;
+ return script;
+}
diff --git a/src/script/standard.h b/src/script/standard.h
index 6c17a9394e..ead79b82a2 100644
--- a/src/script/standard.h
+++ b/src/script/standard.h
@@ -45,6 +45,20 @@ enum txnouttype
TX_NULL_DATA,
};
+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);
bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet);
@@ -53,4 +67,7 @@ bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType);
bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet);
bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet);
+CScript GetScriptForDestination(const CTxDestination& dest);
+CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey>& keys);
+
#endif // H_BITCOIN_SCRIPT_STANDARD