mirror of
https://github.com/wownero/wownero-cpp.git
synced 2026-10-17 15:21:30 +02:00
refactor create_tx(), create_txs() with relay true|false
move base wallet implementations to monero_wallet.h
This commit is contained in:
@@ -275,7 +275,7 @@ namespace monero {
|
||||
|
||||
// set bool values
|
||||
if (m_is_miner_tx != boost::none) monero_utils::addJsonMember("isMinerTx", m_is_miner_tx.get(), allocator, root);
|
||||
if (m_do_not_relay != boost::none) monero_utils::addJsonMember("doNotRelay", m_do_not_relay.get(), allocator, root);
|
||||
if (m_relay != boost::none) monero_utils::addJsonMember("relay", m_relay.get(), allocator, root);
|
||||
if (m_is_relayed != boost::none) monero_utils::addJsonMember("isRelayed", m_is_relayed.get(), allocator, root);
|
||||
if (m_is_confirmed != boost::none) monero_utils::addJsonMember("isConfirmed", m_is_confirmed.get(), allocator, root);
|
||||
if (m_in_tx_pool != boost::none) monero_utils::addJsonMember("inTxPool", m_in_tx_pool.get(), allocator, root);
|
||||
@@ -305,7 +305,7 @@ namespace monero {
|
||||
else if (key == string("paymentId")) tx->m_payment_id = it->second.data();
|
||||
else if (key == string("fee")) tx->m_fee = it->second.get_value<uint64_t>();
|
||||
else if (key == string("mixin")) throw runtime_error("mixin deserialization not implemented");
|
||||
else if (key == string("doNotRelay")) tx->m_do_not_relay = it->second.get_value<bool>();
|
||||
else if (key == string("relay")) tx->m_relay = it->second.get_value<bool>();
|
||||
else if (key == string("isRelayed")) tx->m_is_relayed = it->second.get_value<bool>();
|
||||
else if (key == string("isConfirmed")) tx->m_is_confirmed = it->second.get_value<bool>();
|
||||
else if (key == string("inTxPool")) tx->m_in_tx_pool = it->second.get_value<bool>();
|
||||
@@ -347,7 +347,7 @@ namespace monero {
|
||||
tgt->m_payment_id = src->m_payment_id;
|
||||
tgt->m_fee = src->m_fee;
|
||||
tgt->m_ring_size = src->m_ring_size;
|
||||
tgt->m_do_not_relay = src->m_do_not_relay;
|
||||
tgt->m_relay = src->m_relay;
|
||||
tgt->m_is_relayed = src->m_is_relayed;
|
||||
tgt->m_is_confirmed = src->m_is_confirmed;
|
||||
tgt->m_in_tx_pool = src->m_in_tx_pool;
|
||||
@@ -427,7 +427,7 @@ namespace monero {
|
||||
m_fee = gen_utils::reconcile(m_fee, other->m_fee, "tx fee");
|
||||
m_ring_size = gen_utils::reconcile(m_ring_size, other->m_ring_size, "tx m_ring_size");
|
||||
m_is_confirmed = gen_utils::reconcile(m_is_confirmed, other->m_is_confirmed);
|
||||
m_do_not_relay = gen_utils::reconcile(m_do_not_relay, other->m_do_not_relay);
|
||||
m_relay = gen_utils::reconcile(m_relay, other->m_relay);
|
||||
m_is_relayed = gen_utils::reconcile(m_is_relayed, other->m_is_relayed);
|
||||
m_is_double_spend_seen = gen_utils::reconcile(m_is_double_spend_seen, other->m_is_double_spend_seen);
|
||||
m_key = gen_utils::reconcile(m_key, other->m_key);
|
||||
|
||||
@@ -176,7 +176,7 @@ namespace monero {
|
||||
boost::optional<string> m_payment_id;
|
||||
boost::optional<uint64_t> m_fee;
|
||||
boost::optional<uint32_t> m_ring_size;
|
||||
boost::optional<bool> m_do_not_relay;
|
||||
boost::optional<bool> m_relay;
|
||||
boost::optional<bool> m_is_relayed;
|
||||
boost::optional<bool> m_is_confirmed;
|
||||
boost::optional<bool> m_in_tx_pool;
|
||||
|
||||
+56
-127
@@ -763,54 +763,58 @@ namespace monero {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a transaction to transfer funds from this wallet according to the
|
||||
* given config. The transaction may be relayed later.
|
||||
* Create a transaction to transfer funds from this wallet.
|
||||
*
|
||||
* @param config configures the transaction to create
|
||||
* @return a tx set for the requested transaction if possible
|
||||
* @return the created transaction
|
||||
*/
|
||||
virtual monero_tx_set create_tx(monero_tx_config& config) {
|
||||
throw runtime_error("create_tx() not supported");
|
||||
virtual shared_ptr<monero_tx_wallet> create_tx(const monero_tx_config& config) {
|
||||
if (config.m_can_split != boost::none && config.m_can_split.get()) throw runtime_error("Cannot split transactions with create_tx(); use create_txs() instead");
|
||||
monero_tx_config config_copy = monero_tx_config(config);
|
||||
config_copy.m_can_split = false;
|
||||
return create_txs(config_copy)[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a transaction to transfers funds from this wallet to a destination address.
|
||||
* The transaction may be relayed later.
|
||||
*
|
||||
* @param accountIndex is the index of the account to withdraw funds from
|
||||
* @param address is the destination address to send funds to
|
||||
* @param amount is the amount being sent
|
||||
* @return a tx set for the requested transaction if possible
|
||||
*/
|
||||
virtual monero_tx_set create_tx(uint32_t account_index, string address, uint64_t amount) {
|
||||
throw runtime_error("create_tx() not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a transaction to transfers funds from this wallet to a destination address.
|
||||
* The transaction may be relayed later.
|
||||
*
|
||||
* @param accountIndex is the index of the account to withdraw funds from
|
||||
* @param address is the destination address to send funds to
|
||||
* @param amount is the amount being sent
|
||||
* @param priority is the send priority (default normal)
|
||||
* @return a tx set for the requested transaction if possible
|
||||
*/
|
||||
virtual monero_tx_set create_tx(int account_index, string address, uint64_t amount, monero_tx_priority priority) {
|
||||
throw runtime_error("create_tx() not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create one or more transactions to transfer funds from this wallet
|
||||
* according to the given config. The transactions may later be relayed.
|
||||
* Create one or more transactions to transfer funds from this wallet.
|
||||
*
|
||||
* @param config configures the transactions to create
|
||||
* @return a tx set for the requested transactions if possible
|
||||
* @return the created transactions
|
||||
*/
|
||||
virtual monero_tx_set create_txs(monero_tx_config& config) {
|
||||
virtual vector<shared_ptr<monero_tx_wallet>> create_txs(const monero_tx_config& config) {
|
||||
throw runtime_error("create_txs() not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sweep unlocked funds according to the given config.
|
||||
*
|
||||
* @param config is the sweep configuration
|
||||
* @return the created transactions
|
||||
*/
|
||||
virtual vector<shared_ptr<monero_tx_wallet>> sweep_unlocked(const monero_tx_config& config) {
|
||||
throw runtime_error("sweep_unlocked() not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sweep an output with a given key image.
|
||||
*
|
||||
* @param config configures the sweep transaction
|
||||
* @return the created transaction
|
||||
*/
|
||||
virtual shared_ptr<monero_tx_wallet> sweep_output(const monero_tx_config& config) {
|
||||
throw runtime_error("sweep_output() not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sweep all unmixable dust outputs back to the wallet to make them easier to spend and mix.
|
||||
*
|
||||
* @param relay specifies if the resulting transaction should be relayed (default false)
|
||||
* @return the created transactions
|
||||
*/
|
||||
virtual vector<shared_ptr<monero_tx_wallet>> sweep_dust(bool relay = false) {
|
||||
throw runtime_error("sweep_dust() not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Relay a transaction previously created without relaying.
|
||||
*
|
||||
@@ -818,7 +822,9 @@ namespace monero {
|
||||
* @return string is the hash of the relayed tx
|
||||
*/
|
||||
virtual string relay_tx(const string& tx_metadata) {
|
||||
throw runtime_error("relay_tx() not supported");
|
||||
vector<string> tx_metadatas;
|
||||
tx_metadatas.push_back(tx_metadata);
|
||||
return relay_txs(tx_metadatas)[0];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -828,7 +834,19 @@ namespace monero {
|
||||
* @return the hash of the relayed tx
|
||||
*/
|
||||
virtual string relay_tx(const monero_tx_wallet& tx) {
|
||||
throw runtime_error("relay_tx() not supported");
|
||||
return relay_tx(tx.m_metadata.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Relay previously created transactions.
|
||||
*
|
||||
* @param txs are the transactions to relay
|
||||
* @return the hashes of the relayed txs
|
||||
*/
|
||||
virtual vector<string> relay_txs(const vector<shared_ptr<monero_tx_wallet>>& txs) {
|
||||
vector<string> tx_hexes;
|
||||
for (const shared_ptr<monero_tx_wallet>& tx : txs) tx_hexes.push_back(tx->m_metadata.get());
|
||||
return relay_txs(tx_hexes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -841,95 +859,6 @@ namespace monero {
|
||||
throw runtime_error("relay_txs() not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Relay previously created transactions.
|
||||
*
|
||||
* @param txs are the transactions to relay
|
||||
* @return the hashes of the relayed txs
|
||||
*/
|
||||
virtual vector<string> relay_txs(const vector<shared_ptr<monero_tx_wallet>>& txs) {
|
||||
throw runtime_error("relay_txs() not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and relay a transaction to transfer funds from this wallet
|
||||
* according to the given config.
|
||||
*
|
||||
* @param config configures the transaction
|
||||
* @return a tx set with the requested transaction if possible
|
||||
*/
|
||||
virtual monero_tx_set send_tx(const monero_tx_config& config) {
|
||||
throw runtime_error("send_tx() not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and relay a transaction to transfers funds from this wallet to
|
||||
* a destination address.
|
||||
*
|
||||
* @param account_index is the index of the account to withdraw funds from
|
||||
* @param address is the destination address to send funds to
|
||||
* @param amount is the amount being sent
|
||||
* @return a tx set with the requested transaction if possible
|
||||
*/
|
||||
virtual monero_tx_set send_tx(uint32_t account_index, string address, uint64_t amount) {
|
||||
throw runtime_error("send_tx() not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and relay a transaction to transfers funds from this wallet to
|
||||
* a destination address.
|
||||
*
|
||||
* @param account_index is the index of the account to withdraw funds from
|
||||
* @param address is the destination address to send funds to
|
||||
* @param amount is the amount being sent
|
||||
* @param priority is the send priority (default normal)
|
||||
* @return a tx set with the requested transaction if possible
|
||||
*/
|
||||
virtual monero_tx_set send_tx(uint32_t account_index, string address, uint64_t amount, monero_tx_priority priority) {
|
||||
throw runtime_error("send_tx() not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create one or more transactions which transfer funds from this wallet to
|
||||
* one or more destinations depending on the given configuration.
|
||||
*
|
||||
* @param config configures the transaction
|
||||
* @return a tx set with the requested transactions if possible
|
||||
*/
|
||||
virtual monero_tx_set send_txs(const monero_tx_config& config) {
|
||||
throw runtime_error("send_txs() not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sweep unlocked funds according to the given config.
|
||||
*
|
||||
* @param config is the sweep configuration
|
||||
* @return the tx sets with the requested transactions
|
||||
*/
|
||||
virtual vector<monero_tx_set> sweep_unlocked(const monero_tx_config& config) {
|
||||
throw runtime_error("sweep_unlocked() not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sweep an output with a given key image.
|
||||
*
|
||||
* @param config configures the sweep transaction
|
||||
* @return a tx set with the requested transaction if possible
|
||||
*/
|
||||
virtual monero_tx_set sweep_output(const monero_tx_config& config) {
|
||||
throw runtime_error("sweep_output() not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sweep all unmixable dust outputs back to the wallet to make them easier to spend and mix.
|
||||
*
|
||||
* @param do_not_relay specifies if the resulting transaction should not be relayed (defaults to false i.e. relayed)
|
||||
* @return a tx set with the requested transactions if possible
|
||||
*/
|
||||
virtual monero_tx_set sweep_dust(bool do_not_relay = false) {
|
||||
throw runtime_error("sweep_dust() not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a tx set containing unsigned or multisig tx hex to a new tx set containing structured transactions.
|
||||
*
|
||||
|
||||
+505
-564
File diff suppressed because it is too large
Load Diff
+104
-114
@@ -172,119 +172,109 @@ namespace monero {
|
||||
/**
|
||||
* Supported wallet methods.
|
||||
*/
|
||||
bool is_watch_only() const { return m_w2->watch_only(); }
|
||||
void set_daemon_connection(const string& uri, const string& username = "", const string& password = "");
|
||||
void set_daemon_connection(const boost::optional<monero_rpc_connection>& connection);
|
||||
boost::optional<monero_rpc_connection> get_daemon_connection() const;
|
||||
bool is_connected() const;
|
||||
bool is_daemon_synced() const;
|
||||
bool is_daemon_trusted() const;
|
||||
bool is_synced() const;
|
||||
monero_version get_version() const;
|
||||
string get_path() const;
|
||||
monero_network_type get_network_type() const;
|
||||
string get_mnemonic() const;
|
||||
string get_mnemonic_language() const;
|
||||
string get_public_view_key() const;
|
||||
string get_private_view_key() const;
|
||||
string get_public_spend_key() const;
|
||||
string get_private_spend_key() const;
|
||||
string get_address(const uint32_t account_idx, const uint32_t subaddress_idx) const;
|
||||
monero_subaddress get_address_index(const string& address) const;
|
||||
monero_integrated_address get_integrated_address(const string& standard_address = "", const string& payment_id = "") const;
|
||||
monero_integrated_address decode_integrated_address(const string& integrated_address) const;
|
||||
uint64_t get_height() const;
|
||||
uint64_t get_sync_height() const;
|
||||
void set_sync_height(uint64_t sync_height);
|
||||
uint64_t get_daemon_height() const;
|
||||
uint64_t get_daemon_max_peer_height() const;
|
||||
void add_listener(monero_wallet_listener& listener);
|
||||
void remove_listener(monero_wallet_listener& listener);
|
||||
set<monero_wallet_listener*> get_listeners();
|
||||
monero_sync_result sync();
|
||||
monero_sync_result sync(monero_wallet_listener& listener);
|
||||
monero_sync_result sync(uint64_t start_height);
|
||||
monero_sync_result sync(uint64_t start_height, monero_wallet_listener& listener);
|
||||
void start_syncing();
|
||||
void stop_syncing();
|
||||
void rescan_spent();
|
||||
void rescan_blockchain();
|
||||
uint64_t get_balance() const;
|
||||
uint64_t get_balance(uint32_t account_idx) const;
|
||||
uint64_t get_balance(uint32_t account_idx, uint32_t subaddress_idx) const;
|
||||
uint64_t get_unlocked_balance() const;
|
||||
uint64_t get_unlocked_balance(uint32_t account_idx) const;
|
||||
uint64_t get_unlocked_balance(uint32_t account_idx, uint32_t subaddress_idx) const;
|
||||
vector<monero_account> get_accounts(bool include_subaddresses, const string& tag) const;
|
||||
monero_account get_account(const uint32_t account_idx, bool include_subaddresses) const;
|
||||
monero_account create_account(const string& label = "");
|
||||
vector<monero_subaddress> get_subaddresses(const uint32_t account_idx, const vector<uint32_t>& subaddress_indices) const;
|
||||
monero_subaddress create_subaddress(uint32_t account_idx, const string& label = "");
|
||||
vector<shared_ptr<monero_tx_wallet>> get_txs() const;
|
||||
vector<shared_ptr<monero_tx_wallet>> get_txs(const monero_tx_query& query) const;
|
||||
vector<shared_ptr<monero_tx_wallet>> get_txs(const monero_tx_query& query, vector<string>& missing_tx_hashes) const;
|
||||
vector<shared_ptr<monero_transfer>> get_transfers(const monero_transfer_query& query) const;
|
||||
vector<shared_ptr<monero_output_wallet>> get_outputs(const monero_output_query& query) const;
|
||||
string get_outputs_hex() const;
|
||||
int import_outputs_hex(const string& outputs_hex);
|
||||
vector<shared_ptr<monero_key_image>> get_key_images() const;
|
||||
shared_ptr<monero_key_image_import_result> import_key_images(const vector<shared_ptr<monero_key_image>>& key_images);
|
||||
monero_tx_set create_tx(monero_tx_config& config);
|
||||
monero_tx_set create_tx(uint32_t account_index, string address, uint64_t amount);
|
||||
monero_tx_set create_tx(int account_index, string address, uint64_t amount, monero_tx_priority priority);
|
||||
monero_tx_set create_txs(monero_tx_config& config);
|
||||
string relay_tx(const string& tx_metadata);
|
||||
string relay_tx(const monero_tx_wallet& tx);
|
||||
vector<string> relay_txs(const vector<string>& tx_metadatas);
|
||||
vector<string> relay_txs(const vector<shared_ptr<monero_tx_wallet>>& txs);
|
||||
monero_tx_set send_tx(const monero_tx_config& config);
|
||||
monero_tx_set send_tx(uint32_t account_index, string address, uint64_t amount);
|
||||
monero_tx_set send_tx(uint32_t account_index, string address, uint64_t amount, monero_tx_priority priority);
|
||||
monero_tx_set send_txs(const monero_tx_config& config);
|
||||
vector<monero_tx_set> sweep_unlocked(const monero_tx_config& config);
|
||||
monero_tx_set sweep_output(const monero_tx_config& config);
|
||||
monero_tx_set sweep_dust(bool do_not_relay = false);
|
||||
monero_tx_set parse_tx_set(const monero_tx_set& tx_set);
|
||||
string sign_txs(const string& unsigned_tx_hex);
|
||||
vector<string> submit_txs(const string& signed_tx_hex);
|
||||
string sign_message(const string& msg) const;
|
||||
bool verify_message(const string& msg, const string& address, const string& signature) const;
|
||||
string get_tx_key(const string& tx_hash) const;
|
||||
shared_ptr<monero_check_tx> check_tx_key(const string& tx_hash, const string& txKey, const string& address) const;
|
||||
string get_tx_proof(const string& tx_hash, const string& address, const string& message) const;
|
||||
shared_ptr<monero_check_tx> check_tx_proof(const string& tx_hash, const string& address, const string& message, const string& signature) const;
|
||||
string get_spend_proof(const string& tx_hash, const string& message) const;
|
||||
bool check_spend_proof(const string& tx_hash, const string& message, const string& signature) const;
|
||||
string get_reserve_proof_wallet(const string& message) const;
|
||||
string get_reserve_proof_account(uint32_t account_idx, uint64_t amount, const string& message) const;
|
||||
shared_ptr<monero_check_reserve> check_reserve_proof(const string& address, const string& message, const string& signature) const;
|
||||
string get_tx_note(const string& tx_hash) const;
|
||||
vector<string> get_tx_notes(const vector<string>& tx_hashes) const;
|
||||
void set_tx_note(const string& tx_hash, const string& note);
|
||||
void set_tx_notes(const vector<string>& tx_hashes, const vector<string>& notes);
|
||||
vector<monero_address_book_entry> get_address_book_entries(const vector<uint64_t>& indices) const;
|
||||
uint64_t add_address_book_entry(const string& address, const string& description);
|
||||
void edit_address_book_entry(uint64_t index, bool set_address, const string& address, bool set_description, const string& description);
|
||||
void delete_address_book_entry(uint64_t index);
|
||||
string create_payment_uri(const monero_tx_config& config) const;
|
||||
shared_ptr<monero_tx_config> parse_payment_uri(const string& uri) const;
|
||||
bool get_attribute(const string& key, string& value) const;
|
||||
void set_attribute(const string& key, const string& val);
|
||||
void start_mining(boost::optional<uint64_t> num_threads, boost::optional<bool> background_mining, boost::optional<bool> ignore_battery);
|
||||
void stop_mining();
|
||||
uint64_t wait_for_next_block();
|
||||
bool is_multisig_import_needed() const;
|
||||
monero_multisig_info get_multisig_info();
|
||||
string prepare_multisig();
|
||||
monero_multisig_init_result make_multisig(const vector<string>& multisig_hexes, int threshold, const string& password);
|
||||
monero_multisig_init_result exchange_multisig_keys(const vector<string>& mutisig_hexes, const string& password);
|
||||
string get_multisig_hex();
|
||||
int import_multisig_hex(const vector<string>& multisig_hexes);
|
||||
monero_multisig_sign_result sign_multisig_tx_hex(const string& multisig_tx_hex);
|
||||
vector<string> submit_multisig_tx_hex(const string& signed_multisig_tx_hex);
|
||||
void save();
|
||||
void move_to(string path, string password);
|
||||
void close(bool save = false);
|
||||
bool is_watch_only() const override { return m_w2->watch_only(); }
|
||||
void set_daemon_connection(const string& uri, const string& username = "", const string& password = "") override;
|
||||
void set_daemon_connection(const boost::optional<monero_rpc_connection>& connection) override;
|
||||
boost::optional<monero_rpc_connection> get_daemon_connection() const override;
|
||||
bool is_connected() const override;
|
||||
bool is_daemon_synced() const override;
|
||||
bool is_daemon_trusted() const override;
|
||||
bool is_synced() const override;
|
||||
monero_version get_version() const override;
|
||||
string get_path() const override;
|
||||
monero_network_type get_network_type() const override;
|
||||
string get_mnemonic() const override;
|
||||
string get_mnemonic_language() const override;
|
||||
string get_public_view_key() const override;
|
||||
string get_private_view_key() const override;
|
||||
string get_public_spend_key() const override;
|
||||
string get_private_spend_key() const override;
|
||||
string get_address(const uint32_t account_idx, const uint32_t subaddress_idx) const override;
|
||||
monero_subaddress get_address_index(const string& address) const override;
|
||||
monero_integrated_address get_integrated_address(const string& standard_address = "", const string& payment_id = "") const override;
|
||||
monero_integrated_address decode_integrated_address(const string& integrated_address) const override;
|
||||
uint64_t get_height() const override;
|
||||
uint64_t get_sync_height() const override;
|
||||
void set_sync_height(uint64_t sync_height) override;
|
||||
uint64_t get_daemon_height() const override;
|
||||
uint64_t get_daemon_max_peer_height() const override;
|
||||
void add_listener(monero_wallet_listener& listener) override;
|
||||
void remove_listener(monero_wallet_listener& listener) override;
|
||||
set<monero_wallet_listener*> get_listeners() override;
|
||||
monero_sync_result sync() override;
|
||||
monero_sync_result sync(monero_wallet_listener& listener) override;
|
||||
monero_sync_result sync(uint64_t start_height) override;
|
||||
monero_sync_result sync(uint64_t start_height, monero_wallet_listener& listener) override;
|
||||
void start_syncing() override;
|
||||
void stop_syncing() override;
|
||||
void rescan_spent() override;
|
||||
void rescan_blockchain() override;
|
||||
uint64_t get_balance() const override;
|
||||
uint64_t get_balance(uint32_t account_idx) const override;
|
||||
uint64_t get_balance(uint32_t account_idx, uint32_t subaddress_idx) const override;
|
||||
uint64_t get_unlocked_balance() const override;
|
||||
uint64_t get_unlocked_balance(uint32_t account_idx) const override;
|
||||
uint64_t get_unlocked_balance(uint32_t account_idx, uint32_t subaddress_idx) const override;
|
||||
vector<monero_account> get_accounts(bool include_subaddresses, const string& tag) const override;
|
||||
monero_account get_account(const uint32_t account_idx, bool include_subaddresses) const override;
|
||||
monero_account create_account(const string& label = "") override;
|
||||
vector<monero_subaddress> get_subaddresses(const uint32_t account_idx, const vector<uint32_t>& subaddress_indices) const override;
|
||||
monero_subaddress create_subaddress(uint32_t account_idx, const string& label = "") override;
|
||||
vector<shared_ptr<monero_tx_wallet>> get_txs() const override;
|
||||
vector<shared_ptr<monero_tx_wallet>> get_txs(const monero_tx_query& query) const override;
|
||||
vector<shared_ptr<monero_tx_wallet>> get_txs(const monero_tx_query& query, vector<string>& missing_tx_hashes) const override;
|
||||
vector<shared_ptr<monero_transfer>> get_transfers(const monero_transfer_query& query) const override;
|
||||
vector<shared_ptr<monero_output_wallet>> get_outputs(const monero_output_query& query) const override;
|
||||
string get_outputs_hex() const override;
|
||||
int import_outputs_hex(const string& outputs_hex) override;
|
||||
vector<shared_ptr<monero_key_image>> get_key_images() const override;
|
||||
shared_ptr<monero_key_image_import_result> import_key_images(const vector<shared_ptr<monero_key_image>>& key_images) override;
|
||||
vector<shared_ptr<monero_tx_wallet>> create_txs(const monero_tx_config& config) override;
|
||||
vector<shared_ptr<monero_tx_wallet>> sweep_unlocked(const monero_tx_config& config) override;
|
||||
shared_ptr<monero_tx_wallet> sweep_output(const monero_tx_config& config) override;
|
||||
vector<shared_ptr<monero_tx_wallet>> sweep_dust(bool relay = false) override;
|
||||
vector<string> relay_txs(const vector<string>& tx_metadatas) override;
|
||||
monero_tx_set parse_tx_set(const monero_tx_set& tx_set) override;
|
||||
string sign_txs(const string& unsigned_tx_hex) override;
|
||||
vector<string> submit_txs(const string& signed_tx_hex) override;
|
||||
string sign_message(const string& msg) const override;
|
||||
bool verify_message(const string& msg, const string& address, const string& signature) const override;
|
||||
string get_tx_key(const string& tx_hash) const override;
|
||||
shared_ptr<monero_check_tx> check_tx_key(const string& tx_hash, const string& txKey, const string& address) const override;
|
||||
string get_tx_proof(const string& tx_hash, const string& address, const string& message) const override;
|
||||
shared_ptr<monero_check_tx> check_tx_proof(const string& tx_hash, const string& address, const string& message, const string& signature) const override;
|
||||
string get_spend_proof(const string& tx_hash, const string& message) const override;
|
||||
bool check_spend_proof(const string& tx_hash, const string& message, const string& signature) const override;
|
||||
string get_reserve_proof_wallet(const string& message) const override;
|
||||
string get_reserve_proof_account(uint32_t account_idx, uint64_t amount, const string& message) const override;
|
||||
shared_ptr<monero_check_reserve> check_reserve_proof(const string& address, const string& message, const string& signature) const override;
|
||||
string get_tx_note(const string& tx_hash) const override;
|
||||
vector<string> get_tx_notes(const vector<string>& tx_hashes) const override;
|
||||
void set_tx_note(const string& tx_hash, const string& note) override;
|
||||
void set_tx_notes(const vector<string>& tx_hashes, const vector<string>& notes) override;
|
||||
vector<monero_address_book_entry> get_address_book_entries(const vector<uint64_t>& indices) const override;
|
||||
uint64_t add_address_book_entry(const string& address, const string& description) override;
|
||||
void edit_address_book_entry(uint64_t index, bool set_address, const string& address, bool set_description, const string& description) override;
|
||||
void delete_address_book_entry(uint64_t index) override;
|
||||
string create_payment_uri(const monero_tx_config& config) const override;
|
||||
shared_ptr<monero_tx_config> parse_payment_uri(const string& uri) const override;
|
||||
bool get_attribute(const string& key, string& value) const override;
|
||||
void set_attribute(const string& key, const string& val) override;
|
||||
void start_mining(boost::optional<uint64_t> num_threads, boost::optional<bool> background_mining, boost::optional<bool> ignore_battery) override;
|
||||
void stop_mining() override;
|
||||
uint64_t wait_for_next_block() override;
|
||||
bool is_multisig_import_needed() const override;
|
||||
monero_multisig_info get_multisig_info() override;
|
||||
string prepare_multisig() override;
|
||||
monero_multisig_init_result make_multisig(const vector<string>& multisig_hexes, int threshold, const string& password) override;
|
||||
monero_multisig_init_result exchange_multisig_keys(const vector<string>& mutisig_hexes, const string& password) override;
|
||||
string get_multisig_hex() override;
|
||||
int import_multisig_hex(const vector<string>& multisig_hexes) override;
|
||||
monero_multisig_sign_result sign_multisig_tx_hex(const string& multisig_tx_hex) override;
|
||||
vector<string> submit_multisig_tx_hex(const string& signed_multisig_tx_hex) override;
|
||||
void save() override;
|
||||
void move_to(string path, string password) override;
|
||||
void close(bool save = false) override;
|
||||
|
||||
/**
|
||||
* Wallet import and export using buffers and not the file system.
|
||||
@@ -302,7 +292,7 @@ namespace monero {
|
||||
|
||||
void init_common();
|
||||
vector<monero_subaddress> get_subaddresses_aux(uint32_t account_idx, const vector<uint32_t>& subaddress_indices, const vector<tools::wallet2::transfer_details>& transfers) const;
|
||||
monero_tx_set sweep_account(const monero_tx_config& config); // sweeps unlocked funds within an account; private helper to sweep_unlocked()
|
||||
vector<shared_ptr<monero_tx_wallet>> sweep_account(const monero_tx_config& config); // sweeps unlocked funds within an account; private helper to sweep_unlocked()
|
||||
|
||||
// blockchain sync management
|
||||
mutable std::atomic<bool> m_is_synced; // whether or not wallet is synced
|
||||
|
||||
@@ -116,24 +116,24 @@ namespace monero {
|
||||
/**
|
||||
* Supported wallet methods.
|
||||
*/
|
||||
bool is_watch_only() const { return m_is_watch_only; }
|
||||
monero_version get_version() const;
|
||||
monero_network_type get_network_type() const { return m_network_type; }
|
||||
string get_mnemonic() const { return m_mnemonic; }
|
||||
string get_mnemonic_language() const { return m_language; }
|
||||
string get_private_view_key() const { return m_prv_view_key; }
|
||||
string get_private_spend_key() const { return m_prv_spend_key; }
|
||||
string get_public_view_key() const { return m_pub_view_key; }
|
||||
string get_public_spend_key() const { return m_pub_spend_key; }
|
||||
string get_primary_address() const { return m_primary_address; }
|
||||
string get_address(const uint32_t account_idx, const uint32_t subaddress_idx) const;
|
||||
monero_integrated_address get_integrated_address(const string& standard_address = "", const string& payment_id = "") const;
|
||||
monero_integrated_address decode_integrated_address(const string& integrated_address) const;
|
||||
monero_account get_account(const uint32_t account_idx, bool include_subaddresses) const;
|
||||
vector<monero_subaddress> get_subaddresses(const uint32_t account_idx, const vector<uint32_t>& subaddress_indices) const;
|
||||
string sign_message(const string& msg) const;
|
||||
bool verify_message(const string& msg, const string& address, const string& signature) const;
|
||||
void close(bool save = false);
|
||||
bool is_watch_only() const override { return m_is_watch_only; }
|
||||
monero_version get_version() const override;
|
||||
monero_network_type get_network_type() const override { return m_network_type; }
|
||||
string get_mnemonic() const override { return m_mnemonic; }
|
||||
string get_mnemonic_language() const override { return m_language; }
|
||||
string get_private_view_key() const override { return m_prv_view_key; }
|
||||
string get_private_spend_key() const override { return m_prv_spend_key; }
|
||||
string get_public_view_key() const override { return m_pub_view_key; }
|
||||
string get_public_spend_key() const override { return m_pub_spend_key; }
|
||||
string get_primary_address() const override { return m_primary_address; }
|
||||
string get_address(const uint32_t account_idx, const uint32_t subaddress_idx) const override;
|
||||
monero_integrated_address get_integrated_address(const string& standard_address = "", const string& payment_id = "") const override;
|
||||
monero_integrated_address decode_integrated_address(const string& integrated_address) const override;
|
||||
monero_account get_account(const uint32_t account_idx, bool include_subaddresses) const override;
|
||||
vector<monero_subaddress> get_subaddresses(const uint32_t account_idx, const vector<uint32_t>& subaddress_indices) const override;
|
||||
string sign_message(const string& msg) const override;
|
||||
bool verify_message(const string& msg, const string& address, const string& signature) const override;
|
||||
void close(bool save = false) override;
|
||||
|
||||
// --------------------------------- PRIVATE --------------------------------
|
||||
|
||||
|
||||
@@ -399,7 +399,7 @@ namespace monero {
|
||||
if (m_payment_id != boost::none && m_payment_id != tx->m_payment_id) return false;
|
||||
if (m_is_confirmed != boost::none && m_is_confirmed != tx->m_is_confirmed) return false;
|
||||
if (m_in_tx_pool != boost::none && m_in_tx_pool != tx->m_in_tx_pool) return false;
|
||||
if (m_do_not_relay != boost::none && m_do_not_relay != tx->m_do_not_relay) return false;
|
||||
if (m_relay != boost::none && m_relay != tx->m_relay) return false;
|
||||
if (m_is_failed != boost::none && m_is_failed != tx->m_is_failed) return false;
|
||||
if (m_is_miner_tx != boost::none && m_is_miner_tx != tx->m_is_miner_tx) return false;
|
||||
if (m_is_locked != boost::none && m_is_locked != tx->m_is_locked) return false;
|
||||
@@ -1039,9 +1039,11 @@ namespace monero {
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------- MONERO SEND REQUEST ----------------------------
|
||||
// --------------------------- MONERO TX CONFIG -----------------------------
|
||||
|
||||
monero_tx_config::monero_tx_config(const monero_tx_config& config) {
|
||||
m_address = config.m_address;
|
||||
m_amount = config.m_amount;
|
||||
if (config.m_destinations.size() > 0) {
|
||||
for (const shared_ptr<monero_destination>& destination : config.m_destinations) {
|
||||
m_destinations.push_back(destination->copy(destination, make_shared<monero_destination>()));
|
||||
@@ -1055,7 +1057,7 @@ namespace monero {
|
||||
m_subaddress_indices = config.m_subaddress_indices;
|
||||
m_unlock_time = config.m_unlock_time;
|
||||
m_can_split = config.m_can_split;
|
||||
m_do_not_relay = config.m_do_not_relay;
|
||||
m_relay = config.m_relay;
|
||||
m_note = config.m_note;
|
||||
m_recipient_name = config.m_recipient_name;
|
||||
m_below_amount = config.m_below_amount;
|
||||
@@ -1063,6 +1065,10 @@ namespace monero {
|
||||
m_key_image = config.m_key_image;
|
||||
}
|
||||
|
||||
monero_tx_config monero_tx_config::copy() const {
|
||||
return monero_tx_config(*this);
|
||||
}
|
||||
|
||||
rapidjson::Value monero_tx_config::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const {
|
||||
|
||||
// create root
|
||||
@@ -1085,7 +1091,7 @@ namespace monero {
|
||||
|
||||
// set bool values
|
||||
if (m_can_split != boost::none) monero_utils::addJsonMember("canSplit", m_can_split.get(), allocator, root);
|
||||
if (m_do_not_relay != boost::none) monero_utils::addJsonMember("doNotRelay", m_do_not_relay.get(), allocator, root);
|
||||
if (m_relay != boost::none) monero_utils::addJsonMember("relay", m_relay.get(), allocator, root);
|
||||
if (m_sweep_each_subaddress != boost::none) monero_utils::addJsonMember("sweepEachSubaddress", m_sweep_each_subaddress.get(), allocator, root);
|
||||
|
||||
// set sub-arrays
|
||||
@@ -1130,7 +1136,7 @@ namespace monero {
|
||||
else if (key == string("subaddressIndices")) for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) config->m_subaddress_indices.push_back(it2->second.get_value<uint32_t>());
|
||||
else if (key == string("unlockTime")) config->m_unlock_time = it->second.get_value<uint64_t>();
|
||||
else if (key == string("canSplit")) config->m_can_split = it->second.get_value<bool>();
|
||||
else if (key == string("doNotRelay")) config->m_do_not_relay = it->second.get_value<bool>();
|
||||
else if (key == string("relay")) config->m_relay = it->second.get_value<bool>();
|
||||
else if (key == string("note")) config->m_note = it->second.data();
|
||||
else if (key == string("recipientName")) config->m_recipient_name = it->second.data();
|
||||
else if (key == string("belowAmount")) config->m_below_amount = it->second.get_value<uint64_t>();
|
||||
@@ -1141,8 +1147,18 @@ namespace monero {
|
||||
return config;
|
||||
}
|
||||
|
||||
monero_tx_config monero_tx_config::copy() const {
|
||||
return monero_tx_config(*this);
|
||||
vector<shared_ptr<monero_destination>> monero_tx_config::get_normalized_destinations() const {
|
||||
if (m_address == boost::none && m_amount == boost::none) return m_destinations;
|
||||
else if (m_destinations.empty()) {
|
||||
vector<shared_ptr<monero_destination>> destinations;
|
||||
destinations.push_back(std::make_shared<monero_destination>(m_address, m_amount));
|
||||
return destinations;
|
||||
} else {
|
||||
if (m_destinations.size() > 1) throw runtime_error("Invalid tx configuration: single destination address/amount incompatible with multiple destinations");
|
||||
if (m_address != m_destinations[0]->m_address) throw runtime_error("Invalid tx configuration: single destination address does not match first destination address");
|
||||
if (m_amount != m_destinations[0]->m_amount) throw runtime_error("Invalid tx configuration: single destination amount does not match first destination amount");
|
||||
return m_destinations;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------- MONERO INTEGRATED ADDRESS -------------------------
|
||||
|
||||
@@ -112,8 +112,7 @@ namespace monero {
|
||||
boost::optional<string> m_address;
|
||||
boost::optional<uint64_t> m_amount;
|
||||
|
||||
monero_destination() {}
|
||||
monero_destination(const string& address, uint64_t amount) : m_address(address), m_amount(amount) {}
|
||||
monero_destination(boost::optional<string> address = boost::none, boost::optional<uint64_t> amount = boost::none) : m_address(address), m_amount(amount) {}
|
||||
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
|
||||
static void from_property_tree(const boost::property_tree::ptree& node, const shared_ptr<monero_destination>& destination);
|
||||
shared_ptr<monero_destination> copy(const shared_ptr<monero_destination>& src, const shared_ptr<monero_destination>& tgt) const;
|
||||
@@ -339,6 +338,8 @@ namespace monero {
|
||||
* Configures a transaction to send, sweep, or create a payment URI.
|
||||
*/
|
||||
struct monero_tx_config : public serializable_struct {
|
||||
boost::optional<string> m_address;
|
||||
boost::optional<uint64_t> m_amount;
|
||||
vector<shared_ptr<monero_destination>> m_destinations;
|
||||
boost::optional<string> m_payment_id;
|
||||
boost::optional<monero_tx_priority> m_priority;
|
||||
@@ -348,7 +349,7 @@ namespace monero {
|
||||
vector<uint32_t> m_subaddress_indices;
|
||||
boost::optional<uint64_t> m_unlock_time;
|
||||
boost::optional<bool> m_can_split;
|
||||
boost::optional<bool> m_do_not_relay;
|
||||
boost::optional<bool> m_relay;
|
||||
boost::optional<string> m_note;
|
||||
boost::optional<string> m_recipient_name;
|
||||
boost::optional<uint64_t> m_below_amount;
|
||||
@@ -357,9 +358,10 @@ namespace monero {
|
||||
|
||||
monero_tx_config() {}
|
||||
monero_tx_config(const monero_tx_config& config);
|
||||
monero_tx_config copy() const;
|
||||
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
|
||||
static shared_ptr<monero_tx_config> deserialize(const string& config_json);
|
||||
monero_tx_config copy() const;
|
||||
vector<shared_ptr<monero_destination>> get_normalized_destinations() const;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
+28
-17
@@ -22,13 +22,16 @@ int main(int argc, const char* argv[]) {
|
||||
// create a wallet from a mnemonic phrase
|
||||
string mnemonic = "hefty value later extra artistic firm radar yodel talent future fungal nutshell because sanity awesome nail unjustly rage unafraid cedar delayed thumbs comb custom sanity";
|
||||
monero_wallet* wallet_restored = monero_wallet_core::create_wallet_from_mnemonic(
|
||||
"MyWalletRestored", // wallet path and name
|
||||
"supersecretpassword123", // wallet password
|
||||
monero_network_type::STAGENET, // network type
|
||||
mnemonic, // mnemonic phrase
|
||||
monero_rpc_connection(string("http://localhost:38081")), // daemon connection
|
||||
380104, // restore height
|
||||
"" // seed offset
|
||||
"MyWalletRestored", // wallet path and name
|
||||
"supersecretpassword123", // wallet password
|
||||
monero_network_type::STAGENET, // network type
|
||||
mnemonic, // mnemonic phrase
|
||||
monero_rpc_connection( // daemon connection
|
||||
string("http://localhost:38081"),
|
||||
string("superuser"),
|
||||
string("abctesting123")),
|
||||
380104, // restore height
|
||||
"" // seed offset
|
||||
);
|
||||
|
||||
// synchronize the wallet and receive progress notifications
|
||||
@@ -70,12 +73,14 @@ int main(int argc, const char* argv[]) {
|
||||
|
||||
// create and sync a new wallet with a random mnemonic phrase
|
||||
monero_wallet* wallet_random = monero_wallet_core::create_wallet_random(
|
||||
"MyWalletRandom", // wallet path and name
|
||||
"supersecretpassword123", // wallet password
|
||||
monero_network_type::STAGENET, // network type
|
||||
monero_rpc_connection(string("http://localhost:38081")), // daemon connection
|
||||
"English"
|
||||
);
|
||||
"MyWalletRandom", // wallet path and name
|
||||
"supersecretpassword123", // wallet password
|
||||
monero_network_type::STAGENET, // network type
|
||||
monero_rpc_connection( // daemon connection
|
||||
string("http://localhost:38081"),
|
||||
string("superuser"),
|
||||
string("abctesting123")),
|
||||
"English");
|
||||
wallet_random->sync();
|
||||
|
||||
// continuously synchronize the wallet in the background
|
||||
@@ -100,7 +105,12 @@ int main(int argc, const char* argv[]) {
|
||||
wallet_random->add_listener(my_listener);
|
||||
|
||||
// send funds from the restored wallet to the random wallet
|
||||
shared_ptr<monero_tx_wallet> sent_tx = wallet_restored->send_tx(0, wallet_random->get_address(1, 0), 50000).m_txs[0];
|
||||
monero_tx_config config;
|
||||
config.m_account_index = 0;
|
||||
config.m_address = wallet_random->get_address(1, 0);
|
||||
config.m_amount = 50000;
|
||||
config.m_relay = true;
|
||||
shared_ptr<monero_tx_wallet> sent_tx = wallet_restored->create_tx(config);
|
||||
bool in_pool = sent_tx->m_in_tx_pool.get(); // true
|
||||
|
||||
// mine with 7 threads to push the network along
|
||||
@@ -115,20 +125,21 @@ int main(int argc, const char* argv[]) {
|
||||
// stop mining
|
||||
wallet_restored->stop_mining();
|
||||
|
||||
// create a request to send funds to multiple destinations in the random wallet
|
||||
monero_tx_config config = monero_tx_config();
|
||||
// create config to send funds to multiple destinations in the random wallet
|
||||
config = monero_tx_config();
|
||||
config.m_account_index = 1; // withdraw funds from this account
|
||||
config.m_subaddress_indices = vector<uint32_t>();
|
||||
config.m_subaddress_indices.push_back(0);
|
||||
config.m_subaddress_indices.push_back(1); // withdraw funds from these subaddresses within the account
|
||||
config.m_priority = monero_tx_priority::UNIMPORTANT; // no rush
|
||||
config.m_relay = true;
|
||||
vector<shared_ptr<monero_destination>> destinations; // specify the recipients and their amounts
|
||||
destinations.push_back(make_shared<monero_destination>(wallet_random->get_address(1, 0), 50000));
|
||||
destinations.push_back(make_shared<monero_destination>(wallet_random->get_address(2, 0), 50000));
|
||||
config.m_destinations = destinations;
|
||||
|
||||
// create the transaction, confirm with the user, and relay to the network
|
||||
shared_ptr<monero_tx_wallet> created_tx = wallet_restored->create_tx(config).m_txs[0];
|
||||
shared_ptr<monero_tx_wallet> created_tx = wallet_restored->create_tx(config);
|
||||
uint64_t fee = created_tx->m_fee.get(); // "Are you sure you want to send ...?"
|
||||
wallet_restored->relay_tx(*created_tx); // submit the transaction to the Monero network which will notify the recipient wallet
|
||||
|
||||
|
||||
Reference in New Issue
Block a user