diff options
author | s_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b> | 2010-02-12 20:38:44 +0000 |
---|---|---|
committer | s_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b> | 2010-02-12 20:38:44 +0000 |
commit | 98500d70a8cf25af4bab80526fd128ccdc36ceeb (patch) | |
tree | 61624e0903150505dc09977ae9ff1bc9ab40ee2b /script.h | |
parent | fa9dbd6b62ab161c29c9b8cf97b9c8da8ef4346e (diff) |
command line and JSON-RPC first draft, requires Boost 1.35 or higher for boost::asio,
added SetBitcoinAddress and GetBitcoinAddress methods on CScript,
critsect interlocks around mapAddressBook,
added some random delays in tx broadcast to improve privacy,
now compiles with MSVC 8.0
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@60 1a98c847-1fd6-4fd8-948a-caf3550aa51b
Diffstat (limited to 'script.h')
-rw-r--r-- | script.h | 44 |
1 files changed, 42 insertions, 2 deletions
@@ -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());
|