Electroneum
cn_deserialize.cpp File Reference
#include <boost/filesystem.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include "cryptonote_basic/cryptonote_basic.h"
#include "cryptonote_basic/tx_extra.h"
#include "cryptonote_core/blockchain.h"
#include "common/command_line.h"
#include "version.h"
Include dependency graph for cn_deserialize.cpp:

Go to the source code of this file.

Macros

#define ELECTRONEUM_DEFAULT_LOG_CATEGORY   "debugtools.deserialize"
 

Functions

int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ ELECTRONEUM_DEFAULT_LOG_CATEGORY

#define ELECTRONEUM_DEFAULT_LOG_CATEGORY   "debugtools.deserialize"

Definition at line 40 of file cn_deserialize.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 73 of file cn_deserialize.cpp.

74 {
75  uint32_t log_level = 0;
76  std::string input;
77 
79 
80  boost::filesystem::path output_file_path;
81 
82  po::options_description desc_cmd_only("Command line options");
83  po::options_description desc_cmd_sett("Command line options and settings options");
84  const command_line::arg_descriptor<uint32_t> arg_log_level = {"log-level", "", log_level};
85  const command_line::arg_descriptor<std::string> arg_input = {"input", "Specify input has a hexadecimal string", ""};
86 
87  command_line::add_arg(desc_cmd_sett, arg_log_level);
88  command_line::add_arg(desc_cmd_sett, arg_input);
89 
91 
92  po::options_description desc_options("Allowed options");
93  desc_options.add(desc_cmd_only).add(desc_cmd_sett);
94 
95  po::variables_map vm;
96  bool r = command_line::handle_error_helper(desc_options, [&]()
97  {
98  po::store(po::parse_command_line(argc, argv, desc_options), vm);
99  po::notify(vm);
100  return true;
101  });
102  if (! r)
103  return 1;
104 
106  {
107  std::cout << "Electroneum '" << ELECTRONEUM_RELEASE_NAME << "' (v" << ELECTRONEUM_VERSION_FULL << ")" << ENDL << ENDL;
108  std::cout << desc_options << std::endl;
109  return 1;
110  }
111 
112  log_level = command_line::get_arg(vm, arg_log_level);
113  input = command_line::get_arg(vm, arg_input);
114  if (input.empty())
115  {
116  std::cerr << "--input is mandatory" << std::endl;
117  return 1;
118  }
119 
120  mlog_configure("", true);
121 
124  {
125  std::cerr << "Invalid hex input" << std::endl;
126  return 1;
127  }
128 
129  bool full;
132  std::vector<cryptonote::tx_extra_field> fields;
134  {
135  std::cout << "Parsed block:" << std::endl;
136  std::cout << cryptonote::obj_to_json_str(block) << std::endl;
137  }
139  {
140  if (tx.pruned)
141  std::cout << "Parsed pruned transaction:" << std::endl;
142  else
143  std::cout << "Parsed transaction:" << std::endl;
144  std::cout << cryptonote::obj_to_json_str(tx) << std::endl;
145 
146  bool parsed = cryptonote::parse_tx_extra(tx.extra, fields);
147  if (!parsed)
148  std::cout << "Failed to parse tx_extra" << std::endl;
149 
150  if (!fields.empty())
151  {
152  print_extra_fields(fields);
153  }
154  else
155  {
156  std::cout << "No fields were found in tx_extra" << std::endl;
157  }
158  }
159  else if (((full = cryptonote::parse_tx_extra(std::vector<uint8_t>(blob.begin(), blob.end()), fields)) || true) && !fields.empty())
160  {
161  std::cout << "Parsed" << (full ? "" : " partial") << " tx_extra:" << std::endl;
162  print_extra_fields(fields);
163  }
164  else
165  {
166  std::cerr << "Not a recognized CN type" << std::endl;
167  return 1;
168  }
169 
170 
171 
172  return 0;
173 }
std::vector< uint8_t > extra
void mlog_configure(const std::string &filename_base, bool console, const std::size_t max_log_file_size=MAX_LOG_FILE_SIZE, const std::size_t max_log_files=MAX_LOG_FILES)
Definition: mlog.cpp:148
#define ENDL
Definition: misc_log_ex.h:149
boost::program_options::basic_parsed_options< charT > parse_command_line(int argc, const charT *const argv[], const boost::program_options::options_description &desc, bool allow_unregistered=false)
Definition: command_line.h:224
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
Definition: command_line.h:188
const arg_descriptor< bool > arg_help
bool handle_error_helper(const boost::program_options::options_description &desc, F parser)
Definition: command_line.h:237
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
Definition: command_line.h:271
std::string obj_to_json_str(T &obj)
bool parse_and_validate_block_from_blob(const blobdata &b_blob, block &b, crypto::hash *block_hash)
bool parse_tx_extra(const std::vector< uint8_t > &tx_extra, std::vector< tx_extra_field > &tx_extra_fields)
std::string blobdata
Definition: blobdatatype.h:39
bool parse_and_validate_tx_from_blob(const blobdata &tx_blob, transaction &tx)
bool parse_and_validate_tx_base_from_blob(const blobdata &tx_blob, transaction &tx)
const command_line::arg_descriptor< std::string > arg_log_level
bool parse_hexstr_to_binbuff(const epee::span< const char > s, epee::span< char > &res)
Definition: string_tools.h:92
::std::string string
Definition: gtest-port.h:1097
bool on_startup()
Definition: util.cpp:778
unsigned int uint32_t
Definition: stdint.h:126
const char *const ELECTRONEUM_RELEASE_NAME
const char *const ELECTRONEUM_VERSION_FULL
Here is the call graph for this function: