Refactor: Remove using namespace <xxx> from script/

pull/365/head
Karl-Johan Alm 8 years ago
parent f3c264e9a6
commit 8cbfc4e472
No known key found for this signature in database
GPG Key ID: 57AF762DB3353322

@ -13,9 +13,7 @@
#include "script/script.h" #include "script/script.h"
#include "uint256.h" #include "uint256.h"
using namespace std; typedef std::vector<unsigned char> valtype;
typedef vector<unsigned char> valtype;
namespace { namespace {
@ -56,10 +54,10 @@ bool CastToBool(const valtype& vch)
*/ */
#define stacktop(i) (stack.at(stack.size()+(i))) #define stacktop(i) (stack.at(stack.size()+(i)))
#define altstacktop(i) (altstack.at(altstack.size()+(i))) #define altstacktop(i) (altstack.at(altstack.size()+(i)))
static inline void popstack(vector<valtype>& stack) static inline void popstack(std::vector<valtype>& stack)
{ {
if (stack.empty()) if (stack.empty())
throw runtime_error("popstack(): stack empty"); throw std::runtime_error("popstack(): stack empty");
stack.pop_back(); stack.pop_back();
} }
@ -194,7 +192,7 @@ bool static IsDefinedHashtypeSignature(const valtype &vchSig) {
return true; return true;
} }
bool CheckSignatureEncoding(const vector<unsigned char> &vchSig, unsigned int flags, ScriptError* serror) { bool CheckSignatureEncoding(const std::vector<unsigned char> &vchSig, unsigned int flags, ScriptError* serror) {
// Empty signature. Not strictly DER encoded, but allowed to provide a // Empty signature. Not strictly DER encoded, but allowed to provide a
// compact way to provide an invalid signature for use with CHECK(MULTI)SIG // compact way to provide an invalid signature for use with CHECK(MULTI)SIG
if (vchSig.size() == 0) { if (vchSig.size() == 0) {
@ -245,7 +243,7 @@ bool static CheckMinimalPush(const valtype& data, opcodetype opcode) {
return true; return true;
} }
bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* serror) bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* serror)
{ {
static const CScriptNum bnZero(0); static const CScriptNum bnZero(0);
static const CScriptNum bnOne(1); static const CScriptNum bnOne(1);
@ -260,8 +258,8 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, un
CScript::const_iterator pbegincodehash = script.begin(); CScript::const_iterator pbegincodehash = script.begin();
opcodetype opcode; opcodetype opcode;
valtype vchPushValue; valtype vchPushValue;
vector<bool> vfExec; std::vector<bool> vfExec;
vector<valtype> altstack; std::vector<valtype> altstack;
set_error(serror, SCRIPT_ERR_UNKNOWN_ERROR); set_error(serror, SCRIPT_ERR_UNKNOWN_ERROR);
if (script.size() > MAX_SCRIPT_SIZE) if (script.size() > MAX_SCRIPT_SIZE)
return set_error(serror, SCRIPT_ERR_SCRIPT_SIZE); return set_error(serror, SCRIPT_ERR_SCRIPT_SIZE);
@ -1250,14 +1248,14 @@ bool TransactionSignatureChecker::VerifySignature(const std::vector<unsigned cha
return pubkey.Verify(sighash, vchSig); return pubkey.Verify(sighash, vchSig);
} }
bool TransactionSignatureChecker::CheckSig(const vector<unsigned char>& vchSigIn, const vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const bool TransactionSignatureChecker::CheckSig(const std::vector<unsigned char>& vchSigIn, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const
{ {
CPubKey pubkey(vchPubKey); CPubKey pubkey(vchPubKey);
if (!pubkey.IsValid()) if (!pubkey.IsValid())
return false; return false;
// Hash type is one byte tacked on to the end of the signature // Hash type is one byte tacked on to the end of the signature
vector<unsigned char> vchSig(vchSigIn); std::vector<unsigned char> vchSig(vchSigIn);
if (vchSig.empty()) if (vchSig.empty())
return false; return false;
int nHashType = vchSig.back(); int nHashType = vchSig.back();
@ -1355,7 +1353,7 @@ bool TransactionSignatureChecker::CheckSequence(const CScriptNum& nSequence) con
static bool VerifyWitnessProgram(const CScriptWitness& witness, int witversion, const std::vector<unsigned char>& program, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* serror) static bool VerifyWitnessProgram(const CScriptWitness& witness, int witversion, const std::vector<unsigned char>& program, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* serror)
{ {
vector<vector<unsigned char> > stack; std::vector<std::vector<unsigned char> > stack;
CScript scriptPubKey; CScript scriptPubKey;
if (witversion == 0) { if (witversion == 0) {
@ -1420,7 +1418,7 @@ bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const C
return set_error(serror, SCRIPT_ERR_SIG_PUSHONLY); return set_error(serror, SCRIPT_ERR_SIG_PUSHONLY);
} }
vector<vector<unsigned char> > stack, stackCopy; std::vector<std::vector<unsigned char> > stack, stackCopy;
if (!EvalScript(stack, scriptSig, flags, checker, SIGVERSION_BASE, serror)) if (!EvalScript(stack, scriptSig, flags, checker, SIGVERSION_BASE, serror))
// serror is set // serror is set
return false; return false;
@ -1558,7 +1556,7 @@ size_t CountWitnessSigOps(const CScript& scriptSig, const CScript& scriptPubKey,
if (scriptPubKey.IsPayToScriptHash() && scriptSig.IsPushOnly()) { if (scriptPubKey.IsPayToScriptHash() && scriptSig.IsPushOnly()) {
CScript::const_iterator pc = scriptSig.begin(); CScript::const_iterator pc = scriptSig.begin();
vector<unsigned char> data; std::vector<unsigned char> data;
while (pc < scriptSig.end()) { while (pc < scriptSig.end()) {
opcodetype opcode; opcodetype opcode;
scriptSig.GetOp(pc, opcode, data); scriptSig.GetOp(pc, opcode, data);

@ -13,11 +13,9 @@
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
using namespace std; typedef std::vector<unsigned char> valtype;
typedef vector<unsigned char> valtype; unsigned int HaveKeys(const std::vector<valtype>& pubkeys, const CKeyStore& keystore)
unsigned int HaveKeys(const vector<valtype>& pubkeys, const CKeyStore& keystore)
{ {
unsigned int nResult = 0; unsigned int nResult = 0;
BOOST_FOREACH(const valtype& pubkey, pubkeys) BOOST_FOREACH(const valtype& pubkey, pubkeys)
@ -49,7 +47,7 @@ isminetype IsMine(const CKeyStore &keystore, const CTxDestination& dest, bool& i
isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey, bool& isInvalid, SigVersion sigversion) isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey, bool& isInvalid, SigVersion sigversion)
{ {
vector<valtype> vSolutions; std::vector<valtype> vSolutions;
txnouttype whichType; txnouttype whichType;
if (!Solver(scriptPubKey, whichType, vSolutions)) { if (!Solver(scriptPubKey, whichType, vSolutions)) {
if (keystore.HaveWatchOnly(scriptPubKey)) if (keystore.HaveWatchOnly(scriptPubKey))
@ -132,7 +130,7 @@ isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey, bool&
// partially owned (somebody else has a key that can spend // partially owned (somebody else has a key that can spend
// them) enable spend-out-from-under-you attacks, especially // them) enable spend-out-from-under-you attacks, especially
// in shared-wallet situations. // in shared-wallet situations.
vector<valtype> keys(vSolutions.begin()+1, vSolutions.begin()+vSolutions.size()-1); std::vector<valtype> keys(vSolutions.begin()+1, vSolutions.begin()+vSolutions.size()-1);
if (sigversion != SIGVERSION_BASE) { if (sigversion != SIGVERSION_BASE) {
for (size_t i = 0; i < keys.size(); i++) { for (size_t i = 0; i < keys.size(); i++) {
if (keys[i].size() != 33) { if (keys[i].size() != 33) {

@ -8,8 +8,6 @@
#include "tinyformat.h" #include "tinyformat.h"
#include "utilstrencodings.h" #include "utilstrencodings.h"
using namespace std;
const char* GetOpName(opcodetype opcode) const char* GetOpName(opcodetype opcode)
{ {
switch (opcode) switch (opcode)
@ -186,7 +184,7 @@ unsigned int CScript::GetSigOpCount(const CScript& scriptSig) const
// get the last item that the scriptSig // get the last item that the scriptSig
// pushes onto the stack: // pushes onto the stack:
const_iterator pc = scriptSig.begin(); const_iterator pc = scriptSig.begin();
vector<unsigned char> vData; std::vector<unsigned char> vData;
while (pc < scriptSig.end()) while (pc < scriptSig.end())
{ {
opcodetype opcode; opcodetype opcode;

@ -14,8 +14,6 @@
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
using namespace std;
typedef std::vector<unsigned char> valtype; typedef std::vector<unsigned char> valtype;
TransactionSignatureCreator::TransactionSignatureCreator(const CKeyStore* keystoreIn, const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : BaseSignatureCreator(keystoreIn), txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {} TransactionSignatureCreator::TransactionSignatureCreator(const CKeyStore* keystoreIn, const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : BaseSignatureCreator(keystoreIn), txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {}
@ -39,14 +37,14 @@ bool TransactionSignatureCreator::CreateSig(std::vector<unsigned char>& vchSig,
static bool Sign1(const CKeyID& address, const BaseSignatureCreator& creator, const CScript& scriptCode, std::vector<valtype>& ret, SigVersion sigversion) static bool Sign1(const CKeyID& address, const BaseSignatureCreator& creator, const CScript& scriptCode, std::vector<valtype>& ret, SigVersion sigversion)
{ {
vector<unsigned char> vchSig; std::vector<unsigned char> vchSig;
if (!creator.CreateSig(vchSig, address, scriptCode, sigversion)) if (!creator.CreateSig(vchSig, address, scriptCode, sigversion))
return false; return false;
ret.push_back(vchSig); ret.push_back(vchSig);
return true; return true;
} }
static bool SignN(const vector<valtype>& multisigdata, const BaseSignatureCreator& creator, const CScript& scriptCode, std::vector<valtype>& ret, SigVersion sigversion) static bool SignN(const std::vector<valtype>& multisigdata, const BaseSignatureCreator& creator, const CScript& scriptCode, std::vector<valtype>& ret, SigVersion sigversion)
{ {
int nSigned = 0; int nSigned = 0;
int nRequired = multisigdata.front()[0]; int nRequired = multisigdata.front()[0];
@ -73,7 +71,7 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP
uint160 h160; uint160 h160;
ret.clear(); ret.clear();
vector<valtype> vSolutions; std::vector<valtype> vSolutions;
if (!Solver(scriptPubKey, whichTypeRet, vSolutions)) if (!Solver(scriptPubKey, whichTypeRet, vSolutions))
return false; return false;
@ -125,7 +123,7 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP
} }
} }
static CScript PushAll(const vector<valtype>& values) static CScript PushAll(const std::vector<valtype>& values)
{ {
CScript result; CScript result;
BOOST_FOREACH(const valtype& v, values) { BOOST_FOREACH(const valtype& v, values) {
@ -228,12 +226,12 @@ bool SignSignature(const CKeyStore &keystore, const CTransaction& txFrom, CMutab
return SignSignature(keystore, txout.scriptPubKey, txTo, nIn, txout.nValue, nHashType); return SignSignature(keystore, txout.scriptPubKey, txTo, nIn, txout.nValue, nHashType);
} }
static vector<valtype> CombineMultisig(const CScript& scriptPubKey, const BaseSignatureChecker& checker, static std::vector<valtype> CombineMultisig(const CScript& scriptPubKey, const BaseSignatureChecker& checker,
const vector<valtype>& vSolutions, const std::vector<valtype>& vSolutions,
const vector<valtype>& sigs1, const vector<valtype>& sigs2, SigVersion sigversion) const std::vector<valtype>& sigs1, const std::vector<valtype>& sigs2, SigVersion sigversion)
{ {
// Combine all the signatures we've got: // Combine all the signatures we've got:
set<valtype> allsigs; std::set<valtype> allsigs;
BOOST_FOREACH(const valtype& v, sigs1) BOOST_FOREACH(const valtype& v, sigs1)
{ {
if (!v.empty()) if (!v.empty())
@ -249,7 +247,7 @@ static vector<valtype> CombineMultisig(const CScript& scriptPubKey, const BaseSi
assert(vSolutions.size() > 1); assert(vSolutions.size() > 1);
unsigned int nSigsRequired = vSolutions.front()[0]; unsigned int nSigsRequired = vSolutions.front()[0];
unsigned int nPubKeys = vSolutions.size()-2; unsigned int nPubKeys = vSolutions.size()-2;
map<valtype, valtype> sigs; std::map<valtype, valtype> sigs;
BOOST_FOREACH(const valtype& sig, allsigs) BOOST_FOREACH(const valtype& sig, allsigs)
{ {
for (unsigned int i = 0; i < nPubKeys; i++) for (unsigned int i = 0; i < nPubKeys; i++)
@ -306,7 +304,7 @@ struct Stacks
} }
static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignatureChecker& checker, static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignatureChecker& checker,
const txnouttype txType, const vector<valtype>& vSolutions, const txnouttype txType, const std::vector<valtype>& vSolutions,
Stacks sigs1, Stacks sigs2, SigVersion sigversion) Stacks sigs1, Stacks sigs2, SigVersion sigversion)
{ {
switch (txType) switch (txType)
@ -340,7 +338,7 @@ static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignature
CScript pubKey2(spk.begin(), spk.end()); CScript pubKey2(spk.begin(), spk.end());
txnouttype txType2; txnouttype txType2;
vector<vector<unsigned char> > vSolutions2; std::vector<std::vector<unsigned char> > vSolutions2;
Solver(pubKey2, txType2, vSolutions2); Solver(pubKey2, txType2, vSolutions2);
sigs1.script.pop_back(); sigs1.script.pop_back();
sigs2.script.pop_back(); sigs2.script.pop_back();
@ -360,7 +358,7 @@ static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignature
// Recur to combine: // Recur to combine:
CScript pubKey2(sigs1.witness.back().begin(), sigs1.witness.back().end()); CScript pubKey2(sigs1.witness.back().begin(), sigs1.witness.back().end());
txnouttype txType2; txnouttype txType2;
vector<valtype> vSolutions2; std::vector<valtype> vSolutions2;
Solver(pubKey2, txType2, vSolutions2); Solver(pubKey2, txType2, vSolutions2);
sigs1.witness.pop_back(); sigs1.witness.pop_back();
sigs1.script = sigs1.witness; sigs1.script = sigs1.witness;
@ -383,7 +381,7 @@ SignatureData CombineSignatures(const CScript& scriptPubKey, const BaseSignature
const SignatureData& scriptSig1, const SignatureData& scriptSig2) const SignatureData& scriptSig1, const SignatureData& scriptSig2)
{ {
txnouttype txType; txnouttype txType;
vector<vector<unsigned char> > vSolutions; std::vector<std::vector<unsigned char> > vSolutions;
Solver(scriptPubKey, txType, vSolutions); Solver(scriptPubKey, txType, vSolutions);
return CombineSignatures(scriptPubKey, checker, txType, vSolutions, Stacks(scriptSig1), Stacks(scriptSig2), SIGVERSION_BASE).Output(); return CombineSignatures(scriptPubKey, checker, txType, vSolutions, Stacks(scriptSig1), Stacks(scriptSig2), SIGVERSION_BASE).Output();

@ -12,9 +12,7 @@
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
using namespace std; typedef std::vector<unsigned char> valtype;
typedef vector<unsigned char> valtype;
bool fAcceptDatacarrier = DEFAULT_ACCEPT_DATACARRIER; bool fAcceptDatacarrier = DEFAULT_ACCEPT_DATACARRIER;
unsigned nMaxDatacarrierBytes = MAX_OP_RETURN_RELAY; unsigned nMaxDatacarrierBytes = MAX_OP_RETURN_RELAY;
@ -40,20 +38,20 @@ const char* GetTxnOutputType(txnouttype t)
/** /**
* Return public keys or hashes from scriptPubKey, for 'standard' transaction types. * Return public keys or hashes from scriptPubKey, for 'standard' transaction types.
*/ */
bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsigned char> >& vSolutionsRet) bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet)
{ {
// Templates // Templates
static multimap<txnouttype, CScript> mTemplates; static std::multimap<txnouttype, CScript> mTemplates;
if (mTemplates.empty()) if (mTemplates.empty())
{ {
// Standard tx, sender provides pubkey, receiver adds signature // Standard tx, sender provides pubkey, receiver adds signature
mTemplates.insert(make_pair(TX_PUBKEY, CScript() << OP_PUBKEY << OP_CHECKSIG)); mTemplates.insert(std::make_pair(TX_PUBKEY, CScript() << OP_PUBKEY << OP_CHECKSIG));
// Bitcoin address tx, sender provides hash of pubkey, receiver provides signature and pubkey // Bitcoin address tx, sender provides hash of pubkey, receiver provides signature and pubkey
mTemplates.insert(make_pair(TX_PUBKEYHASH, CScript() << OP_DUP << OP_HASH160 << OP_PUBKEYHASH << OP_EQUALVERIFY << OP_CHECKSIG)); mTemplates.insert(std::make_pair(TX_PUBKEYHASH, CScript() << OP_DUP << OP_HASH160 << OP_PUBKEYHASH << OP_EQUALVERIFY << OP_CHECKSIG));
// Sender provides N pubkeys, receivers provides M signatures // Sender provides N pubkeys, receivers provides M signatures
mTemplates.insert(make_pair(TX_MULTISIG, CScript() << OP_SMALLINTEGER << OP_PUBKEYS << OP_SMALLINTEGER << OP_CHECKMULTISIG)); mTemplates.insert(std::make_pair(TX_MULTISIG, CScript() << OP_SMALLINTEGER << OP_PUBKEYS << OP_SMALLINTEGER << OP_CHECKMULTISIG));
} }
vSolutionsRet.clear(); vSolutionsRet.clear();
@ -63,7 +61,7 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsi
if (scriptPubKey.IsPayToScriptHash()) if (scriptPubKey.IsPayToScriptHash())
{ {
typeRet = TX_SCRIPTHASH; typeRet = TX_SCRIPTHASH;
vector<unsigned char> hashBytes(scriptPubKey.begin()+2, scriptPubKey.begin()+22); std::vector<unsigned char> hashBytes(scriptPubKey.begin()+2, scriptPubKey.begin()+22);
vSolutionsRet.push_back(hashBytes); vSolutionsRet.push_back(hashBytes);
return true; return true;
} }
@ -102,7 +100,7 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsi
vSolutionsRet.clear(); vSolutionsRet.clear();
opcodetype opcode1, opcode2; opcodetype opcode1, opcode2;
vector<unsigned char> vch1, vch2; std::vector<unsigned char> vch1, vch2;
// Compare // Compare
CScript::const_iterator pc1 = script1.begin(); CScript::const_iterator pc1 = script1.begin();
@ -181,7 +179,7 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsi
bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet) bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
{ {
vector<valtype> vSolutions; std::vector<valtype> vSolutions;
txnouttype whichType; txnouttype whichType;
if (!Solver(scriptPubKey, whichType, vSolutions)) if (!Solver(scriptPubKey, whichType, vSolutions))
return false; return false;
@ -209,11 +207,11 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
return false; return false;
} }
bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, vector<CTxDestination>& addressRet, int& nRequiredRet) bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet)
{ {
addressRet.clear(); addressRet.clear();
typeRet = TX_NONSTANDARD; typeRet = TX_NONSTANDARD;
vector<valtype> vSolutions; std::vector<valtype> vSolutions;
if (!Solver(scriptPubKey, typeRet, vSolutions)) if (!Solver(scriptPubKey, typeRet, vSolutions))
return false; return false;
if (typeRet == TX_NULL_DATA){ if (typeRet == TX_NULL_DATA){

Loading…
Cancel
Save