core_io.h raw
1 // Copyright (c) 2009-present The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5 #ifndef BITCOIN_CORE_IO_H
6 #define BITCOIN_CORE_IO_H
7
8 #include <consensus/amount.h>
9 #include <util/result.h>
10
11 #include <functional>
12 #include <string>
13
14 class CBlock;
15 class CBlockHeader;
16 class CScript;
17 class CTransaction;
18 struct CMutableTransaction;
19 class SigningProvider;
20 class uint256;
21 class UniValue;
22 class CTxUndo;
23 class CTxOut;
24
25 /**
26 * Verbose level for block's transaction
27 */
28 enum class TxVerbosity {
29 SHOW_TXID, //!< Only TXID for each block's transaction
30 SHOW_DETAILS, //!< Include TXID, inputs, outputs, and other common block's transaction information
31 SHOW_DETAILS_AND_PREVOUT //!< The same as previous option with information about prevouts if available
32 };
33
34 CScript ParseScript(const std::string& s);
35 std::string ScriptToAsmStr(const CScript& script, bool fAttemptSighashDecode = false);
36 [[nodiscard]] bool DecodeHexTx(CMutableTransaction& tx, const std::string& hex_tx, bool try_no_witness = false, bool try_witness = true);
37 [[nodiscard]] bool DecodeHexBlk(CBlock&, const std::string& strHexBlk);
38 bool DecodeHexBlockHeader(CBlockHeader&, const std::string& hex_header);
39
40 [[nodiscard]] util::Result<int> SighashFromStr(const std::string& sighash);
41
42 UniValue ValueFromAmount(CAmount amount);
43 std::string FormatScript(const CScript& script);
44 std::string EncodeHexTx(const CTransaction& tx);
45 std::string SighashToStr(unsigned char sighash_type);
46 void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex = true, bool include_address = false, const SigningProvider* provider = nullptr);
47 void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry, bool include_hex = true, const CTxUndo* txundo = nullptr, TxVerbosity verbosity = TxVerbosity::SHOW_DETAILS, std::function<bool(const CTxOut&)> is_change_func = {});
48
49 #endif // BITCOIN_CORE_IO_H
50