23 static_assert(
COIN > 1);
24 int64_t quotient = amount /
COIN;
25 int64_t remainder = amount %
COIN;
28 remainder = -remainder;
31 strprintf(
"%s%d.%08d", amount < 0 ?
"-" :
"", quotient, remainder));
39 while (it != script.
end()) {
41 std::vector<unsigned char> vch;
42 if (script.
GetOp(it, op, vch)) {
51 if (str.substr(0, 3) == std::string(
"OP_")) {
52 ret += str.substr(3, std::string::npos) +
" ";
57 ret +=
strprintf(
"0x%x 0x%x ",
HexStr(std::vector<uint8_t>(it2, it - vch.size())),
58 HexStr(std::vector<uint8_t>(it - vch.size(), it)));
67 return ret.substr(0, ret.size() - 1);
71 {
static_cast<unsigned char>(
SIGHASH_ALL), std::string(
"ALL")},
73 {
static_cast<unsigned char>(
SIGHASH_NONE), std::string(
"NONE")},
75 {
static_cast<unsigned char>(
SIGHASH_SINGLE), std::string(
"SINGLE")},
97 std::vector<unsigned char> vch;
99 while (pc < script.
end()) {
103 if (!script.
GetOp(pc, opcode, vch)) {
108 if (vch.size() <=
static_cast<std::vector<unsigned char>::size_type
>(4)) {
113 std::string strSigHashDecode;
119 const unsigned char chSigHashType = vch.back();
122 strSigHashDecode =
"[" + it->second +
"]";
126 str +=
HexStr(vch) + strSigHashDecode;
155 if (include_hex) out.
pushKV(
"hex",
HexStr(scriptPubKey));
157 std::vector<std::vector<unsigned char>> solns;
172 entry.
pushKV(
"version",
static_cast<int64_t
>(
static_cast<uint32_t
>(tx.
nVersion)));
182 const bool have_undo = txundo !=
nullptr;
186 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
197 in.
pushKV(
"scriptSig", o);
199 if (!tx.
vin[i].scriptWitness.IsNull()) {
201 for (
const auto& item : tx.
vin[i].scriptWitness.stack) {
204 in.
pushKV(
"txinwitness", txinwitness);
208 const CTxOut& prev_txout = prev_coin.
out;
210 amt_total_in += prev_txout.
nValue;
224 p.
pushKV(
"scriptPubKey", o_script_pub_key);
235 for (
unsigned int i = 0; i < tx.
vout.size(); i++) {
241 out.
pushKV(
"n", (int64_t)i);
245 out.
pushKV(
"scriptPubKey", o);
249 amt_total_out += txout.
nValue;
252 entry.
pushKV(
"vout", vout);
255 const CAmount fee = amt_total_in - amt_total_out;
bool MoneyRange(const CAmount &nValue)
int64_t CAmount
Amount in satoshis (Can be negative)
static constexpr CAmount COIN
The amount of satoshis in one BTC.
#define CHECK_NONFATAL(condition)
Throw a NonFatalCheckError when the condition evaluates to false.
Double ended buffer combining vector and stream-like interfaces.
Serialized script, used inside transaction inputs and outputs.
bool IsUnspendable() const
Returns whether the script is guaranteed to fail at execution, regardless of the initial stack.
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet) const
The basic transaction that is broadcasted on the network and contained in blocks.
const uint256 & GetWitnessHash() const
const uint256 & GetHash() const
const std::vector< CTxOut > vout
const std::vector< CTxIn > vin
An input of a transaction.
An output of a transaction.
Undo information for a CTransaction.
std::vector< Coin > vprevout
CTxOut out
unspent transaction output
uint32_t nHeight
at which height this containing transaction was included in the active block chain
unsigned int fCoinBase
whether containing transaction was a coinbase
bool push_back(const UniValue &val)
bool pushKV(const std::string &key, const UniValue &val)
std::string GetHex() const
static int64_t GetTransactionWeight(const CTransaction &tx)
static const int WITNESS_SCALE_FACTOR
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 ScriptPubKeyToUniv(const CScript &scriptPubKey, UniValue &out, bool include_hex, bool include_address)
std::string SighashToStr(unsigned char sighash_type)
std::string FormatScript(const CScript &script)
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode)
Create the assembly string representation of a CScript object.
void ScriptToUniv(const CScript &script, UniValue &out)
std::string EncodeHexTx(const CTransaction &tx, const int serializeFlags)
void TxToUniv(const CTransaction &tx, const uint256 &hashBlock, UniValue &entry, bool include_hex, int serialize_flags, const CTxUndo *txundo, TxVerbosity verbosity)
const std::map< unsigned char, std::string > mapSigHashTypes
UniValue ValueFromAmount(const CAmount amount)
bool CheckSignatureEncoding(const std::vector< unsigned char > &vchSig, unsigned int flags, ScriptError *serror)
@ SCRIPT_VERIFY_STRICTENC
std::string EncodeDestination(const CTxDestination &dest)
std::string GetOpName(opcodetype opcode)
opcodetype
Script opcodes.
size_t GetSerializeSize(const T &t, int nVersion=0)
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
std::string GetTxnOutputType(TxoutType t)
Get the name of a TxoutType as a string.
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
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