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

Function ScriptToAsmStr

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

91 * pass false, or omit the this argument (defaults to false), for scriptPubKeys.
92 */
93std::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
137std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags)
138{

Callers 7

ScriptToUnivFunction · 0.85
ScriptPubKeyToUnivFunction · 0.85
TxToUnivFunction · 0.85
MutateTxSignFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
SignTransactionFunction · 0.85
decodepsbtFunction · 0.85

Calls 14

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

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68