28 while (it != script.end()) {
30 std::vector<uint8_t> vch;
31 if (script.GetOp(it, op, vch)) {
44 if (str.substr(0, 3) == std::string(
"OP_")) {
45 ret += str.substr(3, std::string::npos) +
" ";
53 HexStr(std::vector<uint8_t>(it2, it - vch.size())),
54 HexStr(std::vector<uint8_t>(it - vch.size(), it)));
68 return ret.substr(0, ret.size() - 1);
76 "ALL|FORKID|ANYONECANPAY"},
81 "NONE|FORKID|ANYONECANPAY"},
86 "SINGLE|FORKID|ANYONECANPAY"},
107 const bool fAttemptSighashDecode) {
110 std::vector<uint8_t> vch;
112 while (pc < script.end()) {
117 if (!script.GetOp(pc, opcode, vch)) {
132 if (fAttemptSighashDecode && !script.IsUnspendable()) {
133 std::string strSigHashDecode;
150 const uint8_t chSigHashType = vch.back();
153 strSigHashDecode =
"[" + it->second +
"]";
160 str +=
HexStr(vch) + strSigHashDecode;
183 std::vector<std::vector<uint8_t>> solns;
197 std::vector<CTxDestination> addresses;
211 out.
pushKV(
"reqSigs", nRequired);
218 out.
pushKV(
"addresses", a);
224 std::function<
bool(
const CTxOut &)> is_change_func) {
225 entry.
pushKV(
"txid", tx.GetId().GetHex());
226 entry.
pushKV(
"hash", tx.GetHash().GetHex());
230 static_cast<int64_t
>(
static_cast<uint32_t
>(tx.nVersion)));
232 entry.
pushKV(
"locktime", (int64_t)tx.nLockTime);
239 const bool have_undo = txundo !=
nullptr;
243 for (
unsigned int i = 0; i < tx.vin.size(); i++) {
244 const CTxIn &txin = tx.vin[i];
246 if (tx.IsCoinBase()) {
249 in.
pushKV(
"txid", txin.prevout.GetTxId().GetHex());
250 in.
pushKV(
"vout", int64_t(txin.prevout.GetN()));
254 in.
pushKV(
"scriptSig", std::move(o));
260 amt_total_in += prev_txout.
nValue;
269 o_script_pub_key,
true);
275 p.
pushKV(
"scriptPubKey", std::move(o_script_pub_key));
276 in.
pushKV(
"prevout", std::move(p));
280 in.
pushKV(
"sequence", (int64_t)txin.nSequence);
281 vin.push_back(std::move(in));
284 entry.
pushKV(
"vin", std::move(vin));
287 for (
unsigned int i = 0; i < tx.vout.size(); i++) {
288 const CTxOut &txout = tx.vout[i];
293 out.
pushKV(
"n", int64_t(i));
297 out.
pushKV(
"scriptPubKey", std::move(o));
299 if (is_change_func && is_change_func(txout)) {
300 out.
pushKV(
"ischange",
true);
306 amt_total_out += txout.
nValue;
310 entry.
pushKV(
"vout", std::move(vout));
313 const Amount fee = amt_total_in - amt_total_out;
318 if (!hashBlock.
IsNull()) {
bool MoneyRange(const Amount nValue)
#define CHECK_NONFATAL(condition)
Identity function.
static bool IsMinimallyEncoded(const std::vector< uint8_t > &vch, const size_t nMaxNumSize)
An output of a transaction.
Restore the UTXO in a Coin at a given COutPoint.
std::vector< Coin > vprevout
uint32_t GetHeight() const
Double ended buffer combining vector and stream-like interfaces.
void push_back(UniValue val)
void pushKV(std::string key, UniValue val)
std::string GetHex() const
const Config & GetConfig()
TxVerbosity
Verbose level for block's transaction.
@ SHOW_DETAILS_AND_PREVOUT
The same as previous option with information about prevouts if available.
@ SHOW_TXID
Only TXID for each block's transaction.
@ SHOW_DETAILS
Include TXID, inputs, outputs, and other common block's transaction information.
void ScriptToUniv(const CScript &script, UniValue &out, bool include_address)
std::string EncodeHexTx(const CTransaction &tx)
std::string SighashToStr(uint8_t sighash_type)
std::string FormatScript(const CScript &script)
void ScriptPubKeyToUniv(const CScript &scriptPubKey, UniValue &out, bool fIncludeHex)
void TxToUniv(const CTransaction &tx, const BlockHash &hashBlock, UniValue &entry, bool include_hex, const CTxUndo *txundo, TxVerbosity verbosity, std::function< bool(const CTxOut &)> is_change_func)
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode)
Create the assembly string representation of a CScript object.
const std::map< uint8_t, std::string > mapSigHashTypes
std::string EncodeDestination(const CTxDestination &dest, const Config &config)
std::string GetOpName(opcodetype opcode)
opcodetype
Script opcodes.
@ FIRST_UNDEFINED_OP_VALUE
constexpr size_t MAX_SCRIPTNUM_BYTE_SIZE
@ SCRIPT_VERIFY_STRICTENC
@ SCRIPT_ENABLE_SIGHASH_FORKID
size_t GetSerializeSize(const T &t, int nVersion=0)
bool CheckTransactionSignatureEncoding(const valtype &vchSig, uint32_t flags, ScriptError *serror)
Check that the signature provided to authentify a transaction is properly encoded.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< uint8_t > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
std::string GetTxnOutputType(TxoutType t)
Get the name of a TxoutType as a string.
bool ExtractDestinations(const CScript &scriptPubKey, TxoutType &typeRet, std::vector< CTxDestination > &addressRet, int &nRequiredRet)
Parse a standard scriptPubKey with one or more destination addresses.
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
static constexpr Amount zero() noexcept
A BlockHash is a unqiue identifier for a block.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
static const int PROTOCOL_VERSION
network protocol versioning