MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / FormatScript

Function FormatScript

src/core_io.cpp:296–330  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

294}
295
296std::string FormatScript(const CScript& script)
297{
298 std::string ret;
299 CScript::const_iterator it = script.begin();
300 opcodetype op;
301 while (it != script.end()) {
302 CScript::const_iterator it2 = it;
303 std::vector<unsigned char> vch;
304 if (script.GetOp(it, op, vch)) {
305 if (op == OP_0) {
306 ret += "0 ";
307 continue;
308 } else if ((op >= OP_1 && op <= OP_16) || op == OP_1NEGATE) {
309 ret += strprintf("%i ", op - OP_1NEGATE - 1);
310 continue;
311 } else if (op >= OP_NOP && op <= OP_NOP10) {
312 std::string str(GetOpName(op));
313 if (str.substr(0, 3) == std::string("OP_")) {
314 ret += str.substr(3, std::string::npos) + " ";
315 continue;
316 }
317 }
318 if (vch.size() > 0) {
319 ret += strprintf("0x%x 0x%x ", HexStr(std::vector<uint8_t>(it2, it - vch.size())),
320 HexStr(std::vector<uint8_t>(it - vch.size(), it)));
321 } else {
322 ret += strprintf("0x%x ", HexStr(std::vector<uint8_t>(it2, it)));
323 }
324 continue;
325 }
326 ret += strprintf("0x%x ", HexStr(std::vector<uint8_t>(it2, script.end())));
327 break;
328 }
329 return ret.substr(0, ret.empty() ? ret.npos : ret.size() - 1);
330}
331
332const std::map<unsigned char, std::string> mapSigHashTypes = {
333 {static_cast<unsigned char>(SIGHASH_ALL), std::string("ALL")},

Callers 2

GetJSONMethod · 0.85
script_format.cppFile · 0.85

Calls 7

GetOpNameFunction · 0.85
GetOpMethod · 0.80
HexStrFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by 1

GetJSONMethod · 0.68