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 // refresh_error *
67 // acc_outs_lookup_error
68 // block_parse_error
69 // get_blocks_error
70 // get_hashes_error
71 // get_out_indexes_error
72 // tx_parse_error
73 // get_tx_pool_error
74 // out_of_hashchain_bounds_error
75 // signature_check_failed
76 // transfer_error *
77 // get_outs_general_error
78 // not_enough_unlocked_money
79 // not_enough_money
80 // tx_not_possible
81 // not_enough_outs_to_mix
82 // tx_not_constructed
83 // tx_rejected
84 // tx_sum_overflow
85 // tx_too_big
86 // zero_amount
87 // zero_destination
88 // wallet_rpc_error *
89 // daemon_busy
90 // no_connection_to_daemon
91 // is_key_image_spent_error
92 // get_histogram_error
93 // get_output_distribution
94 // payment_required
95 // wallet_files_doesnt_correspond
96 //
97 // * - class with protected ctor
98
99 //----------------------------------------------------------------------------------------------------
100 template<typename Base>
101 struct wallet_error_base : public Base
102 {
103 const std::string& location() const { return m_loc; }
104
105 std::string to_string() const
106 {
107 std::ostringstream ss;
108 ss << m_loc << ':' << typeid(*this).name() << ": " << Base::what();
109 return ss.str();
110 }
111
112 protected:
113 wallet_error_base(std::string&& loc, const std::string& message)
114 : Base(message)
115 , m_loc(loc)
116 {
117 }
118
119 private:
120 std::string m_loc;
121 };
122 //----------------------------------------------------------------------------------------------------
123 const char* const failed_rpc_request_messages[] = {
124 "failed to get blocks",
125 "failed to get hashes",
126 "failed to get out indices",
127 "failed to get random outs"
128 };
130 {
135 };
136
137 template<typename Base, int msg_index>
138 struct failed_rpc_request : public Base
139 {
140 explicit failed_rpc_request(std::string&& loc, const std::string& status)
141 : Base(std::move(loc), failed_rpc_request_messages[msg_index])
143 {
144 }
145
146 const std::string& status() const { return m_status; }
147
148 std::string to_string() const
149 {
150 std::ostringstream ss;
151 ss << Base::to_string() << ", status = " << status();
152 return ss.str();
153 }
154
155 private:
156 std::string m_status;
157 };
158 //----------------------------------------------------------------------------------------------------
161 //----------------------------------------------------------------------------------------------------
163 {
164 explicit wallet_internal_error(std::string&& loc, const std::string& message)
165 : wallet_runtime_error(std::move(loc), message)
166 {
167 }
168 };
169 //----------------------------------------------------------------------------------------------------
171 {
172 explicit unexpected_txin_type(std::string&& loc, const cryptonote::transaction& tx)
173 : wallet_internal_error(std::move(loc), "one of tx inputs has unexpected type")
174 , m_tx(tx)
175 {
176 }
177
178 const cryptonote::transaction& tx() const { return m_tx; }
179
180 std::string to_string() const
181 {
182 std::ostringstream ss;
185 return ss.str();
186 }
187
188 private:
190 };
191 //----------------------------------------------------------------------------------------------------
193 {
194 explicit wallet_not_initialized(std::string&& loc)
195 : wallet_internal_error(std::move(loc), "wallet is not initialized")
196 {
197 }
198 };
199 //----------------------------------------------------------------------------------------------------
201 {
202 explicit multisig_export_needed(std::string&& loc)
203 : wallet_runtime_error(std::move(loc), "This signature was made with stale data: export fresh multisig data, which other participants must then use")
204 {
205 }
206 };
207 //----------------------------------------------------------------------------------------------------
209 {
210 explicit multisig_import_needed(std::string&& loc)
211 : wallet_runtime_error(std::move(loc), "Not enough multisig data was found to sign: import multisig data from more other participants")
212 {
213 }
214 };
215 //----------------------------------------------------------------------------------------------------
217 {
218 explicit password_needed(std::string&& loc, const std::string &msg = "Password needed")
219 : wallet_runtime_error(std::move(loc), msg)
220 {
221 }
222 };
223 //----------------------------------------------------------------------------------------------------
225 {
226 explicit password_entry_failed(std::string&& loc, const std::string &msg = "Password entry failed")
227 : wallet_runtime_error(std::move(loc), msg)
228 {
229 }
230 };
231 //----------------------------------------------------------------------------------------------------
232 const char* const file_error_messages[] = {
233 "file already exists",
234 "file not found",
235 "failed to read file",
236 "failed to save file"
237 };
239 {
244 };
245
246 template<int msg_index>
248 {
249 explicit file_error_base(std::string&& loc, const std::string& file)
250 : wallet_logic_error(std::move(loc), std::string(file_error_messages[msg_index]) + " \"" + file + '\"')
251 , m_file(file)
252 {
253 }
254
255 explicit file_error_base(std::string&& loc, const std::string& file, const std::error_code &e)
256 : wallet_logic_error(std::move(loc), std::string(file_error_messages[msg_index]) + " \"" + file + "\": " + e.message())
257 , m_file(file)
258 {
259 }
260
261 const std::string& file() const { return m_file; }
262
263 std::string to_string() const { return wallet_logic_error::to_string(); }
264
265 private:
266 std::string m_file;
267 };
268 //----------------------------------------------------------------------------------------------------
273 //----------------------------------------------------------------------------------------------------
275 {
276 explicit invalid_password(std::string&& loc)
277 : wallet_logic_error(std::move(loc), "invalid password")
278 {
279 }
280
281 std::string to_string() const { return wallet_logic_error::to_string(); }
282 };
284 {
285 explicit invalid_priority(std::string&& loc)
286 : wallet_logic_error(std::move(loc), "invalid priority")
287 {
288 }
289
290 std::string to_string() const { return wallet_logic_error::to_string(); }
291 };
292
294 {
295 explicit invalid_multisig_seed(std::string&& loc)
296 : wallet_logic_error(std::move(loc), "invalid multisig seed")
297 {
298 }
299
300 std::string to_string() const { return wallet_logic_error::to_string(); }
301 };
302
303 //----------------------------------------------------------------------------------------------------
305 {
306 explicit invalid_pregenerated_random (std::string&& loc)
307 : wallet_logic_error(std::move(loc), "invalid pregenerated random for wallet creation/recovery")
308 {
309 }
310
311 std::string to_string() const { return wallet_logic_error::to_string(); }
312 };
313 //----------------------------------------------------------------------------------------------------
315 {
316 protected:
317 explicit refresh_error(std::string&& loc, const std::string& message)
318 : wallet_logic_error(std::move(loc), message)
319 {
320 }
321 };
322 //----------------------------------------------------------------------------------------------------
324 {
325 explicit index_outofbound(std::string&& loc, const std::string& message)
326 : wallet_logic_error(std::move(loc), message)
327 {
328 }
329 };
331 {
332 explicit account_index_outofbound(std::string&& loc)
333 : index_outofbound(std::move(loc), "account index is out of bound")
334 {
335 }
336 };
338 {
339 explicit address_index_outofbound(std::string&& loc)
340 : index_outofbound(std::move(loc), "address index is out of bound")
341 {
342 }
343 };
344 //----------------------------------------------------------------------------------------------------
346 {
347 explicit acc_outs_lookup_error(std::string&& loc, const cryptonote::transaction& tx,
349 : refresh_error(std::move(loc), "account outs lookup error")
350 , m_tx(tx)
353 {
354 }
355
356 const cryptonote::transaction& tx() const { return m_tx; }
357 const crypto::public_key& tx_pub_key() const { return m_tx_pub_key; }
359
360 std::string to_string() const
361 {
362 std::ostringstream ss;
365 return ss.str();
366 }
367
368 private:
372 };
373 //----------------------------------------------------------------------------------------------------
375 {
376 explicit block_parse_error(std::string&& loc, const cryptonote::blobdata& block_data)
377 : refresh_error(std::move(loc), "block parse error")
378 , m_block_blob(block_data)
379 {
380 }
381
383
384 std::string to_string() const { return refresh_error::to_string(); }
385
386 private:
388 };
389 //----------------------------------------------------------------------------------------------------
391 //----------------------------------------------------------------------------------------------------
393 //----------------------------------------------------------------------------------------------------
395 //----------------------------------------------------------------------------------------------------
397 {
398 explicit tx_parse_error(std::string&& loc, const cryptonote::blobdata& tx_blob)
399 : refresh_error(std::move(loc), "transaction parse error")
401 {
402 }
403
404 const cryptonote::blobdata& tx_blob() const { return m_tx_blob; }
405
406 std::string to_string() const { return refresh_error::to_string(); }
407
408 private:
410 };
411 //----------------------------------------------------------------------------------------------------
413 {
414 explicit get_tx_pool_error(std::string&& loc)
415 : refresh_error(std::move(loc), "error getting transaction pool")
416 {
417 }
418
419 std::string to_string() const { return refresh_error::to_string(); }
420 };
421 //----------------------------------------------------------------------------------------------------
423 {
424 explicit out_of_hashchain_bounds_error(std::string&& loc)
425 : refresh_error(std::move(loc), "Index out of bounds of of hashchain")
426 {
427 }
428
429 std::string to_string() const { return refresh_error::to_string(); }
430 };
431 //----------------------------------------------------------------------------------------------------
433 {
434 explicit reorg_depth_error(std::string&& loc, const std::string& message)
435 : refresh_error(std::move(loc), message)
436 {
437 }
438
439 std::string to_string() const { return refresh_error::to_string(); }
440 };
441 //----------------------------------------------------------------------------------------------------
443 {
444 explicit incorrect_fork_version(std::string&& loc, const std::string& message)
445 : refresh_error(std::move(loc), message)
446 {
447 }
448
449 std::string to_string() const { return refresh_error::to_string(); }
450 };
451 //----------------------------------------------------------------------------------------------------
453 {
454 explicit signature_check_failed(std::string&& loc, const std::string& message)
455 : wallet_logic_error(std::move(loc), "Signature check failed " + message)
456 {
457 }
458 };
459 //----------------------------------------------------------------------------------------------------
461 {
462 protected:
463 explicit transfer_error(std::string&& loc, const std::string& message)
464 : wallet_logic_error(std::move(loc), message)
465 {
466 }
467 };
468 //----------------------------------------------------------------------------------------------------
470 //----------------------------------------------------------------------------------------------------
472 {
474 : transfer_error(std::move(loc), "not enough unlocked money")
477 {
478 }
479
480 uint64_t available() const { return m_available; }
481 uint64_t tx_amount() const { return m_tx_amount; }
482
483 std::string to_string() const
484 {
485 std::ostringstream ss;
487 ", available = " << cryptonote::print_money(m_available) <<
488 ", tx_amount = " << cryptonote::print_money(m_tx_amount);
489 return ss.str();
490 }
491
492 private:
495 };
496 //----------------------------------------------------------------------------------------------------
498 {
500 : transfer_error(std::move(loc), "not enough money")
503 {
504 }
505
506 uint64_t available() const { return m_available; }
507 uint64_t tx_amount() const { return m_tx_amount; }
508
509 std::string to_string() const
510 {
511 std::ostringstream ss;
513 ", available = " << cryptonote::print_money(m_available) <<
514 ", tx_amount = " << cryptonote::print_money(m_tx_amount);
515 return ss.str();
516 }
517
518 private:
521 };
522 //----------------------------------------------------------------------------------------------------
524 {
526 : transfer_error(std::move(loc), "tx not possible")
529 , m_fee(fee)
530 {
531 }
532
533 uint64_t available() const { return m_available; }
534 uint64_t tx_amount() const { return m_tx_amount; }
535 uint64_t fee() const { return m_fee; }
536
537 std::string to_string() const
538 {
539 std::ostringstream ss;
541 ", available = " << cryptonote::print_money(m_available) <<
542 ", tx_amount = " << cryptonote::print_money(m_tx_amount) <<
543 ", fee = " << cryptonote::print_money(m_fee);
544 return ss.str();
545 }
546
547 private:
551 };
552 //----------------------------------------------------------------------------------------------------
554 {
555 typedef std::unordered_map<uint64_t, uint64_t> scanty_outs_t;
556
557 explicit not_enough_outs_to_mix(std::string&& loc, const scanty_outs_t& scanty_outs, size_t mixin_count)
558 : transfer_error(std::move(loc), "not enough outputs to use")
561 {
562 }
563
564 const scanty_outs_t& scanty_outs() const { return m_scanty_outs; }
565 size_t mixin_count() const { return m_mixin_count; }
566
567 std::string to_string() const
568 {
569 std::ostringstream ss;
570 ss << transfer_error::to_string() << ", ring size = " << (m_mixin_count + 1) << ", scanty_outs:";
571 for (const auto& out: m_scanty_outs)
572 {
573 ss << '\n' << cryptonote::print_money(out.first) << " - " << out.second;
574 }
575 return ss.str();
576 }
577
578 private:
581 };
582 //----------------------------------------------------------------------------------------------------
584 {
585 typedef std::vector<cryptonote::tx_source_entry> sources_t;
586 typedef std::vector<cryptonote::tx_destination_entry> destinations_t;
587
589 std::string && loc
590 , sources_t const & sources
594 )
595 : transfer_error(std::move(loc), "transaction was not constructed")
599 , m_nettype(nettype)
600 {
601 }
602
603 const sources_t& sources() const { return m_sources; }
604 const destinations_t& destinations() const { return m_destinations; }
606
607 std::string to_string() const
608 {
609 std::ostringstream ss;
611 ss << "\nSources:";
612 for (size_t i = 0; i < m_sources.size(); ++i)
613 {
615 ss << "\n source " << i << ":";
616 ss << "\n amount: " << cryptonote::print_money(src.amount);
617 // It's not good, if logs will contain such much data
618 //ss << "\n real_output: " << src.real_output;
619 //ss << "\n real_output_in_tx_index: " << src.real_output_in_tx_index;
620 //ss << "\n real_out_tx_key: " << epee::string_tools::pod_to_hex(src.real_out_tx_key);
621 //ss << "\n outputs:";
622 //for (size_t j = 0; j < src.outputs.size(); ++j)
623 //{
624 // const cryptonote::tx_source_entry::output_entry& out = src.outputs[j];
625 // ss << "\n " << j << ": " << out.first << ", " << epee::string_tools::pod_to_hex(out.second);
626 //}
627 }
628
629 ss << "\nDestinations:";
630 for (size_t i = 0; i < m_destinations.size(); ++i)
631 {
633 ss << "\n " << i << ": " << cryptonote::get_account_address_as_str(m_nettype, dst.is_subaddress, dst.addr) << " " <<
635 }
636
637 ss << "\nunlock_time: " << m_unlock_time;
638
639 return ss.str();
640 }
641
642 private:
647 };
648 //----------------------------------------------------------------------------------------------------
650 {
651 explicit tx_rejected(std::string&& loc, const cryptonote::transaction& tx, const std::string& status, const std::string& reason)
652 : transfer_error(std::move(loc), "transaction was rejected by daemon")
653 , m_tx(tx)
656 {
657 }
658
659 const cryptonote::transaction& tx() const { return m_tx; }
660 const std::string& status() const { return m_status; }
661 const std::string& reason() const { return m_reason; }
662
663 std::string to_string() const
664 {
665 std::ostringstream ss;
666 ss << transfer_error::to_string() << ", status = " << m_status << ", tx:\n";
669 if (!m_reason.empty())
670 {
671 ss << " (" << m_reason << ")";
672 }
673 return ss.str();
674 }
675
676 private:
678 std::string m_status;
679 std::string m_reason;
680 };
681 //----------------------------------------------------------------------------------------------------
683 {
685 std::string && loc
686 , const std::vector<cryptonote::tx_destination_entry>& destinations
687 , uint64_t fee
689 )
690 : transfer_error(std::move(loc), "transaction sum + fee exceeds " + cryptonote::print_money(std::numeric_limits<uint64_t>::max()))
692 , m_fee(fee)
693 , m_nettype(nettype)
694 {
695 }
696
697 const std::vector<cryptonote::tx_destination_entry>& destinations() const { return m_destinations; }
698 uint64_t fee() const { return m_fee; }
699
700 std::string to_string() const
701 {
702 std::ostringstream ss;
704 ", fee = " << cryptonote::print_money(m_fee) <<
705 ", destinations:";
706 for (const auto& dst : m_destinations)
707 {
708 ss << '\n' << cryptonote::print_money(dst.amount) << " -> " << cryptonote::get_account_address_as_str(m_nettype, dst.is_subaddress, dst.addr);
709 }
710 return ss.str();
711 }
712
713 private:
714 std::vector<cryptonote::tx_destination_entry> m_destinations;
717 };
718 //----------------------------------------------------------------------------------------------------
720 {
721 explicit tx_too_big(std::string&& loc, const cryptonote::transaction& tx, uint64_t tx_weight_limit)
722 : transfer_error(std::move(loc), "transaction is too big")
723 , m_tx(tx)
725 , m_tx_weight(cryptonote::get_transaction_weight(tx))
727 {
728 }
729
731 : transfer_error(std::move(loc), "transaction would be too big")
735 {
736 }
737
738 bool tx_valid() const { return m_tx_valid; }
739 const cryptonote::transaction& tx() const { return m_tx; }
740 uint64_t tx_weight() const { return m_tx_weight; }
742
743 std::string to_string() const
744 {
745 std::ostringstream ss;
747 ", tx_weight_limit = " << m_tx_weight_limit <<
748 ", tx weight = " << m_tx_weight;
749 if (m_tx_valid)
750 {
752 ss << ", tx:\n" << cryptonote::obj_to_json_str(tx);
753 }
754 return ss.str();
755 }
756
757 private:
762 };
763 //----------------------------------------------------------------------------------------------------
765 {
766 explicit zero_amount(std::string&& loc)
767 : transfer_error(std::move(loc), "destination amount is zero")
768 {
769 }
770 };
771 //----------------------------------------------------------------------------------------------------
773 {
774 explicit zero_destination(std::string&& loc)
775 : transfer_error(std::move(loc), "transaction has no destination")
776 {
777 }
778 };
779 //----------------------------------------------------------------------------------------------------
781 {
782 const std::string& request() const { return m_request; }
783
784 std::string to_string() const
785 {
786 std::ostringstream ss;
787 ss << wallet_logic_error::to_string() << ", request = " << m_request;
788 return ss.str();
789 }
790
791 protected:
792 explicit wallet_rpc_error(std::string&& loc, const std::string& message, const std::string& request)
793 : wallet_logic_error(std::move(loc), message)
795 {
796 }
797
798 private:
799 std::string m_request;
800 };
801 //----------------------------------------------------------------------------------------------------
803 {
804 explicit wallet_generic_rpc_error(std::string&& loc, const std::string& request, const std::string& status)
805 : wallet_rpc_error(std::move(loc), std::string("error in ") + request + " RPC: " + status, request),
807 {
808 }
809 const std::string& status() const { return m_status; }
810 private:
811 const std::string m_status;
812 };
813 //----------------------------------------------------------------------------------------------------
815 {
816 explicit wallet_coded_rpc_error(std::string&& loc, const std::string& request, int code, const std::string& status)
817 : wallet_rpc_error(std::move(loc), std::string("error ") + std::to_string(code) + (" in ") + request + " RPC: " + status, request),
819 {
820 }
821 int code() const { return m_code; }
822 const std::string& status() const { return m_status; }
823 private:
825 const std::string m_status;
826 };
827 //----------------------------------------------------------------------------------------------------
829 {
830 explicit daemon_busy(std::string&& loc, const std::string& request)
831 : wallet_rpc_error(std::move(loc), "daemon is busy", request)
832 {
833 }
834 };
835 //----------------------------------------------------------------------------------------------------
837 {
838 explicit no_connection_to_daemon(std::string&& loc, const std::string& request)
839 : wallet_rpc_error(std::move(loc), "no connection to daemon", request)
840 {
841 }
842 };
843 //----------------------------------------------------------------------------------------------------
845 {
846 explicit is_key_image_spent_error(std::string&& loc, const std::string& request)
847 : wallet_rpc_error(std::move(loc), "error from is_key_image_spent call", request)
848 {
849 }
850 };
851 //----------------------------------------------------------------------------------------------------
853 {
854 explicit get_histogram_error(std::string&& loc, const std::string& request)
855 : wallet_rpc_error(std::move(loc), "failed to get output histogram", request)
856 {
857 }
858 };
859 //----------------------------------------------------------------------------------------------------
861 {
862 explicit get_output_distribution(std::string&& loc, const std::string& request)
863 : wallet_rpc_error(std::move(loc), "failed to get output distribution", request)
864 {
865 }
866 };
867 //----------------------------------------------------------------------------------------------------
869 {
870 explicit payment_required(std::string&& loc, const std::string& request)
871 : wallet_rpc_error(std::move(loc), "payment required", request)
872 {
873 }
874 };
875 //----------------------------------------------------------------------------------------------------
877 {
878 explicit wallet_files_doesnt_correspond(std::string&& loc, const std::string& keys_file, const std::string& wallet_file)
879 : wallet_logic_error(std::move(loc), "file " + wallet_file + " does not correspond to " + keys_file)
880 {
881 }
882
883 const std::string& keys_file() const { return m_keys_file; }
884 const std::string& wallet_file() const { return m_wallet_file; }
885
886 std::string to_string() const { return wallet_logic_error::to_string(); }
887
888 private:
889 std::string m_keys_file;
890 std::string m_wallet_file;
891 };
892 //----------------------------------------------------------------------------------------------------
894 {
895 protected:
896 explicit mms_error(std::string&& loc, const std::string& message)
897 : wallet_logic_error(std::move(loc), message)
898 {
899 }
900 };
901 //----------------------------------------------------------------------------------------------------
903 {
904 explicit no_connection_to_bitmessage(std::string&& loc, const std::string& address)
905 : mms_error(std::move(loc), "no connection to PyBitmessage at address " + address)
906 {
907 }
908 };
909 //----------------------------------------------------------------------------------------------------
911 {
912 explicit bitmessage_api_error(std::string&& loc, const std::string& error_string)
913 : mms_error(std::move(loc), "PyBitmessage returned " + error_string)
914 {
915 }
916 };
917 //----------------------------------------------------------------------------------------------------
918
919#if !defined(_MSC_VER)
920
921 template<typename TException, typename... TArgs>
922 void throw_wallet_ex(std::string&& loc, const TArgs&... args)
923 {
924 TException e(std::move(loc), args...);
925 LOG_PRINT_L0(e.to_string());
926 throw e;
927 }
928
929#else
930 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
931 #include <boost/preprocessor/repetition/enum_params.hpp>
932 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
933
934 template<typename TException>
935 void throw_wallet_ex(std::string&& loc)
936 {
937 TException e(std::move(loc));
938 LOG_PRINT_L0(e.to_string());
939 throw e;
940 }
941
942#define GEN_throw_wallet_ex(z, n, data) \
943 template<typename TException, BOOST_PP_ENUM_PARAMS(n, typename TArg)> \
944 void throw_wallet_ex(std::string&& loc, BOOST_PP_ENUM_BINARY_PARAMS(n, const TArg, &arg)) \
945 { \
946 TException e(std::move(loc), BOOST_PP_ENUM_PARAMS(n, arg)); \
947 LOG_PRINT_L0(e.to_string()); \
948 throw e; \
949 }
950
951 BOOST_PP_REPEAT_FROM_TO(1, 6, GEN_throw_wallet_ex, ~)
952#endif
953 }
954}
955
956#define STRINGIZE_DETAIL(x) #x
957#define STRINGIZE(x) STRINGIZE_DETAIL(x)
958
959#define THROW_WALLET_EXCEPTION(err_type, ...) \
960 do { \
961 LOG_ERROR("THROW EXCEPTION: " << #err_type); \
962 tools::error::throw_wallet_ex<err_type>(std::string(__FILE__ ":" STRINGIZE(__LINE__)), ## __VA_ARGS__); \
963 } while(0)
964
965#define THROW_WALLET_EXCEPTION_IF(cond, err_type, ...) \
966 if (cond) \
967 { \
968 LOG_ERROR(#cond << ". THROW EXCEPTION: " << #err_type); \
969 tools::error::throw_wallet_ex<err_type>(std::string(__FILE__ ":" STRINGIZE(__LINE__)), ## __VA_ARGS__); \
970 }
Definition: cryptonote_basic.h:205
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:205
network_type
Definition: cryptonote_config.h:289
std::string print_money(uint64_t amount, unsigned int decimal_point)
Definition: cryptonote_format_utils.cpp:1166
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
file_error_message_indices
Definition: wallet_errors.h:239
@ file_save_error_message_index
Definition: wallet_errors.h:243
@ file_read_error_message_index
Definition: wallet_errors.h:242
@ file_not_found_message_index
Definition: wallet_errors.h:241
@ file_exists_message_index
Definition: wallet_errors.h:240
const char *const file_error_messages[]
Definition: wallet_errors.h:232
file_error_base< file_save_error_message_index > file_save_error
Definition: wallet_errors.h:272
failed_rpc_request_message_indices
Definition: wallet_errors.h:130
@ get_out_indices_error_message_index
Definition: wallet_errors.h:133
@ get_blocks_error_message_index
Definition: wallet_errors.h:131
@ get_hashes_error_message_index
Definition: wallet_errors.h:132
@ get_outs_error_message_index
Definition: wallet_errors.h:134
const char *const failed_rpc_request_messages[]
Definition: wallet_errors.h:123
file_error_base< file_not_found_message_index > file_not_found
Definition: wallet_errors.h:270
failed_rpc_request< refresh_error, get_hashes_error_message_index > get_hashes_error
Definition: wallet_errors.h:392
void throw_wallet_ex(std::string &&loc, const TArgs &... args)
Definition: wallet_errors.h:922
file_error_base< file_exists_message_index > file_exists
Definition: wallet_errors.h:269
failed_rpc_request< refresh_error, get_blocks_error_message_index > get_blocks_error
Definition: wallet_errors.h:390
failed_rpc_request< refresh_error, get_out_indices_error_message_index > get_out_indices_error
Definition: wallet_errors.h:394
failed_rpc_request< transfer_error, get_outs_error_message_index > get_outs_error
Definition: wallet_errors.h:469
file_error_base< file_read_error_message_index > file_read_error
Definition: wallet_errors.h:271
wallet_error_base< std::logic_error > wallet_logic_error
Definition: wallet_errors.h:159
wallet_error_base< std::runtime_error > wallet_runtime_error
Definition: wallet_errors.h:160
Various Tools.
Definition: apply_permutation.h:40
#define true
Definition: stdbool.h:36
#define false
Definition: stdbool.h:37
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
Definition: wallet_errors.h:346
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:347
const crypto::public_key m_tx_pub_key
Definition: wallet_errors.h:370
std::string to_string() const
Definition: wallet_errors.h:360
const crypto::public_key & tx_pub_key() const
Definition: wallet_errors.h:357
const cryptonote::account_keys & acc_keys() const
Definition: wallet_errors.h:358
const cryptonote::account_keys m_acc_keys
Definition: wallet_errors.h:371
const cryptonote::transaction m_tx
Definition: wallet_errors.h:369
const cryptonote::transaction & tx() const
Definition: wallet_errors.h:356
Definition: wallet_errors.h:331
account_index_outofbound(std::string &&loc)
Definition: wallet_errors.h:332
Definition: wallet_errors.h:338
address_index_outofbound(std::string &&loc)
Definition: wallet_errors.h:339
Definition: wallet_errors.h:911
bitmessage_api_error(std::string &&loc, const std::string &error_string)
Definition: wallet_errors.h:912
Definition: wallet_errors.h:375
block_parse_error(std::string &&loc, const cryptonote::blobdata &block_data)
Definition: wallet_errors.h:376
std::string to_string() const
Definition: wallet_errors.h:384
const cryptonote::blobdata & block_blob() const
Definition: wallet_errors.h:382
cryptonote::blobdata m_block_blob
Definition: wallet_errors.h:387
Definition: wallet_errors.h:829
daemon_busy(std::string &&loc, const std::string &request)
Definition: wallet_errors.h:830
Definition: wallet_errors.h:139
std::string to_string() const
Definition: wallet_errors.h:148
const std::string & status() const
Definition: wallet_errors.h:146
std::string m_status
Definition: wallet_errors.h:156
failed_rpc_request(std::string &&loc, const std::string &status)
Definition: wallet_errors.h:140
Definition: wallet_errors.h:248
std::string m_file
Definition: wallet_errors.h:266
file_error_base(std::string &&loc, const std::string &file)
Definition: wallet_errors.h:249
std::string to_string() const
Definition: wallet_errors.h:263
const std::string & file() const
Definition: wallet_errors.h:261
Definition: wallet_errors.h:853
get_histogram_error(std::string &&loc, const std::string &request)
Definition: wallet_errors.h:854
get_output_distribution(std::string &&loc, const std::string &request)
Definition: wallet_errors.h:862
Definition: wallet_errors.h:413
get_tx_pool_error(std::string &&loc)
Definition: wallet_errors.h:414
std::string to_string() const
Definition: wallet_errors.h:419
Definition: wallet_errors.h:443
std::string to_string() const
Definition: wallet_errors.h:449
incorrect_fork_version(std::string &&loc, const std::string &message)
Definition: wallet_errors.h:444
Definition: wallet_errors.h:324
index_outofbound(std::string &&loc, const std::string &message)
Definition: wallet_errors.h:325
Definition: wallet_errors.h:294
invalid_multisig_seed(std::string &&loc)
Definition: wallet_errors.h:295
std::string to_string() const
Definition: wallet_errors.h:300
Definition: wallet_errors.h:275
invalid_password(std::string &&loc)
Definition: wallet_errors.h:276
std::string to_string() const
Definition: wallet_errors.h:281
Definition: wallet_errors.h:305
std::string to_string() const
Definition: wallet_errors.h:311
invalid_pregenerated_random(std::string &&loc)
Definition: wallet_errors.h:306
Definition: wallet_errors.h:284
invalid_priority(std::string &&loc)
Definition: wallet_errors.h:285
std::string to_string() const
Definition: wallet_errors.h:290
Definition: wallet_errors.h:845
is_key_image_spent_error(std::string &&loc, const std::string &request)
Definition: wallet_errors.h:846
Definition: wallet_errors.h:894
mms_error(std::string &&loc, const std::string &message)
Definition: wallet_errors.h:896
Definition: wallet_errors.h:201
multisig_export_needed(std::string &&loc)
Definition: wallet_errors.h:202
Definition: wallet_errors.h:209
multisig_import_needed(std::string &&loc)
Definition: wallet_errors.h:210
Definition: wallet_errors.h:903
no_connection_to_bitmessage(std::string &&loc, const std::string &address)
Definition: wallet_errors.h:904
Definition: wallet_errors.h:837
no_connection_to_daemon(std::string &&loc, const std::string &request)
Definition: wallet_errors.h:838
Definition: wallet_errors.h:498
std::string to_string() const
Definition: wallet_errors.h:509
uint64_t available() const
Definition: wallet_errors.h:506
uint64_t m_tx_amount
Definition: wallet_errors.h:520
uint64_t m_available
Definition: wallet_errors.h:519
not_enough_money(std::string &&loc, uint64_t available, uint64_t tx_amount, uint64_t fee)
Definition: wallet_errors.h:499
uint64_t tx_amount() const
Definition: wallet_errors.h:507
Definition: wallet_errors.h:554
not_enough_outs_to_mix(std::string &&loc, const scanty_outs_t &scanty_outs, size_t mixin_count)
Definition: wallet_errors.h:557
const scanty_outs_t & scanty_outs() const
Definition: wallet_errors.h:564
size_t mixin_count() const
Definition: wallet_errors.h:565
scanty_outs_t m_scanty_outs
Definition: wallet_errors.h:579
std::string to_string() const
Definition: wallet_errors.h:567
size_t m_mixin_count
Definition: wallet_errors.h:580
std::unordered_map< uint64_t, uint64_t > scanty_outs_t
Definition: wallet_errors.h:555
Definition: wallet_errors.h:472
not_enough_unlocked_money(std::string &&loc, uint64_t available, uint64_t tx_amount, uint64_t fee)
Definition: wallet_errors.h:473
uint64_t tx_amount() const
Definition: wallet_errors.h:481
uint64_t available() const
Definition: wallet_errors.h:480
std::string to_string() const
Definition: wallet_errors.h:483
uint64_t m_tx_amount
Definition: wallet_errors.h:494
uint64_t m_available
Definition: wallet_errors.h:493
Definition: wallet_errors.h:423
out_of_hashchain_bounds_error(std::string &&loc)
Definition: wallet_errors.h:424
std::string to_string() const
Definition: wallet_errors.h:429
Definition: wallet_errors.h:225
password_entry_failed(std::string &&loc, const std::string &msg="Password entry failed")
Definition: wallet_errors.h:226
Definition: wallet_errors.h:217
password_needed(std::string &&loc, const std::string &msg="Password needed")
Definition: wallet_errors.h:218
Definition: wallet_errors.h:869
payment_required(std::string &&loc, const std::string &request)
Definition: wallet_errors.h:870
Definition: wallet_errors.h:315
refresh_error(std::string &&loc, const std::string &message)
Definition: wallet_errors.h:317
Definition: wallet_errors.h:433
reorg_depth_error(std::string &&loc, const std::string &message)
Definition: wallet_errors.h:434
std::string to_string() const
Definition: wallet_errors.h:439
Definition: wallet_errors.h:453
signature_check_failed(std::string &&loc, const std::string &message)
Definition: wallet_errors.h:454
Definition: wallet_errors.h:461
transfer_error(std::string &&loc, const std::string &message)
Definition: wallet_errors.h:463
Definition: wallet_errors.h:584
sources_t m_sources
Definition: wallet_errors.h:643
std::vector< cryptonote::tx_source_entry > sources_t
Definition: wallet_errors.h:585
std::string to_string() const
Definition: wallet_errors.h:607
tx_not_constructed(std::string &&loc, sources_t const &sources, destinations_t const &destinations, uint64_t unlock_time, cryptonote::network_type nettype)
Definition: wallet_errors.h:588
uint64_t m_unlock_time
Definition: wallet_errors.h:645
std::vector< cryptonote::tx_destination_entry > destinations_t
Definition: wallet_errors.h:586
destinations_t m_destinations
Definition: wallet_errors.h:644
cryptonote::network_type m_nettype
Definition: wallet_errors.h:646
const sources_t & sources() const
Definition: wallet_errors.h:603
uint64_t unlock_time() const
Definition: wallet_errors.h:605
const destinations_t & destinations() const
Definition: wallet_errors.h:604
Definition: wallet_errors.h:524
uint64_t m_fee
Definition: wallet_errors.h:550
uint64_t m_tx_amount
Definition: wallet_errors.h:549
uint64_t m_available
Definition: wallet_errors.h:548
std::string to_string() const
Definition: wallet_errors.h:537
uint64_t available() const
Definition: wallet_errors.h:533
uint64_t tx_amount() const
Definition: wallet_errors.h:534
tx_not_possible(std::string &&loc, uint64_t available, uint64_t tx_amount, uint64_t fee)
Definition: wallet_errors.h:525
uint64_t fee() const
Definition: wallet_errors.h:535
Definition: wallet_errors.h:397
const cryptonote::blobdata & tx_blob() const
Definition: wallet_errors.h:404
tx_parse_error(std::string &&loc, const cryptonote::blobdata &tx_blob)
Definition: wallet_errors.h:398
std::string to_string() const
Definition: wallet_errors.h:406
cryptonote::blobdata m_tx_blob
Definition: wallet_errors.h:409
Definition: wallet_errors.h:650
std::string m_reason
Definition: wallet_errors.h:679
const cryptonote::transaction & tx() const
Definition: wallet_errors.h:659
cryptonote::transaction m_tx
Definition: wallet_errors.h:677
const std::string & reason() const
Definition: wallet_errors.h:661
std::string m_status
Definition: wallet_errors.h:678
std::string to_string() const
Definition: wallet_errors.h:663
tx_rejected(std::string &&loc, const cryptonote::transaction &tx, const std::string &status, const std::string &reason)
Definition: wallet_errors.h:651
const std::string & status() const
Definition: wallet_errors.h:660
Definition: wallet_errors.h:683
uint64_t fee() const
Definition: wallet_errors.h:698
const std::vector< cryptonote::tx_destination_entry > & destinations() const
Definition: wallet_errors.h:697
uint64_t m_fee
Definition: wallet_errors.h:715
cryptonote::network_type m_nettype
Definition: wallet_errors.h:716
std::vector< cryptonote::tx_destination_entry > m_destinations
Definition: wallet_errors.h:714
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:684
std::string to_string() const
Definition: wallet_errors.h:700
Definition: wallet_errors.h:720
std::string to_string() const
Definition: wallet_errors.h:743
tx_too_big(std::string &&loc, uint64_t tx_weight, uint64_t tx_weight_limit)
Definition: wallet_errors.h:730
uint64_t tx_weight() const
Definition: wallet_errors.h:740
tx_too_big(std::string &&loc, const cryptonote::transaction &tx, uint64_t tx_weight_limit)
Definition: wallet_errors.h:721
cryptonote::transaction m_tx
Definition: wallet_errors.h:758
const cryptonote::transaction & tx() const
Definition: wallet_errors.h:739
uint64_t tx_weight_limit() const
Definition: wallet_errors.h:741
bool tx_valid() const
Definition: wallet_errors.h:738
uint64_t m_tx_weight
Definition: wallet_errors.h:760
bool m_tx_valid
Definition: wallet_errors.h:759
uint64_t m_tx_weight_limit
Definition: wallet_errors.h:761
Definition: wallet_errors.h:171
unexpected_txin_type(std::string &&loc, const cryptonote::transaction &tx)
Definition: wallet_errors.h:172
const cryptonote::transaction & tx() const
Definition: wallet_errors.h:178
std::string to_string() const
Definition: wallet_errors.h:180
cryptonote::transaction m_tx
Definition: wallet_errors.h:189
Definition: wallet_errors.h:815
wallet_coded_rpc_error(std::string &&loc, const std::string &request, int code, const std::string &status)
Definition: wallet_errors.h:816
int m_code
Definition: wallet_errors.h:824
int code() const
Definition: wallet_errors.h:821
const std::string m_status
Definition: wallet_errors.h:825
const std::string & status() const
Definition: wallet_errors.h:822
Definition: wallet_errors.h:102
wallet_error_base(std::string &&loc, const std::string &message)
Definition: wallet_errors.h:113
std::string to_string() const
Definition: wallet_errors.h:105
const std::string & location() const
Definition: wallet_errors.h:103
std::string m_loc
Definition: wallet_errors.h:120
Definition: wallet_errors.h:877
std::string to_string() const
Definition: wallet_errors.h:886
const std::string & wallet_file() const
Definition: wallet_errors.h:884
std::string m_keys_file
Definition: wallet_errors.h:889
const std::string & keys_file() const
Definition: wallet_errors.h:883
std::string m_wallet_file
Definition: wallet_errors.h:890
wallet_files_doesnt_correspond(std::string &&loc, const std::string &keys_file, const std::string &wallet_file)
Definition: wallet_errors.h:878
Definition: wallet_errors.h:803
const std::string & status() const
Definition: wallet_errors.h:809
wallet_generic_rpc_error(std::string &&loc, const std::string &request, const std::string &status)
Definition: wallet_errors.h:804
const std::string m_status
Definition: wallet_errors.h:811
Definition: wallet_errors.h:163
wallet_internal_error(std::string &&loc, const std::string &message)
Definition: wallet_errors.h:164
Definition: wallet_errors.h:193
wallet_not_initialized(std::string &&loc)
Definition: wallet_errors.h:194
Definition: wallet_errors.h:781
const std::string & request() const
Definition: wallet_errors.h:782
std::string to_string() const
Definition: wallet_errors.h:784
wallet_rpc_error(std::string &&loc, const std::string &message, const std::string &request)
Definition: wallet_errors.h:792
std::string m_request
Definition: wallet_errors.h:799
Definition: wallet_errors.h:765
zero_amount(std::string &&loc)
Definition: wallet_errors.h:766
Definition: wallet_errors.h:773
zero_destination(std::string &&loc)
Definition: wallet_errors.h:774