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

Function ScriptToAsmStr

src/core_io.cpp:355–398  ·  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

353 * pass false, or omit the this argument (defaults to false), for scriptPubKeys.
354 */
355std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode)
356{
357 std::string str;
358 opcodetype opcode;
359 std::vector<unsigned char> vch;
360 CScript::const_iterator pc = script.begin();
361 while (pc < script.end()) {
362 if (!str.empty()) {
363 str += " ";
364 }
365 if (!script.GetOp(pc, opcode, vch)) {
366 str += "[error]";
367 return str;
368 }
369 if (0 <= opcode && opcode <= OP_PUSHDATA4) {
370 if (vch.size() <= static_cast<std::vector<unsigned char>::size_type>(4)) {
371 str += strprintf("%d", CScriptNum(vch, false).getint());
372 } else {
373 // the IsUnspendable check makes sure not to try to decode OP_RETURN data that may match the format of a signature
374 if (fAttemptSighashDecode && !script.IsUnspendable()) {
375 std::string strSigHashDecode;
376 // goal: only attempt to decode a defined sighash type from data that looks like a signature within a scriptSig.
377 // this won't decode correctly formatted public keys in Pubkey or Multisig scripts due to
378 // the restrictions on the pubkey formats (see IsCompressedOrUncompressedPubKey) being incongruous with the
379 // checks in CheckSignatureEncoding.
380 if (CheckSignatureEncoding(vch, SCRIPT_VERIFY_STRICTENC, nullptr)) {
381 const unsigned char chSigHashType = vch.back();
382 const auto it = mapSigHashTypes.find(chSigHashType);
383 if (it != mapSigHashTypes.end()) {
384 strSigHashDecode = "[" + it->second + "]";
385 vch.pop_back(); // remove the sighash type byte. it will be replaced by the decode.
386 }
387 }
388 str += HexStr(vch) + strSigHashDecode;
389 } else {
390 str += HexStr(vch);
391 }
392 }
393 } else {
394 str += GetOpName(opcode);
395 }
396 }
397 return str;
398}
399
400std::string EncodeHexTx(const CTransaction& tx)
401{

Callers 7

MutateTxSignFunction · 0.85
ScriptToUnivFunction · 0.85
TxToUnivFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
script_format.cppFile · 0.85
decodepsbtFunction · 0.85
ParsePrevoutsFunction · 0.85

Calls 14

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 1

BOOST_AUTO_TEST_CASEFunction · 0.68