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

Function ScriptToAsmStr

src/core_write.cpp:94–155  ·  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 signat

Source from the content-addressed store, hash-verified

92 * pass false, or omit the this argument (defaults to false), for scriptPubKeys.
93 */
94string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode, bool f64BitNums)
95{
96 string str;
97 opcodetype opcode;
98 vector<uint8_t> vch;
99 CScript::const_iterator pc = script.begin();
100 while (pc < script.end())
101 {
102 if (!str.empty())
103 {
104 str += " ";
105 }
106 if (!script.GetOp(pc, opcode, vch))
107 {
108 str += "[error]";
109 return str;
110 }
111 size_t const maxScriptNumSize =
112 f64BitNums ? CScriptNum::MAXIMUM_ELEMENT_SIZE_64_BIT : CScriptNum::MAXIMUM_ELEMENT_SIZE_32_BIT;
113 if (0 <= opcode && opcode <= OP_PUSHDATA4)
114 {
115 if (vch.size() <= maxScriptNumSize)
116 {
117 str += strprintf("%d", CScriptNum(vch, false, maxScriptNumSize).getint64());
118 }
119 else
120 {
121 // the IsUnspendable check makes sure not to try to decode OP_RETURN data that may match the format of a
122 // signature
123 if (fAttemptSighashDecode && !script.IsUnspendable())
124 {
125 string strSigHashDecode;
126 // goal: only attempt to decode a defined sighash type from data that looks like a signature within
127 // a scriptSig.
128 // this won't decode correctly formatted public keys in Pubkey or Multisig scripts due to
129 // the restrictions on the pubkey formats (see IsCompressedOrUncompressedPubKey) being incongruous
130 // with the
131 // checks in CheckSignatureEncoding.
132 if (CheckSignatureEncoding(vch, SCRIPT_VERIFY_STRICTENC, nullptr))
133 {
134 const unsigned char chSigHashType = vch.back();
135 if (mapSigHashTypes.count(chSigHashType))
136 {
137 strSigHashDecode = "[" + mapSigHashTypes.find(chSigHashType)->second + "]";
138 vch.pop_back(); // remove the sighash type byte. it will be replaced by the decode.
139 }
140 }
141 str += HexStr(vch) + strSigHashDecode;
142 }
143 else
144 {
145 str += HexStr(vch);
146 }
147 }
148 }
149 else
150 {
151 str += GetOpName(opcode);

Callers 10

ScriptPubKeyToUnivFunction · 0.85
TxToUnivFunction · 0.85
MutateTxSignFunction · 0.85
LoadFreezeScriptMethod · 0.85
IsMineFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 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 2

BOOST_AUTO_TEST_CASEFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68