MCPcopy Create free account
hub / github.com/Bitcoin-ABC/bitcoin-abc / FormatScript

Function FormatScript

src/core_write.cpp:24–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22#include <univalue.h>
23
24std::string FormatScript(const CScript &script) {
25 std::string ret;
26 CScript::const_iterator it = script.begin();
27 opcodetype op;
28 while (it != script.end()) {
29 CScript::const_iterator it2 = it;
30 std::vector<uint8_t> vch;
31 if (script.GetOp(it, op, vch)) {
32 if (op == OP_0) {
33 ret += "0 ";
34 continue;
35 }
36
37 if ((op >= OP_1 && op <= OP_16) || op == OP_1NEGATE) {
38 ret += strprintf("%i ", op - OP_1NEGATE - 1);
39 continue;
40 }
41
42 if (op >= OP_NOP && op < FIRST_UNDEFINED_OP_VALUE) {
43 std::string str(GetOpName(op));
44 if (str.substr(0, 3) == std::string("OP_")) {
45 ret += str.substr(3, std::string::npos) + " ";
46 continue;
47 }
48 }
49
50 if (vch.size() > 0) {
51 ret += strprintf(
52 "0x%x 0x%x ",
53 HexStr(std::vector<uint8_t>(it2, it - vch.size())),
54 HexStr(std::vector<uint8_t>(it - vch.size(), it)));
55 } else {
56 ret +=
57 strprintf("0x%x ", HexStr(std::vector<uint8_t>(it2, it)));
58 }
59
60 continue;
61 }
62
63 ret +=
64 strprintf("0x%x ", HexStr(std::vector<uint8_t>(it2, script.end())));
65 break;
66 }
67
68 return ret.substr(0, ret.size() - 1);
69}
70
71const std::map<uint8_t, std::string> mapSigHashTypes = {
72 {SIGHASH_ALL, "ALL"},

Callers 5

GetJSONMethod · 0.85
TestFormatRoundTripFunction · 0.85
FUZZ_TARGET_INITFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 6

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

Tested by 5

GetJSONMethod · 0.68
TestFormatRoundTripFunction · 0.68
FUZZ_TARGET_INITFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68