Guest User

Untitled

a guest
Jan 28th, 2025
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. #include <wallet/wallet2.h>
  2. #include <iostream>
  3. #include <string>
  4. #include <memory>
  5.  
  6. using namespace std;
  7. using namespace cryptonote;
  8. using namespace tools;
  9.  
  10. int main() {
  11.     try {
  12.         constexpr network_type nettype = TESTNET;
  13.         unique_ptr<wallet2> wallet(new wallet2(nettype));
  14.  
  15.         const string wallet_path = "/home/adam/Monero/wallets/wallet_2";
  16.         const string password;
  17.         const string daemon_address = "127.0.0.1:28081";
  18.        
  19.         wallet->load(wallet_path, password);
  20.         wallet->init("");
  21.         wallet->set_daemon(daemon_address);
  22.         wallet->refresh(true);
  23.  
  24.         cout << "Current balance: " << wallet->balance(0, true) << endl;
  25.         cout << "Unlocked balance: " << wallet->unlocked_balance(0, true) << endl;
  26.         string recipent_address = "9x54DBt6ooEJY4GTmt4MCXeBJYfwFtRRr975DRiLGM3LVyJuudHDnzYLnUcVzvxi8xgBfY7fMXArTUPLuTxbnYbv3P29ihL";
  27.         constexpr uint64_t amount = 250000000000;
  28.         uint32_t priority = 1;
  29.         uint32_t mixin = 15; // random outs count
  30.         wallet->decrypt_keys("");
  31.         const account_keys account_keys = wallet->get_account().get_keys();
  32.         wallet->encrypt_keys("");
  33.         // we have to use pub_keys instead of pub_address
  34.         const account_public_address address{account_keys.m_account_address.m_spend_public_key, account_keys.m_account_address.m_view_public_key};
  35.  
  36.         // destinations - in this case only one
  37.         vector<tx_destination_entry> dsts;
  38.         dsts.emplace_back(amount, address, false);
  39.  
  40.         uint32_t account_index = 0;
  41.  
  42.         // extra data automatically filled
  43.         std::vector<uint8_t> extra;
  44.         set<uint32_t> subaddress_indices;
  45.         set<uint32_t> subtract_fee_from;
  46.  
  47.         // hot transaction creation
  48.         vector<wallet2::pending_tx> ptx_vector;
  49.         string error_msg;
  50.         wallet->decrypt_keys("");
  51.         ptx_vector = wallet->create_transactions_2(dsts, mixin, priority, extra, account_index, subaddress_indices, subtract_fee_from);
  52.         if(ptx_vector.empty()) {
  53.             cerr << "Failed to create transaction" << endl;
  54.             return 1;
  55.         }
  56.  
  57.  
  58.         wallet->commit_tx(ptx_vector);
  59.  
  60.         wallet->encrypt_keys("");
  61.  
  62.     } catch (const exception& e) {
  63.         cerr << "Error: " << e.what() << endl;
  64.         return 1;
  65.     }
  66.  
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment