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

Function ScriptToAsmStr

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

78 * pass false, or omit the this argument (defaults to false), for scriptPubKeys.
79 */
80string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode)
81{
82 string str;
83 opcodetype opcode;
84 vector<unsigned char> vch;
85 CScript::const_iterator pc = script.begin();
86 while (pc < script.end()) {
87 if (!str.empty()) {
88 str += " ";
89 }
90 if (!script.GetOp(pc, opcode, vch)) {
91 str += "[error]";
92 return str;
93 }
94 if (0 <= opcode && opcode <= OP_PUSHDATA4) {
95 if (vch.size() <= static_cast<vector<unsigned char>::size_type>(4)) {
96 str += strprintf("%d", CScriptNum(vch, false).getint());
97 } else {
98 // the IsUnspendable check makes sure not to try to decode OP_RETURN data that may match the format of a signature
99 if (fAttemptSighashDecode && !script.IsUnspendable()) {
100 std::string strSigHashDecode;
101 // goal: only attempt to decode a defined sighash type from
102 // data that looks like a signature within a scriptSig. This
103 // won't decode correctly formatted public keys in Pubkey or
104 // Multisig scripts due to the restrictions on the pubkey
105 // formats (see IsCompressedOrUncompressedPubKey) being
106 // incongruous with the checks in CheckSignatureEncoding.
107 uint32_t flags = SCRIPT_VERIFY_STRICTENC;
108 if (vch.back() & SIGHASH_FORKID) {
109 // If the transaction is using SIGHASH_FORKID, we need
110 // to set the apropriate flag.
111 // TODO: Remove after the Hard Fork.
112 flags |= SCRIPT_ENABLE_SIGHASH_FORKID;
113 }
114 if (CheckSignatureEncoding(vch, flags, nullptr)) {
115 const unsigned char chSigHashType = vch.back();
116 if (mapSigHashTypes.count(chSigHashType)) {
117 strSigHashDecode = "[" + mapSigHashTypes.find(chSigHashType)->second + "]";
118 vch.pop_back(); // remove the sighash type byte. it will be replaced by the decode.
119 }
120 }
121 str += HexStr(vch) + strSigHashDecode;
122 } else {
123 str += HexStr(vch);
124 }
125 }
126 } else {
127 str += GetOpName(opcode);
128 }
129 }
130 return str;
131}
132
133string EncodeHexTx(const CTransaction& tx)
134{

Callers 7

ScriptPubKeyToUnivFunction · 0.85
BOOST_FOREACHFunction · 0.85
MutateTxSignFunction · 0.85
ScriptPubKeyToJSONFunction · 0.85
BOOST_FOREACHFunction · 0.85
signrawtransactionFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 13

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