1 // Copyright (c) 2009-2019 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 <amount.h>
9 #include <attributes.h>
10 
11 #include <string>
12 #include <vector>
13 
14 class CBlock;
15 class CBlockHeader;
16 class CScript;
17 class CTransaction;
18 struct CMutableTransaction;
19 class uint256;
20 class UniValue;
21 
22 // core_read.cpp
23 CScript ParseScript(const std::string& s);
24 std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode = false);
25 NODISCARD bool DecodeHexTx(CMutableTransaction& tx, const std::string& hex_tx, bool try_no_witness = false, bool try_witness = true);
26 NODISCARD bool DecodeHexBlk(CBlock&, const std::string& strHexBlk);
27 bool DecodeHexBlockHeader(CBlockHeader&, const std::string& hex_header);
28 
29 /**
30  * Parse a hex string into 256 bits
31  * @param[in] strHex a hex-formatted, 64-character string
32  * @param[out] result the result of the parasing
33  * @returns true if successful, false if not
34  *
35  * @see ParseHashV for an RPC-oriented version of this
36  */
37 bool ParseHashStr(const std::string& strHex, uint256& result);
38 std::vector<unsigned char> ParseHexUV(const UniValue& v, const std::string& strName);
39 int ParseSighashString(const UniValue& sighash);
40 
41 // core_write.cpp
42 UniValue ValueFromAmount(const CAmount& amount);
43 std::string FormatScript(const CScript& script);
44 std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0);
45 std::string SighashToStr(unsigned char sighash_type);
46 void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
47 void ScriptToUniv(const CScript& script, UniValue& out, bool include_address);
48 void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0);
49 
50 #endif // BITCOIN_CORE_IO_H
51