Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <wallet/wallet2.h>
- #include <iostream>
- #include <string>
- #include <memory>
- using namespace std;
- using namespace cryptonote;
- using namespace tools;
- int main() {
- try {
- constexpr network_type nettype = TESTNET;
- unique_ptr<wallet2> wallet(new wallet2(nettype));
- const string wallet_path = "/home/adam/Monero/wallets/wallet_2";
- const string password;
- const string daemon_address = "127.0.0.1:28081";
- wallet->load(wallet_path, password);
- wallet->init("");
- wallet->set_daemon(daemon_address);
- wallet->refresh(true);
- cout << "Current balance: " << wallet->balance(0, true) << endl;
- cout << "Unlocked balance: " << wallet->unlocked_balance(0, true) << endl;
- string recipent_address = "9x54DBt6ooEJY4GTmt4MCXeBJYfwFtRRr975DRiLGM3LVyJuudHDnzYLnUcVzvxi8xgBfY7fMXArTUPLuTxbnYbv3P29ihL";
- constexpr uint64_t amount = 250000000000;
- uint32_t priority = 1;
- uint32_t mixin = 15; // random outs count
- wallet->decrypt_keys("");
- const account_keys account_keys = wallet->get_account().get_keys();
- wallet->encrypt_keys("");
- // we have to use pub_keys instead of pub_address
- const account_public_address address{account_keys.m_account_address.m_spend_public_key, account_keys.m_account_address.m_view_public_key};
- // destinations - in this case only one
- vector<tx_destination_entry> dsts;
- dsts.emplace_back(amount, address, false);
- uint32_t account_index = 0;
- // extra data automatically filled
- std::vector<uint8_t> extra;
- set<uint32_t> subaddress_indices;
- set<uint32_t> subtract_fee_from;
- // hot transaction creation
- vector<wallet2::pending_tx> ptx_vector;
- string error_msg;
- wallet->decrypt_keys("");
- ptx_vector = wallet->create_transactions_2(dsts, mixin, priority, extra, account_index, subaddress_indices, subtract_fee_from);
- if(ptx_vector.empty()) {
- cerr << "Failed to create transaction" << endl;
- return 1;
- }
- wallet->commit_tx(ptx_vector);
- wallet->encrypt_keys("");
- } catch (const exception& e) {
- cerr << "Error: " << e.what() << endl;
- return 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment