Advertisement
Guest User

pymonero.cpp

a guest
Mar 5th, 2020
303
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include "cryptonote_basic/cryptonote_format_utils.h"
  3.  
  4. using namespace cryptonote;
  5. using namespace std;
  6.  
  7. std::string string_to_hex(const std::string& input)
  8. {
  9.     static const char hex_digits[] = "0123456789abcdef";
  10.     std::string output;
  11.     output.reserve(input.length() * 2);
  12.     for (unsigned char c : input)
  13.     {
  14.         output.push_back(hex_digits[c >> 4]);
  15.         output.push_back(hex_digits[c & 15]);
  16.     }
  17.     return output;
  18. }
  19.  
  20.  
  21. // convert hex string to string that has values based on that hex
  22. // thankfully should automatically ignore null-terminator.
  23. std::string h2b(const std::string &s) {
  24.     bool upper = true;
  25.     std::string result;
  26.     unsigned char val = 0;
  27.     for (char c : s) {
  28.         if (upper) {
  29.             val = 0;
  30.             if (c <= 'f' && c >= 'a') {
  31.                 val = ((c - 'a') + 10) << 4;
  32.             } else {
  33.                 val = (c - '0') << 4;
  34.             }
  35.         } else {
  36.             if (c <= 'f' && c >= 'a') {
  37.                 val |= (c - 'a') + 10;
  38.             } else {
  39.                 val |= c - '0';
  40.             }
  41.             result += (char) val;
  42.         }
  43.         upper = !upper;
  44.     }
  45.     return result;
  46. }
  47.  
  48.  
  49. int main() {
  50.     blobdata b_blob = h2b(
  51.          "0c0ce185b0f2053941deed208d6449bb432fbce9778efb4cd9229cc79e4c04ef7b2a2f7c99df4a0000000002afdd1f01fff3dc1f018f918980888803025b08e22c6cb11c61b628de4217c3959627414d2d10579b780ca1e1fec0164bba210174b9819eb50c698d574bc408a0f7fedd608296647291551e98be4f7134bc26660000");
  52.     blobdata hashing_blob;
  53.     cout << "Input:\t" << string_to_hex(b_blob) << endl;
  54.  
  55.     block b = AUTO_VAL_INIT(b);
  56.     if (!parse_and_validate_block_from_blob(b_blob, b)) {
  57.         cout << "Not valid blob" << endl;
  58.         return -1;
  59.     }
  60.     hashing_blob = get_block_hashing_blob(b);
  61.     cout << "Output:\t" << string_to_hex(hashing_blob) << endl;
  62.     return 0;
  63. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement