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

Function ScriptToAsmStr

src/core_write.cpp:73–115  ·  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

71 * pass false, or omit the this argument (defaults to false), for scriptPubKeys.
72 */
73std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode)
74{
75 std::string str;
76 opcodetype opcode;
77 std::vector<unsigned char> vch;
78 CScript::const_iterator pc = script.begin();
79 while (pc < script.end()) {
80 if (!str.empty()) {
81 str += " ";
82 }
83 if (!script.GetOp(pc, opcode, vch)) {
84 str += "[error]";
85 return str;
86 }
87 if (0 <= opcode && opcode <= OP_PUSHDATA4) {
88 if (vch.size() <= static_cast<std::vector<unsigned char>::size_type>(4)) {
89 str += strprintf("%d", CScriptNum(vch, false).getint());
90 } else {
91 // the IsUnspendable check makes sure not to try to decode OP_RETURN data that may match the format of a signature
92 if (fAttemptSighashDecode && !script.IsUnspendable()) {
93 std::string strSigHashDecode;
94 // goal: only attempt to decode a defined sighash type from data that looks like a signature within a scriptSig.
95 // this won't decode correctly formatted public keys in Pubkey or Multisig scripts due to
96 // the restrictions on the pubkey formats (see IsCompressedOrUncompressedPubKey) being incongruous with the
97 // checks in CheckSignatureEncoding.
98 if (CheckSignatureEncoding(vch, SCRIPT_VERIFY_STRICTENC, NULL)) {
99 const unsigned char chSigHashType = vch.back();
100 if (mapSigHashTypes.count(chSigHashType)) {
101 strSigHashDecode = "[" + mapSigHashTypes.find(chSigHashType)->second + "]";
102 vch.pop_back(); // remove the sighash type byte. it will be replaced by the decode.
103 }
104 }
105 str += HexStr(vch) + strSigHashDecode;
106 } else {
107 str += HexStr(vch);
108 }
109 }
110 } else {
111 str += GetOpName(opcode);
112 }
113 }
114 return str;
115}
116
117std::string EncodeHexTx(const CTransaction& tx, const int serialFlags)
118{

Callers 7

ScriptPubKeyToUnivFunction · 0.85
TxToUnivFunction · 0.85
MutateTxSignFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
ScriptPubKeyToJSONFunction · 0.85
TxToJSONFunction · 0.85
signrawtransactionFunction · 0.85

Calls 14

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

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68