X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fscript.h;h=502bce1e54f1d5cf18b2580894a2a7e025af696a;hb=58ac600b2c94f12309fc5e18933891590dc1eb4c;hp=22a6020dcee1c63c90b975ef168876b91a976b25;hpb=223b6f1ba4819e9a146e7aa451d546726d0bc714;p=novacoin.git diff --git a/src/script.h b/src/script.h index 22a6020..502bce1 100644 --- a/src/script.h +++ b/src/script.h @@ -1,14 +1,18 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2011 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying -// file license.txt or http://www.opensource.org/licenses/mit-license.php. +// file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef H_BITCOIN_SCRIPT #define H_BITCOIN_SCRIPT #include "base58.h" +#include "keystore.h" #include #include +#include + class CTransaction; enum @@ -398,7 +402,8 @@ public: } - explicit CScript(char b) { operator<<(b); } + //explicit CScript(char b) is not portable. Use 'signed char' or 'unsigned char'. + explicit CScript(signed char b) { operator<<(b); } explicit CScript(short b) { operator<<(b); } explicit CScript(int b) { operator<<(b); } explicit CScript(long b) { operator<<(b); } @@ -415,7 +420,8 @@ public: explicit CScript(const std::vector& b) { operator<<(b); } - CScript& operator<<(char b) { return push_int64(b); } + //CScript& operator<<(char b) is not portable. Use 'signed char' or 'unsigned char'. + CScript& operator<<(signed char b) { return push_int64(b); } CScript& operator<<(short b) { return push_int64(b); } CScript& operator<<(int b) { return push_int64(b); } CScript& operator<<(long b) { return push_int64(b); } @@ -485,7 +491,7 @@ public: { // I'm not sure if this should push the script or concatenate scripts. // If there's ever a use for pushing a script onto a script, delete this member fn - assert(("warning: pushing a CScript onto a CScript with << is probably not intended, use + to concatenate", false)); + assert(!"warning: pushing a CScript onto a CScript with << is probably not intended, use + to concatenate"); return *this; } @@ -570,6 +576,14 @@ public: return true; } + // Encode/decode small integers: + static int DecodeOP_N(opcodetype opcode) + { + if (opcode == OP_0) + return 0; + assert(opcode >= OP_1 && opcode <= OP_16); + return (int)opcode - (int)(OP_1 - 1); + } void FindAndDelete(const CScript& b) { @@ -584,25 +598,28 @@ public: } while (GetOp(pc, opcode)); } - - - int GetSigOpCount() const + int Find(opcodetype op) const { - int n = 0; - const_iterator pc = begin(); - while (pc < end()) - { - opcodetype opcode; - if (!GetOp(pc, opcode)) - break; - if (opcode == OP_CHECKSIG || opcode == OP_CHECKSIGVERIFY) - n++; - else if (opcode == OP_CHECKMULTISIG || opcode == OP_CHECKMULTISIGVERIFY) - n += 20; - } - return n; + int nFound = 0; + opcodetype opcode; + for (const_iterator pc = begin(); pc != end() && GetOp(pc, opcode);) + if (opcode == op) + ++nFound; + return nFound; } + // Pre-version-0.6, Bitcoin always counted CHECKMULTISIGs + // as 20 sigops. With pay-to-script-hash, that changed: + // CHECKMULTISIGs serialized in scriptSigs are + // counted more accurately, assuming they are of the form + // ... OP_N CHECKMULTISIG ... + int GetSigOpCount(bool fAccurate=false) const; + + // Accurately count sigOps, including sigOps in + // pay-to-script-hash transactions: + int GetSigOpCount(const CScript& scriptSig) const; + + bool IsPayToScriptHash() const; bool IsPushOnly() const { @@ -621,7 +638,7 @@ public: } - uint160 GetBitcoinAddressHash160() const + CBitcoinAddress GetBitcoinAddress() const { opcodetype opcode; std::vector vch; @@ -633,36 +650,18 @@ public: 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; - } - - std::string GetBitcoinAddress() const - { - uint160 hash160 = GetBitcoinAddressHash160(); - if (hash160 == 0) - return ""; - return Hash160ToAddress(hash160); + return CBitcoinAddress(hash160); } - void SetBitcoinAddress(const uint160& hash160) + void SetBitcoinAddress(const CBitcoinAddress& address) { this->clear(); - *this << OP_DUP << OP_HASH160 << hash160 << OP_EQUALVERIFY << OP_CHECKSIG; + *this << OP_DUP << OP_HASH160 << address.GetHash160() << OP_EQUALVERIFY << OP_CHECKSIG; } void SetBitcoinAddress(const std::vector& vchPubKey) { - SetBitcoinAddress(Hash160(vchPubKey)); - } - - bool SetBitcoinAddress(const std::string& strAddress) - { - this->clear(); - uint160 hash160; - if (!AddressToHash160(strAddress, hash160)) - return false; - SetBitcoinAddress(hash160); - return true; + SetBitcoinAddress(CBitcoinAddress(vchPubKey)); } @@ -706,13 +705,12 @@ public: +bool EvalScript(std::vector >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, int nHashType); -uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType); bool IsStandard(const CScript& scriptPubKey); -bool IsMine(const CScript& scriptPubKey); -bool ExtractPubKey(const CScript& scriptPubKey, bool fMineOnly, std::vector& vchPubKeyRet); -bool ExtractHash160(const CScript& scriptPubKey, uint160& hash160Ret); -bool SignSignature(const CTransaction& txFrom, CTransaction& txTo, unsigned int nIn, int nHashType=SIGHASH_ALL, CScript scriptPrereq=CScript()); -bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, unsigned int nIn, int nHashType=0); +bool IsMine(const CKeyStore& keystore, const CScript& scriptPubKey); +bool ExtractAddress(const CScript& scriptPubKey, const CKeyStore* pkeystore, CBitcoinAddress& addressRet); +bool SignSignature(const CKeyStore& keystore, const CTransaction& txFrom, CTransaction& txTo, unsigned int nIn, int nHashType=SIGHASH_ALL, CScript scriptPrereq=CScript()); +bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, unsigned int nIn, bool fValidatePayToScriptHash, int nHashType); #endif