| 22 | #include <univalue.h> |
| 23 | |
| 24 | std::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 | |
| 71 | const std::map<uint8_t, std::string> mapSigHashTypes = { |
| 72 | {SIGHASH_ALL, "ALL"}, |