Skip to content

Commit 8cbfc4e

Browse files
committed
Refactor: Remove using namespace <xxx> from script/
1 parent f3c264e commit 8cbfc4e

File tree

5 files changed

+41
-51
lines changed

5 files changed

+41
-51
lines changed

src/script/interpreter.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
#include "script/script.h"
1414
#include "uint256.h"
1515

16-
using namespace std;
17-
18-
typedef vector<unsigned char> valtype;
16+
typedef std::vector<unsigned char> valtype;
1917

2018
namespace {
2119

@@ -56,10 +54,10 @@ bool CastToBool(const valtype& vch)
5654
*/
5755
#define stacktop(i) (stack.at(stack.size()+(i)))
5856
#define altstacktop(i) (altstack.at(altstack.size()+(i)))
59-
static inline void popstack(vector<valtype>& stack)
57+
static inline void popstack(std::vector<valtype>& stack)
6058
{
6159
if (stack.empty())
62-
throw runtime_error("popstack(): stack empty");
60+
throw std::runtime_error("popstack(): stack empty");
6361
stack.pop_back();
6462
}
6563

@@ -194,7 +192,7 @@ bool static IsDefinedHashtypeSignature(const valtype &vchSig) {
194192
return true;
195193
}
196194

197-
bool CheckSignatureEncoding(const vector<unsigned char> &vchSig, unsigned int flags, ScriptError* serror) {
195+
bool CheckSignatureEncoding(const std::vector<unsigned char> &vchSig, unsigned int flags, ScriptError* serror) {
198196
// Empty signature. Not strictly DER encoded, but allowed to provide a
199197
// compact way to provide an invalid signature for use with CHECK(MULTI)SIG
200198
if (vchSig.size() == 0) {
@@ -245,7 +243,7 @@ bool static CheckMinimalPush(const valtype& data, opcodetype opcode) {
245243
return true;
246244
}
247245

248-
bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* serror)
246+
bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* serror)
249247
{
250248
static const CScriptNum bnZero(0);
251249
static const CScriptNum bnOne(1);
@@ -260,8 +258,8 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, un
260258
CScript::const_iterator pbegincodehash = script.begin();
261259
opcodetype opcode;
262260
valtype vchPushValue;
263-
vector<bool> vfExec;
264-
vector<valtype> altstack;
261+
std::vector<bool> vfExec;
262+
std::vector<valtype> altstack;
265263
set_error(serror, SCRIPT_ERR_UNKNOWN_ERROR);
266264
if (script.size() > MAX_SCRIPT_SIZE)
267265
return set_error(serror, SCRIPT_ERR_SCRIPT_SIZE);
@@ -1250,14 +1248,14 @@ bool TransactionSignatureChecker::VerifySignature(const std::vector<unsigned cha
12501248
return pubkey.Verify(sighash, vchSig);
12511249
}
12521250

1253-
bool TransactionSignatureChecker::CheckSig(const vector<unsigned char>& vchSigIn, const vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const
1251+
bool TransactionSignatureChecker::CheckSig(const std::vector<unsigned char>& vchSigIn, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const
12541252
{
12551253
CPubKey pubkey(vchPubKey);
12561254
if (!pubkey.IsValid())
12571255
return false;
12581256

12591257
// Hash type is one byte tacked on to the end of the signature
1260-
vector<unsigned char> vchSig(vchSigIn);
1258+
std::vector<unsigned char> vchSig(vchSigIn);
12611259
if (vchSig.empty())
12621260
return false;
12631261
int nHashType = vchSig.back();
@@ -1355,7 +1353,7 @@ bool TransactionSignatureChecker::CheckSequence(const CScriptNum& nSequence) con
13551353

13561354
static bool VerifyWitnessProgram(const CScriptWitness& witness, int witversion, const std::vector<unsigned char>& program, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* serror)
13571355
{
1358-
vector<vector<unsigned char> > stack;
1356+
std::vector<std::vector<unsigned char> > stack;
13591357
CScript scriptPubKey;
13601358

13611359
if (witversion == 0) {
@@ -1420,7 +1418,7 @@ bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const C
14201418
return set_error(serror, SCRIPT_ERR_SIG_PUSHONLY);
14211419
}
14221420

1423-
vector<vector<unsigned char> > stack, stackCopy;
1421+
std::vector<std::vector<unsigned char> > stack, stackCopy;
14241422
if (!EvalScript(stack, scriptSig, flags, checker, SIGVERSION_BASE, serror))
14251423
// serror is set
14261424
return false;
@@ -1558,7 +1556,7 @@ size_t CountWitnessSigOps(const CScript& scriptSig, const CScript& scriptPubKey,
15581556

15591557
if (scriptPubKey.IsPayToScriptHash() && scriptSig.IsPushOnly()) {
15601558
CScript::const_iterator pc = scriptSig.begin();
1561-
vector<unsigned char> data;
1559+
std::vector<unsigned char> data;
15621560
while (pc < scriptSig.end()) {
15631561
opcodetype opcode;
15641562
scriptSig.GetOp(pc, opcode, data);

src/script/ismine.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313

1414
#include <boost/foreach.hpp>
1515

16-
using namespace std;
16+
typedef std::vector<unsigned char> valtype;
1717

18-
typedef vector<unsigned char> valtype;
19-
20-
unsigned int HaveKeys(const vector<valtype>& pubkeys, const CKeyStore& keystore)
18+
unsigned int HaveKeys(const std::vector<valtype>& pubkeys, const CKeyStore& keystore)
2119
{
2220
unsigned int nResult = 0;
2321
BOOST_FOREACH(const valtype& pubkey, pubkeys)
@@ -49,7 +47,7 @@ isminetype IsMine(const CKeyStore &keystore, const CTxDestination& dest, bool& i
4947

5048
isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey, bool& isInvalid, SigVersion sigversion)
5149
{
52-
vector<valtype> vSolutions;
50+
std::vector<valtype> vSolutions;
5351
txnouttype whichType;
5452
if (!Solver(scriptPubKey, whichType, vSolutions)) {
5553
if (keystore.HaveWatchOnly(scriptPubKey))
@@ -132,7 +130,7 @@ isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey, bool&
132130
// partially owned (somebody else has a key that can spend
133131
// them) enable spend-out-from-under-you attacks, especially
134132
// in shared-wallet situations.
135-
vector<valtype> keys(vSolutions.begin()+1, vSolutions.begin()+vSolutions.size()-1);
133+
std::vector<valtype> keys(vSolutions.begin()+1, vSolutions.begin()+vSolutions.size()-1);
136134
if (sigversion != SIGVERSION_BASE) {
137135
for (size_t i = 0; i < keys.size(); i++) {
138136
if (keys[i].size() != 33) {

src/script/script.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include "tinyformat.h"
99
#include "utilstrencodings.h"
1010

11-
using namespace std;
12-
1311
const char* GetOpName(opcodetype opcode)
1412
{
1513
switch (opcode)
@@ -186,7 +184,7 @@ unsigned int CScript::GetSigOpCount(const CScript& scriptSig) const
186184
// get the last item that the scriptSig
187185
// pushes onto the stack:
188186
const_iterator pc = scriptSig.begin();
189-
vector<unsigned char> vData;
187+
std::vector<unsigned char> vData;
190188
while (pc < scriptSig.end())
191189
{
192190
opcodetype opcode;

src/script/sign.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
#include <boost/foreach.hpp>
1616

17-
using namespace std;
18-
1917
typedef std::vector<unsigned char> valtype;
2018

2119
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,
3937

4038
static bool Sign1(const CKeyID& address, const BaseSignatureCreator& creator, const CScript& scriptCode, std::vector<valtype>& ret, SigVersion sigversion)
4139
{
42-
vector<unsigned char> vchSig;
40+
std::vector<unsigned char> vchSig;
4341
if (!creator.CreateSig(vchSig, address, scriptCode, sigversion))
4442
return false;
4543
ret.push_back(vchSig);
4644
return true;
4745
}
4846

49-
static bool SignN(const vector<valtype>& multisigdata, const BaseSignatureCreator& creator, const CScript& scriptCode, std::vector<valtype>& ret, SigVersion sigversion)
47+
static bool SignN(const std::vector<valtype>& multisigdata, const BaseSignatureCreator& creator, const CScript& scriptCode, std::vector<valtype>& ret, SigVersion sigversion)
5048
{
5149
int nSigned = 0;
5250
int nRequired = multisigdata.front()[0];
@@ -73,7 +71,7 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP
7371
uint160 h160;
7472
ret.clear();
7573

76-
vector<valtype> vSolutions;
74+
std::vector<valtype> vSolutions;
7775
if (!Solver(scriptPubKey, whichTypeRet, vSolutions))
7876
return false;
7977

@@ -125,7 +123,7 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP
125123
}
126124
}
127125

128-
static CScript PushAll(const vector<valtype>& values)
126+
static CScript PushAll(const std::vector<valtype>& values)
129127
{
130128
CScript result;
131129
BOOST_FOREACH(const valtype& v, values) {
@@ -228,12 +226,12 @@ bool SignSignature(const CKeyStore &keystore, const CTransaction& txFrom, CMutab
228226
return SignSignature(keystore, txout.scriptPubKey, txTo, nIn, txout.nValue, nHashType);
229227
}
230228

231-
static vector<valtype> CombineMultisig(const CScript& scriptPubKey, const BaseSignatureChecker& checker,
232-
const vector<valtype>& vSolutions,
233-
const vector<valtype>& sigs1, const vector<valtype>& sigs2, SigVersion sigversion)
229+
static std::vector<valtype> CombineMultisig(const CScript& scriptPubKey, const BaseSignatureChecker& checker,
230+
const std::vector<valtype>& vSolutions,
231+
const std::vector<valtype>& sigs1, const std::vector<valtype>& sigs2, SigVersion sigversion)
234232
{
235233
// Combine all the signatures we've got:
236-
set<valtype> allsigs;
234+
std::set<valtype> allsigs;
237235
BOOST_FOREACH(const valtype& v, sigs1)
238236
{
239237
if (!v.empty())
@@ -249,7 +247,7 @@ static vector<valtype> CombineMultisig(const CScript& scriptPubKey, const BaseSi
249247
assert(vSolutions.size() > 1);
250248
unsigned int nSigsRequired = vSolutions.front()[0];
251249
unsigned int nPubKeys = vSolutions.size()-2;
252-
map<valtype, valtype> sigs;
250+
std::map<valtype, valtype> sigs;
253251
BOOST_FOREACH(const valtype& sig, allsigs)
254252
{
255253
for (unsigned int i = 0; i < nPubKeys; i++)
@@ -306,7 +304,7 @@ struct Stacks
306304
}
307305

308306
static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignatureChecker& checker,
309-
const txnouttype txType, const vector<valtype>& vSolutions,
307+
const txnouttype txType, const std::vector<valtype>& vSolutions,
310308
Stacks sigs1, Stacks sigs2, SigVersion sigversion)
311309
{
312310
switch (txType)
@@ -340,7 +338,7 @@ static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignature
340338
CScript pubKey2(spk.begin(), spk.end());
341339

342340
txnouttype txType2;
343-
vector<vector<unsigned char> > vSolutions2;
341+
std::vector<std::vector<unsigned char> > vSolutions2;
344342
Solver(pubKey2, txType2, vSolutions2);
345343
sigs1.script.pop_back();
346344
sigs2.script.pop_back();
@@ -360,7 +358,7 @@ static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignature
360358
// Recur to combine:
361359
CScript pubKey2(sigs1.witness.back().begin(), sigs1.witness.back().end());
362360
txnouttype txType2;
363-
vector<valtype> vSolutions2;
361+
std::vector<valtype> vSolutions2;
364362
Solver(pubKey2, txType2, vSolutions2);
365363
sigs1.witness.pop_back();
366364
sigs1.script = sigs1.witness;
@@ -383,7 +381,7 @@ SignatureData CombineSignatures(const CScript& scriptPubKey, const BaseSignature
383381
const SignatureData& scriptSig1, const SignatureData& scriptSig2)
384382
{
385383
txnouttype txType;
386-
vector<vector<unsigned char> > vSolutions;
384+
std::vector<std::vector<unsigned char> > vSolutions;
387385
Solver(scriptPubKey, txType, vSolutions);
388386

389387
return CombineSignatures(scriptPubKey, checker, txType, vSolutions, Stacks(scriptSig1), Stacks(scriptSig2), SIGVERSION_BASE).Output();

src/script/standard.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212

1313
#include <boost/foreach.hpp>
1414

15-
using namespace std;
16-
17-
typedef vector<unsigned char> valtype;
15+
typedef std::vector<unsigned char> valtype;
1816

1917
bool fAcceptDatacarrier = DEFAULT_ACCEPT_DATACARRIER;
2018
unsigned nMaxDatacarrierBytes = MAX_OP_RETURN_RELAY;
@@ -40,20 +38,20 @@ const char* GetTxnOutputType(txnouttype t)
4038
/**
4139
* Return public keys or hashes from scriptPubKey, for 'standard' transaction types.
4240
*/
43-
bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsigned char> >& vSolutionsRet)
41+
bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet)
4442
{
4543
// Templates
46-
static multimap<txnouttype, CScript> mTemplates;
44+
static std::multimap<txnouttype, CScript> mTemplates;
4745
if (mTemplates.empty())
4846
{
4947
// Standard tx, sender provides pubkey, receiver adds signature
50-
mTemplates.insert(make_pair(TX_PUBKEY, CScript() << OP_PUBKEY << OP_CHECKSIG));
48+
mTemplates.insert(std::make_pair(TX_PUBKEY, CScript() << OP_PUBKEY << OP_CHECKSIG));
5149

5250
// Bitcoin address tx, sender provides hash of pubkey, receiver provides signature and pubkey
53-
mTemplates.insert(make_pair(TX_PUBKEYHASH, CScript() << OP_DUP << OP_HASH160 << OP_PUBKEYHASH << OP_EQUALVERIFY << OP_CHECKSIG));
51+
mTemplates.insert(std::make_pair(TX_PUBKEYHASH, CScript() << OP_DUP << OP_HASH160 << OP_PUBKEYHASH << OP_EQUALVERIFY << OP_CHECKSIG));
5452

5553
// Sender provides N pubkeys, receivers provides M signatures
56-
mTemplates.insert(make_pair(TX_MULTISIG, CScript() << OP_SMALLINTEGER << OP_PUBKEYS << OP_SMALLINTEGER << OP_CHECKMULTISIG));
54+
mTemplates.insert(std::make_pair(TX_MULTISIG, CScript() << OP_SMALLINTEGER << OP_PUBKEYS << OP_SMALLINTEGER << OP_CHECKMULTISIG));
5755
}
5856

5957
vSolutionsRet.clear();
@@ -63,7 +61,7 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsi
6361
if (scriptPubKey.IsPayToScriptHash())
6462
{
6563
typeRet = TX_SCRIPTHASH;
66-
vector<unsigned char> hashBytes(scriptPubKey.begin()+2, scriptPubKey.begin()+22);
64+
std::vector<unsigned char> hashBytes(scriptPubKey.begin()+2, scriptPubKey.begin()+22);
6765
vSolutionsRet.push_back(hashBytes);
6866
return true;
6967
}
@@ -102,7 +100,7 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsi
102100
vSolutionsRet.clear();
103101

104102
opcodetype opcode1, opcode2;
105-
vector<unsigned char> vch1, vch2;
103+
std::vector<unsigned char> vch1, vch2;
106104

107105
// Compare
108106
CScript::const_iterator pc1 = script1.begin();
@@ -181,7 +179,7 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsi
181179

182180
bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
183181
{
184-
vector<valtype> vSolutions;
182+
std::vector<valtype> vSolutions;
185183
txnouttype whichType;
186184
if (!Solver(scriptPubKey, whichType, vSolutions))
187185
return false;
@@ -209,11 +207,11 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
209207
return false;
210208
}
211209

212-
bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, vector<CTxDestination>& addressRet, int& nRequiredRet)
210+
bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet)
213211
{
214212
addressRet.clear();
215213
typeRet = TX_NONSTANDARD;
216-
vector<valtype> vSolutions;
214+
std::vector<valtype> vSolutions;
217215
if (!Solver(scriptPubKey, typeRet, vSolutions))
218216
return false;
219217
if (typeRet == TX_NULL_DATA){

0 commit comments

Comments
 (0)