* Create the assembly string representation of a CScript object. * @param[in] script CScript object to convert into the asm string representation. * @param[in] fAttemptSighashDecode Whether to attempt to decode sighash types on data within the script that matches the format * of a signature. Only pass true for scripts you believe could contain signature
| 91 | * pass false, or omit the this argument (defaults to false), for scriptPubKeys. |
| 92 | */ |
| 93 | std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode) |
| 94 | { |
| 95 | std::string str; |
| 96 | opcodetype opcode; |
| 97 | std::vector<unsigned char> vch; |
| 98 | CScript::const_iterator pc = script.begin(); |
| 99 | while (pc < script.end()) { |
| 100 | if (!str.empty()) { |
| 101 | str += " "; |
| 102 | } |
| 103 | if (!script.GetOp(pc, opcode, vch)) { |
| 104 | str += "[error]"; |
| 105 | return str; |
| 106 | } |
| 107 | if (0 <= opcode && opcode <= OP_PUSHDATA4) { |
| 108 | if (vch.size() <= static_cast<std::vector<unsigned char>::size_type>(4)) { |
| 109 | str += strprintf("%d", CScriptNum(vch, false).getint()); |
| 110 | } else { |
| 111 | // the IsUnspendable check makes sure not to try to decode OP_RETURN data that may match the format of a signature |
| 112 | if (fAttemptSighashDecode && !script.IsUnspendable()) { |
| 113 | std::string strSigHashDecode; |
| 114 | // goal: only attempt to decode a defined sighash type from data that looks like a signature within a scriptSig. |
| 115 | // this won't decode correctly formatted public keys in Pubkey or Multisig scripts due to |
| 116 | // the restrictions on the pubkey formats (see IsCompressedOrUncompressedPubKey) being incongruous with the |
| 117 | // checks in CheckSignatureEncoding. |
| 118 | if (CheckSignatureEncoding(vch, SCRIPT_VERIFY_STRICTENC | SCRIPT_FORKID_DISABLED, nullptr)) { |
| 119 | const unsigned char chSigHashType = vch.back(); |
| 120 | if (mapSigHashTypes.count(chSigHashType)) { |
| 121 | strSigHashDecode = "[" + mapSigHashTypes.find(chSigHashType)->second + "]"; |
| 122 | vch.pop_back(); // remove the sighash type byte. it will be replaced by the decode. |
| 123 | } |
| 124 | } |
| 125 | str += HexStr(vch) + strSigHashDecode; |
| 126 | } else { |
| 127 | str += HexStr(vch); |
| 128 | } |
| 129 | } |
| 130 | } else { |
| 131 | str += GetOpName(opcode); |
| 132 | } |
| 133 | } |
| 134 | return str; |
| 135 | } |
| 136 | |
| 137 | std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags) |
| 138 | { |