aboutsummaryrefslogtreecommitdiff
path: root/script.h
diff options
context:
space:
mode:
Diffstat (limited to 'script.h')
-rw-r--r--script.h44
1 files changed, 42 insertions, 2 deletions
diff --git a/script.h b/script.h
index 0d977734b9..9e41889150 100644
--- a/script.h
+++ b/script.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 Satoshi Nakamoto
+// Copyright (c) 2009-2010 Satoshi Nakamoto
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
@@ -472,7 +472,7 @@ public:
bool GetOp(iterator& pc, opcodetype& opcodeRet, vector<unsigned char>& vchRet)
{
- // This is why people hate C++
+ // Wrapper so it can be called with either iterator or const_iterator
const_iterator pc2 = pc;
bool fRet = GetOp(pc2, opcodeRet, vchRet);
pc = begin() + (pc2 - begin());
@@ -551,6 +551,46 @@ public:
}
+ uint160 GetBitcoinAddressHash160() const
+ {
+ opcodetype opcode;
+ vector<unsigned char> vch;
+ CScript::const_iterator pc = begin();
+ if (!GetOp(pc, opcode, vch) || opcode != OP_DUP) return 0;
+ if (!GetOp(pc, opcode, vch) || opcode != OP_HASH160) return 0;
+ if (!GetOp(pc, opcode, vch) || vch.size() != sizeof(uint160)) return 0;
+ uint160 hash160 = uint160(vch);
+ if (!GetOp(pc, opcode, vch) || opcode != OP_EQUALVERIFY) return 0;
+ if (!GetOp(pc, opcode, vch) || opcode != OP_CHECKSIG) return 0;
+ if (pc != end()) return 0;
+ return hash160;
+ }
+
+ string GetBitcoinAddress() const
+ {
+ uint160 hash160 = GetBitcoinAddressHash160();
+ if (hash160 == 0)
+ return "";
+ return Hash160ToAddress(hash160);
+ }
+
+ void SetBitcoinAddress(const uint160& hash160)
+ {
+ this->clear();
+ *this << OP_DUP << OP_HASH160 << hash160 << OP_EQUALVERIFY << OP_CHECKSIG;
+ }
+
+ bool SetBitcoinAddress(const string& strAddress)
+ {
+ this->clear();
+ uint160 hash160;
+ if (!AddressToHash160(strAddress, hash160))
+ return false;
+ SetBitcoinAddress(hash160);
+ return true;
+ }
+
+
void PrintHex() const
{
printf("CScript(%s)\n", HexStr(begin(), end()).c_str());