Monero C++ Library
monero_wallet_model.h
1
53#pragma once
54
55#include "daemon/monero_daemon_model.h"
56
57using namespace monero;
58
62namespace monero {
63
68 boost::optional<std::string> m_path;
69 boost::optional<std::string> m_password;
70 boost::optional<monero_network_type> m_network_type;
71 boost::optional<std::string> m_server_uri;
72 boost::optional<std::string> m_server_username;
73 boost::optional<std::string> m_server_password;
74 boost::optional<std::string> m_seed;
75 boost::optional<std::string> m_seed_offset;
76 boost::optional<std::string> m_primary_address;
77 boost::optional<std::string> m_private_view_key;
78 boost::optional<std::string> m_private_spend_key;
79 boost::optional<uint64_t> m_restore_height;
80 boost::optional<std::string> m_language;
81 boost::optional<bool> m_save_current;
82 boost::optional<uint64_t> m_account_lookahead;
83 boost::optional<uint64_t> m_subaddress_lookahead;
84 boost::optional<bool> m_is_multisig;
85
88 monero_wallet_config copy() const;
89 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
90 static std::shared_ptr<monero_wallet_config> deserialize(const std::string& config_json);
91 void set_server(const monero_rpc_connection& server);
92 monero_rpc_connection get_server() const;
93 };
94
99 uint64_t m_num_blocks_fetched;
100 bool m_received_money;
102 monero_sync_result(const uint64_t num_blocks_fetched, const bool received_money) : m_num_blocks_fetched(num_blocks_fetched), m_received_money(received_money) {}
103
104 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
105 };
106
111 boost::optional<uint32_t> m_account_index;
112 boost::optional<uint32_t> m_index;
113 boost::optional<std::string> m_address;
114 boost::optional<std::string> m_label;
115 boost::optional<uint64_t> m_balance;
116 boost::optional<uint64_t> m_unlocked_balance;
117 boost::optional<uint64_t> m_num_unspent_outputs;
118 boost::optional<bool> m_is_used;
119 boost::optional<uint64_t> m_num_blocks_to_unlock;
120
121 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
122 };
123
128 boost::optional<uint32_t> m_index;
129 boost::optional<std::string> m_primary_address;
130 boost::optional<uint64_t> m_balance;
131 boost::optional<uint64_t> m_unlocked_balance;
132 boost::optional<std::string> m_tag;
133 std::vector<monero_subaddress> m_subaddresses;
134
135 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
136 };
137
142 boost::optional<std::string> m_address;
143 boost::optional<uint64_t> m_amount;
144
145 monero_destination(boost::optional<std::string> address = boost::none, boost::optional<uint64_t> amount = boost::none) : m_address(address), m_amount(amount) {}
146 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
147 static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_destination>& destination);
148 std::shared_ptr<monero_destination> copy(const std::shared_ptr<monero_destination>& src, const std::shared_ptr<monero_destination>& tgt) const;
149 };
150
151 // forward declarations
152 struct monero_tx_wallet;
153 struct monero_tx_query;
154 struct monero_tx_set;
155
162 std::shared_ptr<monero_tx_wallet> m_tx;
163 boost::optional<uint64_t> m_amount;
164 boost::optional<uint32_t> m_account_index;
165
166 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
167 static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_transfer>& transfer);
168 virtual boost::optional<bool> is_incoming() const = 0; // derived class must implement
169 std::shared_ptr<monero_transfer> copy(const std::shared_ptr<monero_transfer>& src, const std::shared_ptr<monero_transfer>& tgt) const;
170 boost::optional<bool> is_outgoing() const {
171 if (is_incoming() == boost::none) return boost::none;
172 return !(*is_incoming());
173 }
174 void merge(const std::shared_ptr<monero_transfer>& self, const std::shared_ptr<monero_transfer>& other);
175 };
176
181 boost::optional<uint32_t> m_subaddress_index;
182 boost::optional<std::string> m_address;
183 boost::optional<uint64_t> m_num_suggested_confirmations;
184
185 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
186 std::shared_ptr<monero_incoming_transfer> copy(const std::shared_ptr<monero_transfer>& src, const std::shared_ptr<monero_transfer>& tgt) const;
187 std::shared_ptr<monero_incoming_transfer> copy(const std::shared_ptr<monero_incoming_transfer>& src, const std::shared_ptr<monero_incoming_transfer>& tgt) const;
188 boost::optional<bool> is_incoming() const;
189 void merge(const std::shared_ptr<monero_transfer>& self, const std::shared_ptr<monero_transfer>& other);
190 void merge(const std::shared_ptr<monero_incoming_transfer>& self, const std::shared_ptr<monero_incoming_transfer>& other);
191 };
192
197 std::vector<uint32_t> m_subaddress_indices;
198 std::vector<std::string> m_addresses;
199 std::vector<std::shared_ptr<monero_destination>> m_destinations;
200
201 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
202 std::shared_ptr<monero_outgoing_transfer> copy(const std::shared_ptr<monero_transfer>& src, const std::shared_ptr<monero_transfer>& tgt) const;
203 std::shared_ptr<monero_outgoing_transfer> copy(const std::shared_ptr<monero_outgoing_transfer>& src, const std::shared_ptr<monero_outgoing_transfer>& tgt) const;
204 boost::optional<bool> is_incoming() const;
205 void merge(const std::shared_ptr<monero_transfer>& self, const std::shared_ptr<monero_transfer>& other);
206 void merge(const std::shared_ptr<monero_outgoing_transfer>& self, const std::shared_ptr<monero_outgoing_transfer>& other);
207 };
208
215 boost::optional<bool> m_is_incoming;
216 boost::optional<std::string> m_address;
217 std::vector<std::string> m_addresses;
218 boost::optional<uint32_t> m_subaddress_index;
219 std::vector<uint32_t> m_subaddress_indices;
220 std::vector<std::shared_ptr<monero_destination>> m_destinations;
221 boost::optional<bool> m_has_destinations;
222 boost::optional<std::shared_ptr<monero_tx_query>> m_tx_query;
223
224 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
225 static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_transfer_query>& transfer_query);
226 static std::shared_ptr<monero_transfer_query> deserialize_from_block(const std::string& transfer_query_json);
227 std::shared_ptr<monero_transfer_query> copy(const std::shared_ptr<monero_transfer>& src, const std::shared_ptr<monero_transfer>& tgt) const;
228 std::shared_ptr<monero_transfer_query> copy(const std::shared_ptr<monero_transfer_query>& src, const std::shared_ptr<monero_transfer_query>& tgt) const;
229 boost::optional<bool> is_incoming() const;
230 bool meets_criteria(monero_transfer* transfer, bool query_parent = true) const;
231 };
232
237 boost::optional<uint32_t> m_account_index;
238 boost::optional<uint32_t> m_subaddress_index;
239 boost::optional<bool> m_is_spent;
240 boost::optional<bool> m_is_frozen;
241
242 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
243 static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_output_wallet>& output_wallet);
244 std::shared_ptr<monero_output_wallet> copy(const std::shared_ptr<monero_output>& src, const std::shared_ptr<monero_output>& tgt) const;
245 std::shared_ptr<monero_output_wallet> copy(const std::shared_ptr<monero_output_wallet>& src, const std::shared_ptr<monero_output_wallet>& tgt) const;
246 void merge(const std::shared_ptr<monero_output>& self, const std::shared_ptr<monero_output>& other);
247 void merge(const std::shared_ptr<monero_output_wallet>& self, const std::shared_ptr<monero_output_wallet>& other);
248 };
249
257 std::vector<uint32_t> m_subaddress_indices;
258 boost::optional<uint64_t> m_min_amount;
259 boost::optional<uint64_t> m_max_amount;
260 boost::optional<std::shared_ptr<monero_tx_query>> m_tx_query;
261
262 //boost::property_tree::ptree to_property_tree() const;
263 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
264 static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_output_query>& output_query);
265 static std::shared_ptr<monero_output_query> deserialize_from_block(const std::string& output_query_json);
266 std::shared_ptr<monero_output_query> copy(const std::shared_ptr<monero_output>& src, const std::shared_ptr<monero_output>& tgt) const;
267 std::shared_ptr<monero_output_query> copy(const std::shared_ptr<monero_output_wallet>& src, const std::shared_ptr<monero_output_wallet>& tgt) const; // TODO: necessary to override all super classes?
268 std::shared_ptr<monero_output_query> copy(const std::shared_ptr<monero_output_query>& src, const std::shared_ptr<monero_output_query>& tgt) const;
269 bool meets_criteria(monero_output_wallet* output, bool query_parent = true) const;
270 };
271
275 struct monero_tx_wallet : public monero_tx {
276 boost::optional<std::shared_ptr<monero_tx_set>> m_tx_set;
277 boost::optional<bool> m_is_incoming;
278 boost::optional<bool> m_is_outgoing;
279 std::vector<std::shared_ptr<monero_incoming_transfer>> m_incoming_transfers;
280 boost::optional<std::shared_ptr<monero_outgoing_transfer>> m_outgoing_transfer;
281 boost::optional<std::string> m_note;
282 boost::optional<bool> m_is_locked;
283 boost::optional<uint64_t> m_input_sum;
284 boost::optional<uint64_t> m_output_sum;
285 boost::optional<std::string> m_change_address;
286 boost::optional<uint64_t> m_change_amount;
287 boost::optional<uint32_t> m_num_dummy_outputs;
288 boost::optional<std::string> m_extra_hex;
289
290 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
291 static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_tx_wallet>& tx_wallet);
292 std::shared_ptr<monero_tx_wallet> copy(const std::shared_ptr<monero_tx>& src, const std::shared_ptr<monero_tx>& tgt) const;
293 std::shared_ptr<monero_tx_wallet> copy(const std::shared_ptr<monero_tx_wallet>& src, const std::shared_ptr<monero_tx_wallet>& tgt) const;
294 void merge(const std::shared_ptr<monero_tx>& self, const std::shared_ptr<monero_tx>& other);
295 void merge(const std::shared_ptr<monero_tx_wallet>& self, const std::shared_ptr<monero_tx_wallet>& other);
296 std::vector<std::shared_ptr<monero_transfer>> get_transfers() const;
297 std::vector<std::shared_ptr<monero_transfer>> get_transfers(const monero_transfer_query& query) const;
298 std::vector<std::shared_ptr<monero_transfer>> filter_transfers(const monero_transfer_query& query);
299 std::vector<std::shared_ptr<monero_output_wallet>> get_outputs_wallet() const;
300 std::vector<std::shared_ptr<monero_output_wallet>> get_outputs_wallet(const monero_output_query& query) const;
301 std::vector<std::shared_ptr<monero_output_wallet>> filter_outputs_wallet(const monero_output_query& query);
302 };
303
310 boost::optional<bool> m_is_outgoing;
311 boost::optional<bool> m_is_incoming;
312 std::vector<std::string> m_hashes;
313 boost::optional<bool> m_has_payment_id;
314 std::vector<std::string> m_payment_ids;
315 boost::optional<uint64_t> m_height;
316 boost::optional<uint64_t> m_min_height;
317 boost::optional<uint64_t> m_max_height;
318 boost::optional<uint64_t> m_include_outputs;
319 boost::optional<std::shared_ptr<monero_transfer_query>> m_transfer_query;
320 boost::optional<std::shared_ptr<monero_output_query>> m_input_query;
321 boost::optional<std::shared_ptr<monero_output_query>> m_output_query;
322
323 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
324 static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_tx_query>& tx_query);
325 static std::shared_ptr<monero_tx_query> deserialize_from_block(const std::string& tx_query_json);
326 std::shared_ptr<monero_tx_query> copy(const std::shared_ptr<monero_tx>& src, const std::shared_ptr<monero_tx>& tgt) const;
327 std::shared_ptr<monero_tx_query> copy(const std::shared_ptr<monero_tx_wallet>& src, const std::shared_ptr<monero_tx_wallet>& tgt) const; // TODO: necessary to override all super classes?
328 std::shared_ptr<monero_tx_query> copy(const std::shared_ptr<monero_tx_query>& src, const std::shared_ptr<monero_tx_query>& tgt) const;
329 bool meets_criteria(monero_tx_wallet* tx, bool query_children = true) const;
330 };
331
341 std::vector<std::shared_ptr<monero_tx_wallet>> m_txs;
342 boost::optional<std::string> m_signed_tx_hex;
343 boost::optional<std::string> m_unsigned_tx_hex;
344 boost::optional<std::string> m_multisig_tx_hex;
345
346 //boost::property_tree::ptree to_property_tree() const;
347 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
348 static monero_tx_set deserialize(const std::string& tx_set_json);
349 };
350
355 std::string m_standard_address;
356 std::string m_payment_id;
357 std::string m_integrated_address;
358
359 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
360 };
361
365 enum monero_tx_priority : uint8_t {
366 DEFAULT = 0,
367 UNIMPORTANT,
368 NORMAL,
369 ELEVATED
370 };
371
376 boost::optional<std::string> m_address;
377 boost::optional<uint64_t> m_amount;
378 std::vector<std::shared_ptr<monero_destination>> m_destinations;
379 std::vector<uint32_t> m_subtract_fee_from;
380 boost::optional<std::string> m_payment_id;
381 boost::optional<monero_tx_priority> m_priority;
382 boost::optional<uint32_t> m_ring_size;
383 boost::optional<uint64_t> m_fee;
384 boost::optional<uint32_t> m_account_index;
385 std::vector<uint32_t> m_subaddress_indices;
386 boost::optional<uint64_t> m_unlock_time;
387 boost::optional<bool> m_can_split;
388 boost::optional<bool> m_relay;
389 boost::optional<std::string> m_note;
390 boost::optional<std::string> m_recipient_name;
391 boost::optional<uint64_t> m_below_amount;
392 boost::optional<bool> m_sweep_each_subaddress;
393 boost::optional<std::string> m_key_image;
394
396 monero_tx_config(const monero_tx_config& config);
397 monero_tx_config copy() const;
398 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
399 static std::shared_ptr<monero_tx_config> deserialize(const std::string& config_json);
400 std::vector<std::shared_ptr<monero_destination>> get_normalized_destinations() const;
401 };
402
407 boost::optional<uint64_t> m_height;
408 boost::optional<uint64_t> m_spent_amount;
409 boost::optional<uint64_t> m_unspent_amount;
410
411 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
412 };
413
418 SIGN_WITH_SPEND_KEY = 0,
419 SIGN_WITH_VIEW_KEY
420 };
421
426 bool m_is_good;
427 uint32_t m_version;
428 bool m_is_old;
429 monero_message_signature_type m_signature_type;
430
431 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
432 };
433
438 bool m_is_good;
439
440 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
441 };
442
447 boost::optional<bool> m_in_tx_pool;
448 boost::optional<uint64_t> m_num_confirmations;
449 boost::optional<uint64_t> m_received_amount;
450
451 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
452 };
453
458 boost::optional<uint64_t> m_total_amount;
459 boost::optional<uint64_t> m_unconfirmed_spent_amount;
460
461 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
462 };
463
468 bool m_is_multisig;
469 bool m_is_ready;
470 uint32_t m_threshold;
471 uint32_t m_num_participants;
472
473 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
474 };
475
482 boost::optional<std::string> m_address;
483 boost::optional<std::string> m_multisig_hex;
484
485 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
486 };
487
492 boost::optional<std::string> m_signed_multisig_tx_hex;
493 std::vector<std::string> m_tx_hashes;
494
495 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
496 };
497
502 boost::optional<uint64_t> m_index; // TODO: not boost::optional
503 boost::optional<std::string> m_address;
504 boost::optional<std::string> m_description;
505 boost::optional<std::string> m_payment_id;
506
508 monero_address_book_entry(uint64_t index, const std::string& address, const std::string& description) : m_index(index), m_address(address), m_description(description) {}
509 monero_address_book_entry(uint64_t index, const std::string& address, const std::string& description, const std::string& payment_id) : m_index(index), m_address(address), m_description(description), m_payment_id(payment_id) {}
510 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
511 };
512}
Definition: monero_daemon.cpp:58
monero_message_signature_type
Definition: monero_wallet_model.h:417
monero_tx_priority
Definition: monero_wallet_model.h:365
Definition: monero_wallet_model.h:127
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:227
Definition: monero_wallet_model.h:501
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:1558
Definition: monero_wallet_model.h:457
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:1493
Definition: monero_wallet_model.h:446
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:1474
Definition: monero_wallet_model.h:437
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:1460
Definition: monero_wallet_model.h:141
Definition: monero_wallet_model.h:180
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:814
Definition: monero_wallet_model.h:354
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:1403
Definition: monero_wallet_model.h:406
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:1420
Definition: monero_wallet_model.h:425
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:1437
Definition: monero_wallet_model.h:467
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:1509
Definition: monero_wallet_model.h:481
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:1527
Definition: monero_wallet_model.h:491
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:1541
Definition: monero_wallet_model.h:196
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:861
Definition: monero_wallet_model.h:256
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:1166
Definition: monero_wallet_model.h:236
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:1096
Definition: monero_daemon_model.h:235
Definition: monero_daemon_model.h:109
Definition: monero_wallet_model.h:110
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:252
Definition: monero_wallet_model.h:98
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:209
Definition: monero_wallet_model.h:214
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:921
Definition: monero_wallet_model.h:161
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:758
Definition: monero_wallet_model.h:375
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:1307
Definition: monero_wallet_model.h:309
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:475
Definition: monero_wallet_model.h:340
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:711
Definition: monero_wallet_model.h:275
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:280
Definition: monero_daemon_model.h:170
Definition: monero_wallet_model.h:67
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType &allocator) const
Definition: monero_wallet_model.cpp:119
Definition: monero_daemon_model.h:69