@@ -26,20 +26,20 @@ opcodetype ParseOpCode(const std::string& s)
26
26
{
27
27
static std::map<std::string, opcodetype> mapOpNames;
28
28
29
- if (mapOpNames.empty ())
30
- {
31
- for (unsigned int op = 0 ; op <= MAX_OPCODE; op++)
32
- {
29
+ if (mapOpNames.empty ()) {
30
+ for (unsigned int op = 0 ; op <= MAX_OPCODE; op++) {
33
31
// Allow OP_RESERVED to get into mapOpNames
34
- if (op < OP_NOP && op != OP_RESERVED)
32
+ if (op < OP_NOP && op != OP_RESERVED) {
35
33
continue ;
34
+ }
36
35
37
36
std::string strName = GetOpName (static_cast <opcodetype>(op));
38
- if (strName == " OP_UNKNOWN" )
37
+ if (strName == " OP_UNKNOWN" ) {
39
38
continue ;
39
+ }
40
40
mapOpNames[strName] = static_cast <opcodetype>(op);
41
41
// Convenience: OP_ADD and just ADD are both recognized:
42
- if (strName.compare (0 , 3 , " OP_" ) == 0 ) { // strName starts with "OP_"
42
+ if (strName.compare (0 , 3 , " OP_" ) == 0 ) { // strName starts with "OP_"
43
43
mapOpNames[strName.substr (3 )] = static_cast <opcodetype>(op);
44
44
}
45
45
}
@@ -59,42 +59,33 @@ CScript ParseScript(const std::string& s)
59
59
std::vector<std::string> words;
60
60
boost::algorithm::split (words, s, boost::algorithm::is_any_of (" \t\n " ), boost::algorithm::token_compress_on);
61
61
62
- for (const std::string& w : words)
63
- {
64
- if (w.empty ())
65
- {
62
+ for (const std::string& w : words) {
63
+ if (w.empty ()) {
66
64
// Empty string, ignore. (boost::split given '' will return one word)
67
- }
68
- else if (std::all_of (w.begin (), w.end (), ::IsDigit) ||
69
- (w.front () == ' -' && w.size () > 1 && std::all_of (w.begin ()+1 , w.end (), ::IsDigit)))
65
+ } else if (std::all_of (w.begin (), w.end (), ::IsDigit) ||
66
+ (w.front () == ' -' && w.size () > 1 && std::all_of (w.begin () + 1 , w.end (), ::IsDigit)))
70
67
{
71
68
// Number
72
69
int64_t n = LocaleIndependentAtoi<int64_t >(w);
73
70
74
- // limit the range of numbers ParseScript accepts in decimal
75
- // since numbers outside -0xFFFFFFFF...0xFFFFFFFF are illegal in scripts
71
+ // limit the range of numbers ParseScript accepts in decimal
72
+ // since numbers outside -0xFFFFFFFF...0xFFFFFFFF are illegal in scripts
76
73
if (n > int64_t {0xffffffff } || n < -1 * int64_t {0xffffffff }) {
77
74
throw std::runtime_error (" script parse error: decimal numeric value only allowed in the "
78
75
" range -0xFFFFFFFF...0xFFFFFFFF" );
79
76
}
80
77
81
78
result << n;
82
- }
83
- else if (w.substr (0 ,2 ) == " 0x" && w.size () > 2 && IsHex (std::string (w.begin ()+2 , w.end ())))
84
- {
79
+ } else if (w.substr (0 , 2 ) == " 0x" && w.size () > 2 && IsHex (std::string (w.begin () + 2 , w.end ()))) {
85
80
// Raw hex data, inserted NOT pushed onto stack:
86
- std::vector<unsigned char > raw = ParseHex (std::string (w.begin ()+ 2 , w.end ()));
81
+ std::vector<unsigned char > raw = ParseHex (std::string (w.begin () + 2 , w.end ()));
87
82
result.insert (result.end (), raw.begin (), raw.end ());
88
- }
89
- else if (w.size () >= 2 && w.front () == ' \' ' && w.back () == ' \' ' )
90
- {
83
+ } else if (w.size () >= 2 && w.front () == ' \' ' && w.back () == ' \' ' ) {
91
84
// Single-quoted string, pushed as data. NOTE: this is poor-man's
92
85
// parsing, spaces/tabs/newlines in single-quoted strings won't work.
93
- std::vector<unsigned char > value (w.begin ()+ 1 , w.end ()- 1 );
86
+ std::vector<unsigned char > value (w.begin () + 1 , w.end () - 1 );
94
87
result << value;
95
- }
96
- else
97
- {
88
+ } else {
98
89
// opcode, e.g. OP_ADD or ADD:
99
90
result << ParseOpCode (w);
100
91
}
0 commit comments