Monero
Loading...
Searching...
No Matches
wallet_errors.h
Go to the documentation of this file.
1// Copyright (c) 2014-2022, The Monero Project
2//
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without modification, are
6// permitted provided that the following conditions are met:
7//
8// 1. Redistributions of source code must retain the above copyright notice, this list of
9// conditions and the following disclaimer.
10//
11// 2. Redistributions in binary form must reproduce the above copyright notice, this list
12// of conditions and the following disclaimer in the documentation and/or other
13// materials provided with the distribution.
14//
15// 3. Neither the name of the copyright holder nor the names of its contributors may be
16// used to endorse or promote products derived from this software without specific
17// prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28//
29// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
30
31#pragma once
32
33#include <stdexcept>
34#include <system_error>
35#include <string>
36#include <vector>
37
41#include "include_base_utils.h"
42
43
44namespace tools
45{
46 namespace error
47 {
48 // std::exception
49 // std::runtime_error
50 // wallet_runtime_error *
51 // wallet_internal_error
52 // unexpected_txin_type
53 // wallet_not_initialized
54 // multisig_export_needed
55 // multisig_import_needed
56 // password_needed
57 // std::logic_error
58 // wallet_logic_error *
59 // file_exists
60 // file_not_found
61 // file_read_error
62 // file_save_error
63 // invalid_password
64 // invalid_priority
65 // invalid_multisig_seed
66 // invalid_spend_key
67 // refresh_error *
68 // acc_outs_lookup_error
69 // block_parse_error
70 // get_blocks_error
71 // get_hashes_error
72 // get_out_indexes_error
73 // tx_parse_error
74 // get_tx_pool_error
75 // out_of_hashchain_bounds_error
76 // signature_check_failed
77 // transfer_error *
78 // get_outs_general_error
79 // not_enough_unlocked_money
80 // not_enough_money
81 // tx_not_possible
82 // not_enough_outs_to_mix
83 // tx_not_constructed
84 // tx_rejected
85 // tx_sum_overflow
86 // tx_too_big
87 // zero_amount
88 // zero_destination
89 // subtract_fee_from_bad_index
90 // nonzero_unlock_time
91 // wallet_rpc_error *
92 // daemon_busy
93 // no_connection_to_daemon
94 // is_key_image_spent_error
95 // get_histogram_error
96 // get_output_distribution
97 // payment_required
98 // wallet_files_doesnt_correspond
99 // scan_tx_error *
100 // wont_reprocess_recent_txs_via_untrusted_daemon
101 // background_sync_error *
102 // background_wallet_already_open
103 // background_custom_password_same_as_wallet_password
104 //
105 // * - class with protected ctor
106
107 //----------------------------------------------------------------------------------------------------
108 template<typename Base>
109 struct wallet_error_base : public Base
110 {
111 const std::string& location() const { return m_loc; }
112
113 std::string to_string() const
114 {
115 std::ostringstream ss;
116 ss << m_loc << ':' << typeid(*this).name() << ": " << Base::what();
117 return ss.str();
118 }
119
120 protected:
121 wallet_error_base(std::string&& loc, const std::string& message)
122 : Base(message)
123 , m_loc(loc)
124 {
125 }
126
127 private:
128 std::string m_loc;
129 };
130 //----------------------------------------------------------------------------------------------------
131 const char* const failed_rpc_request_messages[] = {
132 "failed to get blocks",
133 "failed to get hashes",
134 "failed to get out indices",
135 "failed to get random outs"
136 };
144
145 template<typename Base, int msg_index>
146 struct failed_rpc_request : public Base
147 {
148 explicit failed_rpc_request(std::string&& loc, const std::string& status)
149 : Base(std::move(loc), failed_rpc_request_messages[msg_index])
151 {
152 }
153
154 const std::string& status() const { return m_status; }
155
156 std::string to_string() const
157 {
158 std::ostringstream ss;
159 ss << Base::to_string() << ", status = " << status();
160 return ss.str();
161 }
162
163 private:
164 std::string m_status;
165 };
166 //----------------------------------------------------------------------------------------------------
169 //----------------------------------------------------------------------------------------------------
171 {
172 explicit wallet_internal_error(std::string&& loc, const std::string& message)
173 : wallet_runtime_error(std::move(loc), message)
174 {
175 }
176 };
177 //----------------------------------------------------------------------------------------------------
179 {
180 explicit unexpected_txin_type(std::string&& loc, const cryptonote::transaction& tx)
181 : wallet_internal_error(std::move(loc), "one of tx inputs has unexpected type")
182 , m_tx(tx)
183 {
184 }
185
186 const cryptonote::transaction& tx() const { return m_tx; }
187
188 std::string to_string() const
189 {
190 std::ostringstream ss;
193 return ss.str();
194 }
195
196 private:
198 };
199 //----------------------------------------------------------------------------------------------------
201 {
202 explicit wallet_not_initialized(std::string&& loc)
203 : wallet_internal_error(std::move(loc), "wallet is not initialized")
204 {
205 }
206 };
207 //----------------------------------------------------------------------------------------------------
209 {
210 explicit multisig_export_needed(std::string&& loc)
211 : wallet_runtime_error(std::move(loc), "This signature was made with stale data: export fresh multisig data, which other participants must then use")
212 {
213 }
214 };
215 //----------------------------------------------------------------------------------------------------
217 {
218 explicit multisig_import_needed(std::string&& loc)
219 : wallet_runtime_error(std::move(loc), "Not enough multisig data was found to sign: import multisig data from more other participants")
220 {
221 }
222 };
223 //----------------------------------------------------------------------------------------------------
225 {
226 explicit password_needed(std::string&& loc, const std::string &msg = "Password needed")
227 : wallet_runtime_error(std::move(loc), msg)
228 {
229 }
230 };
231 //----------------------------------------------------------------------------------------------------
233 {
234 explicit password_entry_failed(std::string&& loc, const std::string &msg = "Password entry failed")
235 : wallet_runtime_error(std::move(loc), msg)
236 {
237 }
238 };
239 //----------------------------------------------------------------------------------------------------
240 const char* const file_error_messages[] = {
241 "file already exists",
242 "file not found",
243 "failed to read file",
244 "failed to save file"
245 };
253
254 template<int msg_index>
256 {
257 explicit file_error_base(std::string&& loc, const std::string& file)
258 : wallet_logic_error(std::move(loc), std::string(file_error_messages[msg_index]) + " \"" + file + '\"')
259 , m_file(file)
260 {
261 }
262
263 explicit file_error_base(std::string&& loc, const std::string& file, const std::error_code &e)
264 : wallet_logic_error(std::move(loc), std::string(file_error_messages[msg_index]) + " \"" + file + "\": " + e.message())
265 , m_file(file)
266 {
267 }
268
269 const std::string& file() const { return m_file; }
270
271 std::string to_string() const { return wallet_logic_error::to_string(); }
272
273 private:
274 std::string m_file;
275 };
276 //----------------------------------------------------------------------------------------------------
281 //----------------------------------------------------------------------------------------------------
283 {
284 explicit invalid_password(std::string&& loc)
285 : wallet_logic_error(std::move(loc), "invalid password")
286 {
287 }
288
289 std::string to_string() const { return wallet_logic_error::to_string(); }
290 };
292 {
293 explicit invalid_priority(std::string&& loc)
294 : wallet_logic_error(std::move(loc), "invalid priority")
295 {
296 }
297
298 std::string to_string() const { return wallet_logic_error::to_string(); }
299 };
300
302 {
303 explicit invalid_multisig_seed(std::string&& loc)
304 : wallet_logic_error(std::move(loc), "invalid multisig seed")
305 {
306 }
307
308 std::string to_string() const { return wallet_logic_error::to_string(); }
309 };
310
312 {
313 explicit invalid_spend_key(std::string&& loc)
314 : wallet_logic_error(std::move(loc), "invalid spend key")
315 {
316 }
317
318 std::string to_string() const { return wallet_logic_error::to_string(); }
319 };
320
321 //----------------------------------------------------------------------------------------------------
323 {
324 explicit invalid_pregenerated_random (std::string&& loc)
325 : wallet_logic_error(std::move(loc), "invalid pregenerated random for wallet creation/recovery")
326 {
327 }
328
329 std::string to_string() const { return wallet_logic_error::to_string(); }
330 };
331 //----------------------------------------------------------------------------------------------------
333 {
334 protected:
335 explicit refresh_error(std::string&& loc, const std::string& message)
336 : wallet_logic_error(std::move(loc), message)
337 {
338 }
339 };
340 //----------------------------------------------------------------------------------------------------
342 {
343 explicit index_outofbound(std::string&& loc, const std::string& message)
344 : wallet_logic_error(std::move(loc), message)
345 {
346 }
347 };
349 {
350 explicit account_index_outofbound(std::string&& loc)
351 : index_outofbound(std::move(loc), "account index is out of bound")
352 {
353 }
354 };
356 {
357 explicit address_index_outofbound(std::string&& loc)
358 : index_outofbound(std::move(loc), "address index is out of bound")
359 {
360 }
361 };
362 //----------------------------------------------------------------------------------------------------
364 {
365 explicit acc_outs_lookup_error(std::string&& loc, const cryptonote::transaction& tx,
367 : refresh_error(std::move(loc), "account outs lookup error")
368 , m_tx(tx)
371 {
372 }
373
374 const cryptonote::transaction& tx() const { return m_tx; }
375 const crypto::public_key& tx_pub_key() const { return m_tx_pub_key; }
377
378 std::string to_string() const
379 {
380 std::ostringstream ss;
383 return ss.str();
384 }
385
386 private:
390 };
391 //----------------------------------------------------------------------------------------------------
393 {
394 explicit block_parse_error(std::string&& loc, const cryptonote::blobdata& block_data)
395 : refresh_error(std::move(loc), "block parse error")
396 , m_block_blob(block_data)
397 {
398 }
399
401
402 std::string to_string() const { return refresh_error::to_string(); }
403
404 private:
406 };
407 //----------------------------------------------------------------------------------------------------
409 //----------------------------------------------------------------------------------------------------
411 //----------------------------------------------------------------------------------------------------
413 //----------------------------------------------------------------------------------------------------
415 {
416 explicit tx_parse_error(std::string&& loc, const cryptonote::blobdata& tx_blob)
417 : refresh_error(std::move(loc), "transaction parse error")
419 {
420 }
421
422 const cryptonote::blobdata& tx_blob() const { return m_tx_blob; }
423
424 std::string to_string() const { return refresh_error::to_string(); }
425
426 private:
428 };
429 //----------------------------------------------------------------------------------------------------
431 {
432 explicit get_tx_pool_error(std::string&& loc)
433 : refresh_error(std::move(loc), "error getting transaction pool")
434 {
435 }
436
437 std::string to_string() const { return refresh_error::to_string(); }
438 };
439 //----------------------------------------------------------------------------------------------------
441 {
442 explicit out_of_hashchain_bounds_error(std::string&& loc)
443 : refresh_error(std::move(loc), "Index out of bounds of of hashchain")
444 {
445 }
446
447 std::string to_string() const { return refresh_error::to_string(); }
448 };
449 //----------------------------------------------------------------------------------------------------
451 {
452 explicit reorg_depth_error(std::string&& loc, const std::string& message)
453 : refresh_error(std::move(loc), message)
454 {
455 }
456
457 std::string to_string() const { return refresh_error::to_string(); }
458 };
459 //----------------------------------------------------------------------------------------------------
461 {
462 explicit incorrect_fork_version(std::string&& loc, const std::string& message)
463 : refresh_error(std::move(loc), message)
464 {
465 }
466
467 std::string to_string() const { return refresh_error::to_string(); }
468 };
469 //----------------------------------------------------------------------------------------------------
471 {
472 explicit signature_check_failed(std::string&& loc, const std::string& message)
473 : wallet_logic_error(std::move(loc), "Signature check failed " + message)
474 {
475 }
476 };
477 //----------------------------------------------------------------------------------------------------
479 {
480 protected:
481 explicit transfer_error(std::string&& loc, const std::string& message)
482 : wallet_logic_error(std::move(loc), message)
483 {
484 }
485 };
486 //----------------------------------------------------------------------------------------------------
488 //----------------------------------------------------------------------------------------------------
490 {
492 : transfer_error(std::move(loc), "not enough unlocked money")
495 {
496 }
497
498 uint64_t available() const { return m_available; }
499 uint64_t tx_amount() const { return m_tx_amount; }
500
501 std::string to_string() const
502 {
503 std::ostringstream ss;
505 ", available = " << cryptonote::print_money(m_available) <<
506 ", tx_amount = " << cryptonote::print_money(m_tx_amount);
507 return ss.str();
508 }
509
510 private:
513 };
514 //----------------------------------------------------------------------------------------------------
516 {
518 : transfer_error(std::move(loc), "not enough money")
521 {
522 }
523
524 uint64_t available() const { return m_available; }
525 uint64_t tx_amount() const { return m_tx_amount; }
526
527 std::string to_string() const
528 {
529 std::ostringstream ss;
531 ", available = " << cryptonote::print_money(m_available) <<
532 ", tx_amount = " << cryptonote::print_money(m_tx_amount);
533 return ss.str();
534 }
535
536 private:
539 };
540 //----------------------------------------------------------------------------------------------------
542 {
544 : transfer_error(std::move(loc), "tx not possible")
547 , m_fee(fee)
548 {
549 }
550
551 uint64_t available() const { return m_available; }
552 uint64_t tx_amount() const { return m_tx_amount; }
553 uint64_t fee() const { return m_fee; }
554
555 std::string to_string() const
556 {
557 std::ostringstream ss;
559 ", available = " << cryptonote::print_money(m_available) <<
560 ", tx_amount = " << cryptonote::print_money(m_tx_amount) <<
561 ", fee = " << cryptonote::print_money(m_fee);
562 return ss.str();
563 }
564
565 private:
569 };
570 //----------------------------------------------------------------------------------------------------
572 {
573 typedef std::unordered_map<uint64_t, uint64_t> scanty_outs_t;
574
575 explicit not_enough_outs_to_mix(std::string&& loc, const scanty_outs_t& scanty_outs, size_t mixin_count)
576 : transfer_error(std::move(loc), "not enough outputs to use")
579 {
580 }
581
582 const scanty_outs_t& scanty_outs() const { return m_scanty_outs; }
583 size_t mixin_count() const { return m_mixin_count; }
584
585 std::string to_string() const
586 {
587 std::ostringstream ss;
588 ss << transfer_error::to_string() << ", ring size = " << (m_mixin_count + 1) << ", scanty_outs:";
589 for (const auto& out: m_scanty_outs)
590 {
591 ss << '\n' << cryptonote::print_money(out.first) << " - " << out.second;
592 }
593 return ss.str();
594 }
595
596 private:
599 };
600 //----------------------------------------------------------------------------------------------------
602 {
603 typedef std::vector<cryptonote::tx_source_entry> sources_t;
604 typedef std::vector<cryptonote::tx_destination_entry> destinations_t;
605
607 std::string && loc
608 , sources_t const & sources
611 )
612 : transfer_error(std::move(loc), "transaction was not constructed")
615 , m_nettype(nettype)
616 {
617 }
618
619 const sources_t& sources() const { return m_sources; }
620 const destinations_t& destinations() const { return m_destinations; }
621
622 std::string to_string() const
623 {
624 std::ostringstream ss;
626 ss << "\nSources:";
627 for (size_t i = 0; i < m_sources.size(); ++i)
628 {
630 ss << "\n source " << i << ":";
631 ss << "\n amount: " << cryptonote::print_money(src.amount);
632 // It's not good, if logs will contain such much data
633 //ss << "\n real_output: " << src.real_output;
634 //ss << "\n real_output_in_tx_index: " << src.real_output_in_tx_index;
635 //ss << "\n real_out_tx_key: " << epee::string_tools::pod_to_hex(src.real_out_tx_key);
636 //ss << "\n outputs:";
637 //for (size_t j = 0; j < src.outputs.size(); ++j)
638 //{
639 // const cryptonote::tx_source_entry::output_entry& out = src.outputs[j];
640 // ss << "\n " << j << ": " << out.first << ", " << epee::string_tools::pod_to_hex(out.second);
641 //}
642 }
643
644 ss << "\nDestinations:";
645 for (size_t i = 0; i < m_destinations.size(); ++i)
646 {
648 ss << "\n " << i << ": " << cryptonote::get_account_address_as_str(m_nettype, dst.is_subaddress, dst.addr) << " " <<
650 }
651
652 return ss.str();
653 }
654
655 private:
659 };
660 //----------------------------------------------------------------------------------------------------
662 {
663 explicit tx_rejected(std::string&& loc, const cryptonote::transaction& tx, const std::string& status, const std::string& reason)
664 : transfer_error(std::move(loc), "transaction was rejected by daemon")
665 , m_tx(tx)
668 {
669 }
670
671 const cryptonote::transaction& tx() const { return m_tx; }
672 const std::string& status() const { return m_status; }
673 const std::string& reason() const { return m_reason; }
674
675 std::string to_string() const
676 {
677 std::ostringstream ss;
678 ss << transfer_error::to_string() << ", status = " << m_status << ", tx:\n";
681 if (!m_reason.empty())
682 {
683 ss << " (" << m_reason << ")";
684 }
685 return ss.str();
686 }
687
688 private:
690 std::string m_status;
691 std::string m_reason;
692 };
693 //----------------------------------------------------------------------------------------------------
695 {
697 std::string && loc
698 , const std::vector<cryptonote::tx_destination_entry>& destinations
699 , uint64_t fee
701 )
702 : transfer_error(std::move(loc), "transaction sum + fee exceeds " + cryptonote::print_money(std::numeric_limits<uint64_t>::max()))
704 , m_fee(fee)
705 , m_nettype(nettype)
706 {
707 }
708
709 const std::vector<cryptonote::tx_destination_entry>& destinations() const { return m_destinations; }
710 uint64_t fee() const { return m_fee; }
711
712 std::string to_string() const
713 {
714 std::ostringstream ss;
716 ", fee = " << cryptonote::print_money(m_fee) <<
717 ", destinations:";
718 for (const auto& dst : m_destinations)
719 {
720 ss << '\n' << cryptonote::print_money(dst.amount) << " -> " << cryptonote::get_account_address_as_str(m_nettype, dst.is_subaddress, dst.addr);
721 }
722 return ss.str();
723 }
724
725 private:
726 std::vector<cryptonote::tx_destination_entry> m_destinations;
729 };
730 //----------------------------------------------------------------------------------------------------
732 {
733 explicit tx_too_big(std::string&& loc, const cryptonote::transaction& tx, uint64_t tx_weight_limit)
734 : transfer_error(std::move(loc), "transaction is too big")
735 , m_tx(tx)
737 , m_tx_weight(cryptonote::get_transaction_weight(tx))
739 {
740 }
741
743 : transfer_error(std::move(loc), "transaction would be too big")
747 {
748 }
749
750 bool tx_valid() const { return m_tx_valid; }
751 const cryptonote::transaction& tx() const { return m_tx; }
752 uint64_t tx_weight() const { return m_tx_weight; }
754
755 std::string to_string() const
756 {
757 std::ostringstream ss;
759 ", tx_weight_limit = " << m_tx_weight_limit <<
760 ", tx weight = " << m_tx_weight;
761 if (m_tx_valid)
762 {
764 ss << ", tx:\n" << cryptonote::obj_to_json_str(tx);
765 }
766 return ss.str();
767 }
768
769 private:
774 };
775 //----------------------------------------------------------------------------------------------------
777 {
778 explicit zero_amount(std::string&& loc)
779 : transfer_error(std::move(loc), "destination amount is zero")
780 {
781 }
782 };
783 //----------------------------------------------------------------------------------------------------
785 {
786 explicit zero_destination(std::string&& loc)
787 : transfer_error(std::move(loc), "transaction has no destination")
788 {
789 }
790 };
791 //----------------------------------------------------------------------------------------------------
793 {
794 explicit subtract_fee_from_bad_index(std::string&& loc, long bad_index)
795 : transfer_error(std::move(loc),
796 "subtractfeefrom: bad index: " + std::to_string(bad_index) + " (indexes are 0-based)")
797 {
798 }
799 };
800 //----------------------------------------------------------------------------------------------------
802 {
803 explicit nonzero_unlock_time(std::string&& loc)
804 : transfer_error(std::move(loc), "transaction cannot have non-zero unlock time")
805 {
806 }
807 };
808 //----------------------------------------------------------------------------------------------------
810 {
811 const std::string& request() const { return m_request; }
812
813 std::string to_string() const
814 {
815 std::ostringstream ss;
816 ss << wallet_logic_error::to_string() << ", request = " << m_request;
817 return ss.str();
818 }
819
820 protected:
821 explicit wallet_rpc_error(std::string&& loc, const std::string& message, const std::string& request)
822 : wallet_logic_error(std::move(loc), message)
824 {
825 }
826
827 private:
828 std::string m_request;
829 };
830 //----------------------------------------------------------------------------------------------------
832 {
833 explicit wallet_generic_rpc_error(std::string&& loc, const std::string& request, const std::string& status)
834 : wallet_rpc_error(std::move(loc), std::string("error in ") + request + " RPC: " + status, request),
836 {
837 }
838 const std::string& status() const { return m_status; }
839 private:
840 const std::string m_status;
841 };
842 //----------------------------------------------------------------------------------------------------
844 {
845 explicit wallet_coded_rpc_error(std::string&& loc, const std::string& request, int code, const std::string& status)
846 : wallet_rpc_error(std::move(loc), std::string("error ") + std::to_string(code) + (" in ") + request + " RPC: " + status, request),
848 {
849 }
850 int code() const { return m_code; }
851 const std::string& status() const { return m_status; }
852 private:
854 const std::string m_status;
855 };
856 //----------------------------------------------------------------------------------------------------
858 {
859 explicit daemon_busy(std::string&& loc, const std::string& request)
860 : wallet_rpc_error(std::move(loc), "daemon is busy", request)
861 {
862 }
863 };
864 //----------------------------------------------------------------------------------------------------
866 {
867 explicit no_connection_to_daemon(std::string&& loc, const std::string& request)
868 : wallet_rpc_error(std::move(loc), "no connection to daemon", request)
869 {
870 }
871 };
872 //----------------------------------------------------------------------------------------------------
874 {
875 explicit is_key_image_spent_error(std::string&& loc, const std::string& request)
876 : wallet_rpc_error(std::move(loc), "error from is_key_image_spent call", request)
877 {
878 }
879 };
880 //----------------------------------------------------------------------------------------------------
882 {
883 explicit get_histogram_error(std::string&& loc, const std::string& request)
884 : wallet_rpc_error(std::move(loc), "failed to get output histogram", request)
885 {
886 }
887 };
888 //----------------------------------------------------------------------------------------------------
890 {
891 explicit get_output_distribution(std::string&& loc, const std::string& request)
892 : wallet_rpc_error(std::move(loc), "failed to get output distribution", request)
893 {
894 }
895 };
896 //----------------------------------------------------------------------------------------------------
898 {
899 explicit payment_required(std::string&& loc, const std::string& request)
900 : wallet_rpc_error(std::move(loc), "payment required", request)
901 {
902 }
903 };
904 //----------------------------------------------------------------------------------------------------
906 {
907 explicit wallet_files_doesnt_correspond(std::string&& loc, const std::string& keys_file, const std::string& wallet_file)
908 : wallet_logic_error(std::move(loc), "file " + wallet_file + " does not correspond to " + keys_file)
909 {
910 }
911
912 const std::string& keys_file() const { return m_keys_file; }
913 const std::string& wallet_file() const { return m_wallet_file; }
914
915 std::string to_string() const { return wallet_logic_error::to_string(); }
916
917 private:
918 std::string m_keys_file;
919 std::string m_wallet_file;
920 };
921 //----------------------------------------------------------------------------------------------------
923 {
924 protected:
925 explicit mms_error(std::string&& loc, const std::string& message)
926 : wallet_logic_error(std::move(loc), message)
927 {
928 }
929 };
930 //----------------------------------------------------------------------------------------------------
932 {
933 explicit no_connection_to_bitmessage(std::string&& loc, const std::string& address)
934 : mms_error(std::move(loc), "no connection to PyBitmessage at address " + address)
935 {
936 }
937 };
938 //----------------------------------------------------------------------------------------------------
940 {
941 explicit bitmessage_api_error(std::string&& loc, const std::string& error_string)
942 : mms_error(std::move(loc), "PyBitmessage returned " + error_string)
943 {
944 }
945 };
946 //----------------------------------------------------------------------------------------------------
948 {
949 protected:
950 explicit scan_tx_error(std::string&& loc, const std::string& message)
951 : wallet_logic_error(std::move(loc), message)
952 {
953 }
954 };
955 //----------------------------------------------------------------------------------------------------
957 {
959 : scan_tx_error(std::move(loc), "The wallet has already seen 1 or more recent transactions than the scanned tx")
960 {
961 }
962 };
963 //----------------------------------------------------------------------------------------------------
965 {
966 protected:
967 explicit background_sync_error(std::string&& loc, const std::string& message)
968 : wallet_logic_error(std::move(loc), message)
969 {
970 }
971 };
972 //----------------------------------------------------------------------------------------------------
974 {
975 explicit background_wallet_already_open(std::string&& loc, const std::string& background_wallet_file)
976 : background_sync_error(std::move(loc), "background wallet " + background_wallet_file + " is already opened by another wallet program")
977 {
978 }
979 };
980 //----------------------------------------------------------------------------------------------------
982 {
984 : background_sync_error(std::move(loc), "custom background password must be different than wallet password")
985 {
986 }
987 };
988 //----------------------------------------------------------------------------------------------------
989
990#if !defined(_MSC_VER)
991
992 template<typename TException, typename... TArgs>
993 void throw_wallet_ex(std::string&& loc, const TArgs&... args)
994 {
995 TException e(std::move(loc), args...);
996 LOG_PRINT_L0(e.to_string());
997 throw e;
998 }
999
1000#else
1001 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
1002 #include <boost/preprocessor/repetition/enum_params.hpp>
1003 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
1004
1005 template<typename TException>
1006 void throw_wallet_ex(std::string&& loc)
1007 {
1008 TException e(std::move(loc));
1009 LOG_PRINT_L0(e.to_string());
1010 throw e;
1011 }
1012
1013#define GEN_throw_wallet_ex(z, n, data) \
1014 template<typename TException, BOOST_PP_ENUM_PARAMS(n, typename TArg)> \
1015 void throw_wallet_ex(std::string&& loc, BOOST_PP_ENUM_BINARY_PARAMS(n, const TArg, &arg)) \
1016 { \
1017 TException e(std::move(loc), BOOST_PP_ENUM_PARAMS(n, arg)); \
1018 LOG_PRINT_L0(e.to_string()); \
1019 throw e; \
1020 }
1021
1022 BOOST_PP_REPEAT_FROM_TO(1, 6, GEN_throw_wallet_ex, ~)
1023#endif
1024 }
1025}
1026
1027#define STRINGIZE_DETAIL(x) #x
1028#define STRINGIZE(x) STRINGIZE_DETAIL(x)
1029
1030#define THROW_WALLET_EXCEPTION(err_type, ...) \
1031 do { \
1032 LOG_ERROR("THROW EXCEPTION: " << #err_type); \
1033 tools::error::throw_wallet_ex<err_type>(std::string(__FILE__ ":" STRINGIZE(__LINE__)), ## __VA_ARGS__); \
1034 } while(0)
1035
1036#define THROW_WALLET_EXCEPTION_IF(cond, err_type, ...) \
1037 if (cond) \
1038 { \
1039 LOG_ERROR(#cond << ". THROW EXCEPTION: " << #err_type); \
1040 tools::error::throw_wallet_ex<err_type>(std::string(__FILE__ ":" STRINGIZE(__LINE__)), ## __VA_ARGS__); \
1041 }
Definition cryptonote_basic.h:205
#define true
#define false
uint32_t address
Definition getifaddr.c:269
POD_CLASS public_key
Definition crypto.h:64
Holds cryptonote related classes and helpers.
Definition blockchain_db.cpp:45
std::string obj_to_json_str(T &obj)
Definition cryptonote_format_utils.h:206
network_type
Definition cryptonote_config.h:302
std::string print_money(uint64_t amount, unsigned int decimal_point)
Definition cryptonote_format_utils.cpp:1180
std::string get_account_address_as_str(network_type nettype, bool subaddress, account_public_address const &adr)
Definition cryptonote_basic_impl.cpp:150
std::string blobdata
Definition blobdatatype.h:39
Definition get_output_distribution.py:1
Definition enums.h:68
Definition wallet_errors.h:47
file_error_message_indices
Definition wallet_errors.h:247
@ file_save_error_message_index
Definition wallet_errors.h:251
@ file_read_error_message_index
Definition wallet_errors.h:250
@ file_not_found_message_index
Definition wallet_errors.h:249
@ file_exists_message_index
Definition wallet_errors.h:248
const char *const file_error_messages[]
Definition wallet_errors.h:240
file_error_base< file_save_error_message_index > file_save_error
Definition wallet_errors.h:280
failed_rpc_request_message_indices
Definition wallet_errors.h:138
@ get_out_indices_error_message_index
Definition wallet_errors.h:141
@ get_blocks_error_message_index
Definition wallet_errors.h:139
@ get_hashes_error_message_index
Definition wallet_errors.h:140
@ get_outs_error_message_index
Definition wallet_errors.h:142
const char *const failed_rpc_request_messages[]
Definition wallet_errors.h:131
file_error_base< file_not_found_message_index > file_not_found
Definition wallet_errors.h:278
failed_rpc_request< refresh_error, get_hashes_error_message_index > get_hashes_error
Definition wallet_errors.h:410
void throw_wallet_ex(std::string &&loc, const TArgs &... args)
Definition wallet_errors.h:993
file_error_base< file_exists_message_index > file_exists
Definition wallet_errors.h:277
failed_rpc_request< refresh_error, get_blocks_error_message_index > get_blocks_error
Definition wallet_errors.h:408
failed_rpc_request< refresh_error, get_out_indices_error_message_index > get_out_indices_error
Definition wallet_errors.h:412
failed_rpc_request< transfer_error, get_outs_error_message_index > get_outs_error
Definition wallet_errors.h:487
file_error_base< file_read_error_message_index > file_read_error
Definition wallet_errors.h:279
wallet_error_base< std::logic_error > wallet_logic_error
Definition wallet_errors.h:167
wallet_error_base< std::runtime_error > wallet_runtime_error
Definition wallet_errors.h:168
Various Tools.
Definition apply_permutation.h:40
unsigned __int64 uint64_t
Definition stdint.h:136
Definition account.h:41
Definition cryptonote_tx_utils.h:75
bool is_subaddress
Definition cryptonote_tx_utils.h:79
uint64_t amount
Definition cryptonote_tx_utils.h:77
account_public_address addr
Definition cryptonote_tx_utils.h:78
Definition cryptonote_tx_utils.h:43
uint64_t amount
Definition cryptonote_tx_utils.h:51
acc_outs_lookup_error(std::string &&loc, const cryptonote::transaction &tx, const crypto::public_key &tx_pub_key, const cryptonote::account_keys &acc_keys)
Definition wallet_errors.h:365
const crypto::public_key m_tx_pub_key
Definition wallet_errors.h:388
std::string to_string() const
Definition wallet_errors.h:378
const crypto::public_key & tx_pub_key() const
Definition wallet_errors.h:375
const cryptonote::account_keys & acc_keys() const
Definition wallet_errors.h:376
const cryptonote::account_keys m_acc_keys
Definition wallet_errors.h:389
const cryptonote::transaction m_tx
Definition wallet_errors.h:387
const cryptonote::transaction & tx() const
Definition wallet_errors.h:374
account_index_outofbound(std::string &&loc)
Definition wallet_errors.h:350
address_index_outofbound(std::string &&loc)
Definition wallet_errors.h:357
background_custom_password_same_as_wallet_password(std::string &&loc)
Definition wallet_errors.h:983
background_sync_error(std::string &&loc, const std::string &message)
Definition wallet_errors.h:967
background_wallet_already_open(std::string &&loc, const std::string &background_wallet_file)
Definition wallet_errors.h:975
bitmessage_api_error(std::string &&loc, const std::string &error_string)
Definition wallet_errors.h:941
block_parse_error(std::string &&loc, const cryptonote::blobdata &block_data)
Definition wallet_errors.h:394
std::string to_string() const
Definition wallet_errors.h:402
const cryptonote::blobdata & block_blob() const
Definition wallet_errors.h:400
cryptonote::blobdata m_block_blob
Definition wallet_errors.h:405
daemon_busy(std::string &&loc, const std::string &request)
Definition wallet_errors.h:859
Definition wallet_errors.h:147
std::string to_string() const
Definition wallet_errors.h:156
const std::string & status() const
Definition wallet_errors.h:154
failed_rpc_request(std::string &&loc, const std::string &status)
Definition wallet_errors.h:148
Definition wallet_errors.h:256
std::string m_file
Definition wallet_errors.h:274
file_error_base(std::string &&loc, const std::string &file)
Definition wallet_errors.h:257
std::string to_string() const
Definition wallet_errors.h:271
const std::string & file() const
Definition wallet_errors.h:269
get_histogram_error(std::string &&loc, const std::string &request)
Definition wallet_errors.h:883
get_output_distribution(std::string &&loc, const std::string &request)
Definition wallet_errors.h:891
get_tx_pool_error(std::string &&loc)
Definition wallet_errors.h:432
std::string to_string() const
Definition wallet_errors.h:437
std::string to_string() const
Definition wallet_errors.h:467
incorrect_fork_version(std::string &&loc, const std::string &message)
Definition wallet_errors.h:462
index_outofbound(std::string &&loc, const std::string &message)
Definition wallet_errors.h:343
invalid_multisig_seed(std::string &&loc)
Definition wallet_errors.h:303
std::string to_string() const
Definition wallet_errors.h:308
invalid_password(std::string &&loc)
Definition wallet_errors.h:284
std::string to_string() const
Definition wallet_errors.h:289
std::string to_string() const
Definition wallet_errors.h:329
invalid_pregenerated_random(std::string &&loc)
Definition wallet_errors.h:324
invalid_priority(std::string &&loc)
Definition wallet_errors.h:293
std::string to_string() const
Definition wallet_errors.h:298
std::string to_string() const
Definition wallet_errors.h:318
invalid_spend_key(std::string &&loc)
Definition wallet_errors.h:313
is_key_image_spent_error(std::string &&loc, const std::string &request)
Definition wallet_errors.h:875
mms_error(std::string &&loc, const std::string &message)
Definition wallet_errors.h:925
multisig_export_needed(std::string &&loc)
Definition wallet_errors.h:210
multisig_import_needed(std::string &&loc)
Definition wallet_errors.h:218
no_connection_to_bitmessage(std::string &&loc, const std::string &address)
Definition wallet_errors.h:933
no_connection_to_daemon(std::string &&loc, const std::string &request)
Definition wallet_errors.h:867
nonzero_unlock_time(std::string &&loc)
Definition wallet_errors.h:803
std::string to_string() const
Definition wallet_errors.h:527
uint64_t available() const
Definition wallet_errors.h:524
uint64_t m_tx_amount
Definition wallet_errors.h:538
uint64_t m_available
Definition wallet_errors.h:537
not_enough_money(std::string &&loc, uint64_t available, uint64_t tx_amount, uint64_t fee)
Definition wallet_errors.h:517
uint64_t tx_amount() const
Definition wallet_errors.h:525
not_enough_outs_to_mix(std::string &&loc, const scanty_outs_t &scanty_outs, size_t mixin_count)
Definition wallet_errors.h:575
const scanty_outs_t & scanty_outs() const
Definition wallet_errors.h:582
size_t mixin_count() const
Definition wallet_errors.h:583
scanty_outs_t m_scanty_outs
Definition wallet_errors.h:597
std::string to_string() const
Definition wallet_errors.h:585
size_t m_mixin_count
Definition wallet_errors.h:598
std::unordered_map< uint64_t, uint64_t > scanty_outs_t
Definition wallet_errors.h:573
not_enough_unlocked_money(std::string &&loc, uint64_t available, uint64_t tx_amount, uint64_t fee)
Definition wallet_errors.h:491
uint64_t tx_amount() const
Definition wallet_errors.h:499
uint64_t available() const
Definition wallet_errors.h:498
std::string to_string() const
Definition wallet_errors.h:501
uint64_t m_tx_amount
Definition wallet_errors.h:512
uint64_t m_available
Definition wallet_errors.h:511
out_of_hashchain_bounds_error(std::string &&loc)
Definition wallet_errors.h:442
std::string to_string() const
Definition wallet_errors.h:447
password_entry_failed(std::string &&loc, const std::string &msg="Password entry failed")
Definition wallet_errors.h:234
password_needed(std::string &&loc, const std::string &msg="Password needed")
Definition wallet_errors.h:226
payment_required(std::string &&loc, const std::string &request)
Definition wallet_errors.h:899
refresh_error(std::string &&loc, const std::string &message)
Definition wallet_errors.h:335
reorg_depth_error(std::string &&loc, const std::string &message)
Definition wallet_errors.h:452
std::string to_string() const
Definition wallet_errors.h:457
scan_tx_error(std::string &&loc, const std::string &message)
Definition wallet_errors.h:950
signature_check_failed(std::string &&loc, const std::string &message)
Definition wallet_errors.h:472
subtract_fee_from_bad_index(std::string &&loc, long bad_index)
Definition wallet_errors.h:794
transfer_error(std::string &&loc, const std::string &message)
Definition wallet_errors.h:481
tx_not_constructed(std::string &&loc, sources_t const &sources, destinations_t const &destinations, cryptonote::network_type nettype)
Definition wallet_errors.h:606
sources_t m_sources
Definition wallet_errors.h:656
std::vector< cryptonote::tx_source_entry > sources_t
Definition wallet_errors.h:603
std::string to_string() const
Definition wallet_errors.h:622
std::vector< cryptonote::tx_destination_entry > destinations_t
Definition wallet_errors.h:604
destinations_t m_destinations
Definition wallet_errors.h:657
cryptonote::network_type m_nettype
Definition wallet_errors.h:658
const sources_t & sources() const
Definition wallet_errors.h:619
const destinations_t & destinations() const
Definition wallet_errors.h:620
uint64_t m_fee
Definition wallet_errors.h:568
uint64_t m_tx_amount
Definition wallet_errors.h:567
uint64_t m_available
Definition wallet_errors.h:566
std::string to_string() const
Definition wallet_errors.h:555
uint64_t available() const
Definition wallet_errors.h:551
uint64_t tx_amount() const
Definition wallet_errors.h:552
tx_not_possible(std::string &&loc, uint64_t available, uint64_t tx_amount, uint64_t fee)
Definition wallet_errors.h:543
uint64_t fee() const
Definition wallet_errors.h:553
const cryptonote::blobdata & tx_blob() const
Definition wallet_errors.h:422
tx_parse_error(std::string &&loc, const cryptonote::blobdata &tx_blob)
Definition wallet_errors.h:416
std::string to_string() const
Definition wallet_errors.h:424
cryptonote::blobdata m_tx_blob
Definition wallet_errors.h:427
std::string m_reason
Definition wallet_errors.h:691
const cryptonote::transaction & tx() const
Definition wallet_errors.h:671
cryptonote::transaction m_tx
Definition wallet_errors.h:689
const std::string & reason() const
Definition wallet_errors.h:673
std::string m_status
Definition wallet_errors.h:690
std::string to_string() const
Definition wallet_errors.h:675
tx_rejected(std::string &&loc, const cryptonote::transaction &tx, const std::string &status, const std::string &reason)
Definition wallet_errors.h:663
const std::string & status() const
Definition wallet_errors.h:672
uint64_t fee() const
Definition wallet_errors.h:710
const std::vector< cryptonote::tx_destination_entry > & destinations() const
Definition wallet_errors.h:709
uint64_t m_fee
Definition wallet_errors.h:727
cryptonote::network_type m_nettype
Definition wallet_errors.h:728
std::vector< cryptonote::tx_destination_entry > m_destinations
Definition wallet_errors.h:726
tx_sum_overflow(std::string &&loc, const std::vector< cryptonote::tx_destination_entry > &destinations, uint64_t fee, cryptonote::network_type nettype)
Definition wallet_errors.h:696
std::string to_string() const
Definition wallet_errors.h:712
std::string to_string() const
Definition wallet_errors.h:755
tx_too_big(std::string &&loc, uint64_t tx_weight, uint64_t tx_weight_limit)
Definition wallet_errors.h:742
uint64_t tx_weight() const
Definition wallet_errors.h:752
tx_too_big(std::string &&loc, const cryptonote::transaction &tx, uint64_t tx_weight_limit)
Definition wallet_errors.h:733
cryptonote::transaction m_tx
Definition wallet_errors.h:770
const cryptonote::transaction & tx() const
Definition wallet_errors.h:751
uint64_t tx_weight_limit() const
Definition wallet_errors.h:753
bool tx_valid() const
Definition wallet_errors.h:750
uint64_t m_tx_weight
Definition wallet_errors.h:772
bool m_tx_valid
Definition wallet_errors.h:771
uint64_t m_tx_weight_limit
Definition wallet_errors.h:773
unexpected_txin_type(std::string &&loc, const cryptonote::transaction &tx)
Definition wallet_errors.h:180
const cryptonote::transaction & tx() const
Definition wallet_errors.h:186
std::string to_string() const
Definition wallet_errors.h:188
cryptonote::transaction m_tx
Definition wallet_errors.h:197
wallet_coded_rpc_error(std::string &&loc, const std::string &request, int code, const std::string &status)
Definition wallet_errors.h:845
int m_code
Definition wallet_errors.h:853
int code() const
Definition wallet_errors.h:850
const std::string m_status
Definition wallet_errors.h:854
const std::string & status() const
Definition wallet_errors.h:851
Definition wallet_errors.h:110
wallet_error_base(std::string &&loc, const std::string &message)
Definition wallet_errors.h:121
std::string to_string() const
Definition wallet_errors.h:113
const std::string & location() const
Definition wallet_errors.h:111
std::string m_loc
Definition wallet_errors.h:128
std::string to_string() const
Definition wallet_errors.h:915
const std::string & wallet_file() const
Definition wallet_errors.h:913
std::string m_keys_file
Definition wallet_errors.h:918
const std::string & keys_file() const
Definition wallet_errors.h:912
std::string m_wallet_file
Definition wallet_errors.h:919
wallet_files_doesnt_correspond(std::string &&loc, const std::string &keys_file, const std::string &wallet_file)
Definition wallet_errors.h:907
const std::string & status() const
Definition wallet_errors.h:838
wallet_generic_rpc_error(std::string &&loc, const std::string &request, const std::string &status)
Definition wallet_errors.h:833
const std::string m_status
Definition wallet_errors.h:840
wallet_internal_error(std::string &&loc, const std::string &message)
Definition wallet_errors.h:172
wallet_not_initialized(std::string &&loc)
Definition wallet_errors.h:202
const std::string & request() const
Definition wallet_errors.h:811
std::string to_string() const
Definition wallet_errors.h:813
wallet_rpc_error(std::string &&loc, const std::string &message, const std::string &request)
Definition wallet_errors.h:821
std::string m_request
Definition wallet_errors.h:828
wont_reprocess_recent_txs_via_untrusted_daemon(std::string &&loc)
Definition wallet_errors.h:958
zero_amount(std::string &&loc)
Definition wallet_errors.h:778
zero_destination(std::string &&loc)
Definition wallet_errors.h:786