core_io.h raw

   1  // Copyright (c) 2009-2022 The Limenka 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 LIMENKA_CORE_IO_H
   6  #define LIMENKA_CORE_IO_H
   7  
   8  #include <consensus/amount.h>
   9  #include <util/result.h>
  10  
  11  #include <string>
  12  #include <vector>
  13  #include <optional>
  14  
  15  class CBlock;
  16  class CBlockHeader;
  17  class CFeeRate;
  18  class CScript;
  19  class CTransaction;
  20  struct CMutableTransaction;
  21  class SigningProvider;
  22  class uint256;
  23  class UniValue;
  24  class CTxUndo;
  25  
  26  /**
  27   * Verbose level for block's transaction
  28   */
  29  enum class TxVerbosity {
  30      SHOW_TXID,                //!< Only TXID for each block's transaction
  31      SHOW_DETAILS,             //!< Include TXID, inputs, outputs, and other common block's transaction information
  32      SHOW_DETAILS_AND_PREVOUT  //!< The same as previous option with information about prevouts if available
  33  };
  34  
  35  // core_read.cpp
  36  CScript ParseScript(const std::string& s);
  37  std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode = false);
  38  [[nodiscard]] bool DecodeTx(CMutableTransaction& tx, const std::vector<unsigned char>& tx_data, bool try_no_witness, bool try_witness);
  39  [[nodiscard]] bool DecodeHexTx(CMutableTransaction& tx, const std::string& hex_tx, bool try_no_witness = false, bool try_witness = true);
  40  [[nodiscard]] bool DecodeHexBlk(CBlock&, const std::string& strHexBlk);
  41  bool DecodeHexBlockHeader(CBlockHeader&, const std::string& hex_header);
  42  
  43  [[nodiscard]] util::Result<int> SighashFromStr(const std::string& sighash);
  44  
  45  // core_write.cpp
  46  UniValue ValueFromAmount(const CAmount amount);
  47  UniValue ValueFromFeeRate(const CFeeRate& fee_rate);
  48  std::string FormatScript(const CScript& script);
  49  std::string EncodeHexTx(const CTransaction& tx);
  50  std::string SighashToStr(unsigned char sighash_type);
  51  void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex = true, bool include_address = false, const SigningProvider* provider = nullptr);
  52  void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry, bool include_hex = true, const CTxUndo* txundo = nullptr, TxVerbosity verbosity = TxVerbosity::SHOW_DETAILS);
  53  
  54  #endif // LIMENKA_CORE_IO_H
  55