github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/cmd/util/hex.cpp (about) 1 // Copyright (C) 2018 go-nebulas authors 2 // 3 // This file is part of the go-nebulas library. 4 // 5 // the go-nebulas library is free software: you can redistribute it and/or 6 // modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // (at your option) any later version. 10 // 11 // the go-nebulas library is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with the go-nebulas library. If not, see 18 // <http://www.gnu.org/licenses/>. 19 // 20 21 #include "common/byte.h" 22 #include "common/common.h" 23 #include <boost/program_options.hpp> 24 #include <iomanip> 25 #include <sstream> 26 27 namespace po = boost::program_options; 28 29 int main(int argc, char *argv[]) { 30 31 po::options_description desc("Address base58 to string bytes"); 32 desc.add_options()("help", "show help message")( 33 "address", po::value<std::string>(), "address base58 encoding"); 34 35 po::variables_map vm; 36 po::store(po::parse_command_line(argc, argv, desc), vm); 37 po::notify(vm); 38 39 if (vm.count("help")) { 40 std::cout << desc << "\n"; 41 return 1; 42 } 43 44 if (!vm.count("address")) { 45 std::cout << "You must specify \"address\"!" << std::endl; 46 return 1; 47 } 48 49 std::string addr_base58 = vm["address"].as<std::string>(); 50 neb::bytes addr_bytes = neb::bytes::from_base58(addr_base58); 51 std::string addr = neb::byte_to_string(addr_bytes); 52 LOG(INFO) << addr.size(); 53 54 std::stringstream ss; 55 ss << '{'; 56 for (std::size_t i = 0; i < addr.size(); i++) { 57 uint8_t c = addr[i]; 58 ss << "0x" << std::hex << std::setw(2) << std::setfill('0') 59 << static_cast<int>(c) << ','; 60 } 61 ss.seekp(-1, std::ios_base::end); 62 ss << '}'; 63 LOG(INFO) << ss.str(); 64 return 0; 65 }