Electroneum
Loading...
Searching...
No Matches
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 75 of file cn_deserialize.cpp.

76{
77 uint32_t log_level = 0;
78 std::string input;
79
81
82 boost::filesystem::path output_file_path;
83
84 po::options_description desc_cmd_only("Command line options");
85 po::options_description desc_cmd_sett("Command line options and settings options");
86 const command_line::arg_descriptor<uint32_t> arg_log_level = {"log-level", "", log_level};
87 const command_line::arg_descriptor<std::string> arg_input = {"input", "Specify input has a hexadecimal string", ""};
88
89 command_line::add_arg(desc_cmd_sett, arg_log_level);
90 command_line::add_arg(desc_cmd_sett, arg_input);
91
93
94 po::options_description desc_options("Allowed options");
95 desc_options.add(desc_cmd_only).add(desc_cmd_sett);
96
97 po::variables_map vm;
98 bool r = command_line::handle_error_helper(desc_options, [&]()
99 {
100 po::store(po::parse_command_line(argc, argv, desc_options), vm);
101 po::notify(vm);
102 return true;
103 });
104 if (! r)
105 return 1;
106
108 {
109 std::cout << "Electroneum '" << ELECTRONEUM_RELEASE_NAME << "' (v" << ELECTRONEUM_VERSION_FULL << ")" << ENDL << ENDL;
110 std::cout << desc_options << std::endl;
111 return 1;
112 }
113
114 log_level = command_line::get_arg(vm, arg_log_level);
115 input = command_line::get_arg(vm, arg_input);
116 if (input.empty())
117 {
118 std::cerr << "--input is mandatory" << std::endl;
119 return 1;
120 }
121
122 mlog_configure("", true);
123
126 {
127 std::cerr << "Invalid hex input" << std::endl;
128 return 1;
129 }
130
131 bool full;
134 std::vector<cryptonote::tx_extra_field> fields;
136 {
137 std::cout << "Parsed block:" << std::endl;
138 std::cout << cryptonote::obj_to_json_str(block) << std::endl;
139 }
141 {
142 if (tx.pruned)
143 std::cout << "Parsed pruned transaction:" << std::endl;
144 else
145 std::cout << "Parsed transaction:" << std::endl;
146 std::cout << cryptonote::obj_to_json_str(tx) << std::endl;
147
148 bool parsed = cryptonote::parse_tx_extra(tx.extra, fields);
149 if (!parsed)
150 std::cout << "Failed to parse tx_extra" << std::endl;
151
152 if (!fields.empty())
153 {
154 print_extra_fields(fields);
155 }
156 else
157 {
158 std::cout << "No fields were found in tx_extra" << std::endl;
159 }
160 }
161 else if (((full = cryptonote::parse_tx_extra(std::vector<uint8_t>(blob.begin(), blob.end()), fields)) || true) && !fields.empty())
162 {
163 std::cout << "Parsed" << (full ? "" : " partial") << " tx_extra:" << std::endl;
164 print_extra_fields(fields);
165 }
166 else
167 {
168 std::cerr << "Not a recognized CN type" << std::endl;
169 return 1;
170 }
171
172
173
174 return 0;
175}
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
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
const arg_descriptor< bool > arg_help
bool handle_error_helper(const boost::program_options::options_description &desc, F parser)
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
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
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)
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: