MCPcopy Create free account
hub / github.com/ElementsProject/elements / ScriptToAsmStr

Function ScriptToAsmStr

src/core_write.cpp:123–166  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

121 * pass false, or omit the this argument (defaults to false), for scriptPubKeys.
122 */
123std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode)
124{
125 std::string str;
126 opcodetype opcode;
127 std::vector<unsigned char> vch;
128 CScript::const_iterator pc = script.begin();
129 while (pc < script.end()) {
130 if (!str.empty()) {
131 str += " ";
132 }
133 if (!script.GetOp(pc, opcode, vch)) {
134 str += "[error]";
135 return str;
136 }
137 if (0 <= opcode && opcode <= OP_PUSHDATA4) {
138 if (vch.size() <= static_cast<std::vector<unsigned char>::size_type>(4)) {
139 str += strprintf("%d", CScriptNum(vch, false).getint());
140 } else {
141 // the IsUnspendable check makes sure not to try to decode OP_RETURN data that may match the format of a signature
142 if (fAttemptSighashDecode && !script.IsUnspendable()) {
143 std::string strSigHashDecode;
144 // goal: only attempt to decode a defined sighash type from data that looks like a signature within a scriptSig.
145 // this won't decode correctly formatted public keys in Pubkey or Multisig scripts due to
146 // the restrictions on the pubkey formats (see IsCompressedOrUncompressedPubKey) being incongruous with the
147 // checks in CheckSignatureEncoding.
148 if (CheckSignatureEncoding(vch, SCRIPT_VERIFY_STRICTENC, nullptr)) {
149 const unsigned char chSigHashType = vch.back();
150 const auto it = mapSigHashTypes.find(chSigHashType);
151 if (it != mapSigHashTypes.end()) {
152 strSigHashDecode = "[" + it->second + "]";
153 vch.pop_back(); // remove the sighash type byte. it will be replaced by the decode.
154 }
155 }
156 str += HexStr(vch) + strSigHashDecode;
157 } else {
158 str += HexStr(vch);
159 }
160 }
161 } else {
162 str += GetOpName(opcode);
163 }
164 }
165 return str;
166}
167
168std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags)
169{

Callers 10

TxToUnivFunction · 0.85
MutateTxSignFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
FUZZ_TARGET_INITFunction · 0.85
decodepsbtFunction · 0.85
ParsePrevoutsFunction · 0.85
blockheaderToJSONFunction · 0.85
getblockchaininfoFunction · 0.85
getsidechaininfoFunction · 0.85

Calls 13

CheckSignatureEncodingFunction · 0.85
GetOpNameFunction · 0.85
GetOpMethod · 0.80
IsUnspendableMethod · 0.80
findMethod · 0.80
CScriptNumClass · 0.50
HexStrFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
getintMethod · 0.45

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.68
FUZZ_TARGET_INITFunction · 0.68