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 | 22f721dbf23cf5ce9e3ded9bcfb65a3894cc0f8c (patch) | |
tree | 61624e0903150505dc09977ae9ff1bc9ab40ee2b /script.h | |
parent | 73278c0a16cf0d68fb9011203a2112c3499df195 (diff) | |
download | bitcoin-22f721dbf23cf5ce9e3ded9bcfb65a3894cc0f8c.tar.xz |
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
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());
|