Changeset View
Changeset View
Standalone View
Standalone View
src/script/script.cpp
Show First 20 Lines • Show All 262 Lines • ▼ Show 20 Lines | switch (opcode) { | ||||
return "OP_UNKNOWN"; | return "OP_UNKNOWN"; | ||||
} | } | ||||
} | } | ||||
std::vector<uint8_t> | std::vector<uint8_t> | ||||
MinimalizeBigEndianArray(const std::vector<uint8_t> &data) { | MinimalizeBigEndianArray(const std::vector<uint8_t> &data) { | ||||
std::vector<uint8_t> res; | std::vector<uint8_t> res; | ||||
// Can't encode more than this, go ahead and grab as much room as we could | |||||
// possibly need | |||||
res.reserve(data.size()); | |||||
// Ensure we have a byte to work with. | // Ensure we have a byte to work with. | ||||
if (data.size() == 0) { | if (data.size() == 0) { | ||||
return res; | return res; | ||||
} | } | ||||
// Check for a negative bit | // Store the MSB | ||||
uint8_t msb = data[0] & 0x80; | uint8_t neg = data[0] & 0x80; | ||||
bool start = false; | bool havePushed = false; | ||||
for (size_t i = 0; i < data.size(); ++i) { | for (size_t i = 0; i < data.size(); ++i) { | ||||
uint8_t x = data[i]; | uint8_t x = data[i]; | ||||
if (i == 0 && (x & 0x7f) == 0) { | |||||
continue; | // Remove any MSB that might exist | ||||
if (i == 0) { | |||||
x &= 0x7f; | |||||
} | } | ||||
if (!start && x == 0) { | |||||
// If we haven't pushed anything, and the current value is zero, keep | |||||
// ignoring bytes. | |||||
if (!havePushed && x == 0) { | |||||
continue; | continue; | ||||
} | } | ||||
start = true; | |||||
// Record that we have begun pushing, and store the current value. | |||||
havePushed = true; | |||||
res.push_back(x); | res.push_back(x); | ||||
} | } | ||||
if (res.size() != 0) { | // Give us at least one byte | ||||
res[0] |= msb; | if (res.size() == 0) { | ||||
res.push_back(0); | |||||
} | |||||
// Only add back the sign if a value has been pushed. This implies the | |||||
// result is non-zero. | |||||
if (havePushed) { | |||||
// If the MSB is currently occupied, we need one extra byte. | |||||
if ((res[0] & 0x80) != 0) { | |||||
res.insert(res.begin(), 0); | |||||
} | |||||
res[0] |= neg; | |||||
} | } | ||||
return res; | return res; | ||||
} | } | ||||
unsigned int CScript::GetSigOpCount(bool fAccurate) const { | unsigned int CScript::GetSigOpCount(bool fAccurate) const { | ||||
unsigned int n = 0; | unsigned int n = 0; | ||||
const_iterator pc = begin(); | const_iterator pc = begin(); | ||||
▲ Show 20 Lines • Show All 109 Lines • Show Last 20 Lines |