Electroneum
Loading...
Searching...
No Matches
wallet_errors.h
Go to the documentation of this file.
1// Copyrights(c) 2017-2021, The Electroneum Project
2// Copyrights(c) 2014-2019, The Monero Project
3//
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without modification, are
7// permitted provided that the following conditions are met:
8//
9// 1. Redistributions of source code must retain the above copyright notice, this list of
10// conditions and the following disclaimer.
11//
12// 2. Redistributions in binary form must reproduce the above copyright notice, this list
13// of conditions and the following disclaimer in the documentation and/or other
14// materials provided with the distribution.
15//
16// 3. Neither the name of the copyright holder nor the names of its contributors may be
17// used to endorse or promote products derived from this software without specific
18// prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29//
30// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
31
32#pragma once
33
34#include <stdexcept>
35#include <system_error>
36#include <string>
37#include <vector>
38
42#include "include_base_utils.h"
43
44
45namespace tools
46{
47 namespace error
48 {
49 // std::exception
50 // std::runtime_error
51 // wallet_runtime_error *
52 // wallet_internal_error
53 // unexpected_txin_type
54 // unexpected_txout_type
55 // wallet_not_initialized
56 // multisig_export_needed
57 // multisig_import_needed
58 // password_needed
59 // std::logic_error
60 // wallet_logic_error *
61 // file_exists
62 // file_not_found
63 // file_read_error
64 // file_save_error
65 // invalid_password
66 // invalid_priority
67 // invalid_multisig_seed
68 // refresh_error *
69 // acc_outs_lookup_error
70 // block_parse_error
71 // get_blocks_error
72 // get_hashes_error
73 // get_out_indexes_error
74 // tx_parse_error
75 // get_tx_pool_error
76 // out_of_hashchain_bounds_error
77 // signature_check_failed
78 // transfer_error *
79 // get_outs_general_error
80 // not_enough_unlocked_etn
81 // not_enough_etn
82 // tx_not_possible
83 // not_enough_outs_to_mix
84 // tx_not_constructed
85 // tx_rejected
86 // tx_sum_overflow
87 // tx_too_big
88 // zero_destination
89 // wallet_rpc_error *
90 // daemon_busy
91 // no_connection_to_daemon
92 // is_key_image_spent_error
93 // is_public_output_spent_error
94 // get_histogram_error
95 // get_output_distribution
96 // wallet_files_doesnt_correspond
97 //
98 // * - class with protected ctor
99
100 //----------------------------------------------------------------------------------------------------
101 template<typename Base>
102 struct wallet_error_base : public Base
103 {
104 const std::string& location() const { return m_loc; }
105
106 std::string to_string() const
107 {
108 std::ostringstream ss;
109 ss << m_loc << ':' << typeid(*this).name() << ": " << Base::what();
110 return ss.str();
111 }
112
113 protected:
114 wallet_error_base(std::string&& loc, const std::string& message)
115 : Base(message)
116 , m_loc(loc)
117 {
118 }
119
120 private:
121 std::string m_loc;
122 };
123 //----------------------------------------------------------------------------------------------------
124 const char* const failed_rpc_request_messages[] = {
125 "failed to get blocks",
126 "failed to get hashes",
127 "failed to get out indices",
128 "failed to get random outs"
129 };
137
138 template<typename Base, int msg_index>
139 struct failed_rpc_request : public Base
140 {
141 explicit failed_rpc_request(std::string&& loc, const std::string& status)
142 : Base(std::move(loc), failed_rpc_request_messages[msg_index])
143 , m_status(status)
144 {
145 }
146
147 const std::string& status() const { return m_status; }
148
149 std::string to_string() const
150 {
151 std::ostringstream ss;
152 ss << Base::to_string() << ", status = " << status();
153 return ss.str();
154 }
155
156 private:
157 std::string m_status;
158 };
159 //----------------------------------------------------------------------------------------------------
162 //----------------------------------------------------------------------------------------------------
164 {
165 explicit wallet_internal_error(std::string&& loc, const std::string& message)
166 : wallet_runtime_error(std::move(loc), message)
167 {
168 }
169 };
170 //----------------------------------------------------------------------------------------------------
172 {
173 explicit unexpected_txin_type(std::string&& loc, const cryptonote::transaction& tx)
174 : wallet_internal_error(std::move(loc), "one of tx inputs has unexpected type")
175 , m_tx(tx)
176 {
177 }
178
179 const cryptonote::transaction& tx() const { return m_tx; }
180
181 std::string to_string() const
182 {
183 std::ostringstream ss;
186 return ss.str();
187 }
188
189 private:
191 };
192 //----------------------------------------------------------------------------------------------------
194 {
195 explicit unexpected_txout_type(std::string&& loc, const cryptonote::transaction& tx)
196 : wallet_internal_error(std::move(loc), "one of tx outputs has unexpected type")
197 , m_tx(tx)
198 {
199 }
200
201 const cryptonote::transaction& tx() const { return m_tx; }
202
203 std::string to_string() const
204 {
205 std::ostringstream ss;
208 return ss.str();
209 }
210
211 private:
213 };
214 //----------------------------------------------------------------------------------------------------
216 {
217 explicit wallet_not_initialized(std::string&& loc)
218 : wallet_internal_error(std::move(loc), "wallet is not initialized")
219 {
220 }
221 };
222 //----------------------------------------------------------------------------------------------------
224 {
225 explicit multisig_export_needed(std::string&& loc)
226 : wallet_runtime_error(std::move(loc), "This signature was made with stale data: export fresh multisig data, which other participants must then use")
227 {
228 }
229 };
230 //----------------------------------------------------------------------------------------------------
232 {
233 explicit multisig_import_needed(std::string&& loc)
234 : wallet_runtime_error(std::move(loc), "Not enough multisig data was found to sign: import multisig data from more other participants")
235 {
236 }
237 };
238 //----------------------------------------------------------------------------------------------------
240 {
241 explicit password_needed(std::string&& loc, const std::string &msg = "Password needed")
242 : wallet_runtime_error(std::move(loc), msg)
243 {
244 }
245 };
246 //----------------------------------------------------------------------------------------------------
248 {
249 explicit password_entry_failed(std::string&& loc, const std::string &msg = "Password entry failed")
250 : wallet_runtime_error(std::move(loc), msg)
251 {
252 }
253 };
254 //----------------------------------------------------------------------------------------------------
255 const char* const file_error_messages[] = {
256 "file already exists",
257 "file not found",
258 "failed to read file",
259 "failed to save file"
260 };
268
269 template<int msg_index>
271 {
272 explicit file_error_base(std::string&& loc, const std::string& file)
273 : wallet_logic_error(std::move(loc), std::string(file_error_messages[msg_index]) + " \"" + file + '\"')
274 , m_file(file)
275 {
276 }
277
278 explicit file_error_base(std::string&& loc, const std::string& file, const std::error_code &e)
279 : wallet_logic_error(std::move(loc), std::string(file_error_messages[msg_index]) + " \"" + file + "\": " + e.message())
280 , m_file(file)
281 {
282 }
283
284 const std::string& file() const { return m_file; }
285
286 std::string to_string() const { return wallet_logic_error::to_string(); }
287
288 private:
289 std::string m_file;
290 };
291 //----------------------------------------------------------------------------------------------------
296 //----------------------------------------------------------------------------------------------------
298 {
299 explicit invalid_password(std::string&& loc)
300 : wallet_logic_error(std::move(loc), "invalid password")
301 {
302 }
303
304 std::string to_string() const { return wallet_logic_error::to_string(); }
305 };
307 {
308 explicit invalid_priority(std::string&& loc)
309 : wallet_logic_error(std::move(loc), "invalid priority")
310 {
311 }
312
313 std::string to_string() const { return wallet_logic_error::to_string(); }
314 };
315
317 {
318 explicit invalid_multisig_seed(std::string&& loc)
319 : wallet_logic_error(std::move(loc), "invalid multisig seed")
320 {
321 }
322
323 std::string to_string() const { return wallet_logic_error::to_string(); }
324 };
325
326 //----------------------------------------------------------------------------------------------------
328 {
329 explicit invalid_pregenerated_random (std::string&& loc)
330 : wallet_logic_error(std::move(loc), "invalid pregenerated random for wallet creation/recovery")
331 {
332 }
333
334 std::string to_string() const { return wallet_logic_error::to_string(); }
335 };
336 //----------------------------------------------------------------------------------------------------
338 {
339 protected:
340 explicit refresh_error(std::string&& loc, const std::string& message)
341 : wallet_logic_error(std::move(loc), message)
342 {
343 }
344 };
345 //----------------------------------------------------------------------------------------------------
347 {
348 explicit index_outofbound(std::string&& loc, const std::string& message)
349 : wallet_logic_error(std::move(loc), message)
350 {
351 }
352 };
354 {
355 explicit account_index_outofbound(std::string&& loc)
356 : index_outofbound(std::move(loc), "account index is out of bound")
357 {
358 }
359 };
361 {
362 explicit address_index_outofbound(std::string&& loc)
363 : index_outofbound(std::move(loc), "address index is out of bound")
364 {
365 }
366 };
367 //----------------------------------------------------------------------------------------------------
369 {
370 explicit acc_outs_lookup_error(std::string&& loc, const cryptonote::transaction& tx,
372 : refresh_error(std::move(loc), "account outs lookup error")
373 , m_tx(tx)
374 , m_tx_pub_key(tx_pub_key)
375 , m_acc_keys(acc_keys)
376 {
377 }
378
379 const cryptonote::transaction& tx() const { return m_tx; }
380 const crypto::public_key& tx_pub_key() const { return m_tx_pub_key; }
381 const cryptonote::account_keys& acc_keys() const { return m_acc_keys; }
382
383 std::string to_string() const
384 {
385 std::ostringstream ss;
388 return ss.str();
389 }
390
391 private:
392 const cryptonote::transaction m_tx;
393 const crypto::public_key m_tx_pub_key;
394 const cryptonote::account_keys m_acc_keys;
395 };
396 //----------------------------------------------------------------------------------------------------
398 {
399 explicit block_parse_error(std::string&& loc, const cryptonote::blobdata& block_data)
400 : refresh_error(std::move(loc), "block parse error")
401 , m_block_blob(block_data)
402 {
403 }
404
405 const cryptonote::blobdata& block_blob() const { return m_block_blob; }
406
407 std::string to_string() const { return refresh_error::to_string(); }
408
409 private:
410 cryptonote::blobdata m_block_blob;
411 };
412 //----------------------------------------------------------------------------------------------------
414 //----------------------------------------------------------------------------------------------------
416 //----------------------------------------------------------------------------------------------------
418 //----------------------------------------------------------------------------------------------------
420 {
421 explicit tx_parse_error(std::string&& loc, const cryptonote::blobdata& tx_blob)
422 : refresh_error(std::move(loc), "transaction parse error")
423 , m_tx_blob(tx_blob)
424 {
425 }
426
427 const cryptonote::blobdata& tx_blob() const { return m_tx_blob; }
428
429 std::string to_string() const { return refresh_error::to_string(); }
430
431 private:
432 cryptonote::blobdata m_tx_blob;
433 };
434 //----------------------------------------------------------------------------------------------------
436 {
437 explicit get_tx_pool_error(std::string&& loc)
438 : refresh_error(std::move(loc), "error getting transaction pool")
439 {
440 }
441
442 std::string to_string() const { return refresh_error::to_string(); }
443 };
444 //----------------------------------------------------------------------------------------------------
446 {
447 explicit out_of_hashchain_bounds_error(std::string&& loc)
448 : refresh_error(std::move(loc), "Index out of bounds of of hashchain")
449 {
450 }
451
452 std::string to_string() const { return refresh_error::to_string(); }
453 };
454 //----------------------------------------------------------------------------------------------------
456 {
457 explicit signature_check_failed(std::string&& loc, const std::string& message)
458 : wallet_logic_error(std::move(loc), "Signature check failed " + message)
459 {
460 }
461 };
462 //----------------------------------------------------------------------------------------------------
464 {
465 protected:
466 explicit transfer_error(std::string&& loc, const std::string& message)
467 : wallet_logic_error(std::move(loc), message)
468 {
469 }
470 };
471 //----------------------------------------------------------------------------------------------------
473 //----------------------------------------------------------------------------------------------------
475 {
477 : transfer_error(std::move(loc), "not enough unlocked ETN")
478 , m_available(available)
479 , m_tx_amount(tx_amount)
480 {
481 }
482
483 uint64_t available() const { return m_available; }
484 uint64_t tx_amount() const { return m_tx_amount; }
485
486 std::string to_string() const
487 {
488 std::ostringstream ss;
490 ", available = " << cryptonote::print_etn(m_available) <<
491 ", tx_amount = " << cryptonote::print_etn(m_tx_amount);
492 return ss.str();
493 }
494
495 private:
496 uint64_t m_available;
497 uint64_t m_tx_amount;
498 };
499 //----------------------------------------------------------------------------------------------------
501 {
502 explicit not_enough_etn(std::string&& loc, uint64_t available, uint64_t tx_amount, uint64_t fee)
503 : transfer_error(std::move(loc), "not enough ETN")
504 , m_available(available)
505 , m_tx_amount(tx_amount)
506 {
507 }
508
509 uint64_t available() const { return m_available; }
510 uint64_t tx_amount() const { return m_tx_amount; }
511
512 std::string to_string() const
513 {
514 std::ostringstream ss;
516 ", available = " << cryptonote::print_etn(m_available) <<
517 ", tx_amount = " << cryptonote::print_etn(m_tx_amount);
518 return ss.str();
519 }
520
521 private:
522 uint64_t m_available;
523 uint64_t m_tx_amount;
524 };
525 //----------------------------------------------------------------------------------------------------
527 {
529 : transfer_error(std::move(loc), "tx not possible")
530 , m_available(available)
531 , m_tx_amount(tx_amount)
532 , m_fee(fee)
533 {
534 }
535
536 uint64_t available() const { return m_available; }
537 uint64_t tx_amount() const { return m_tx_amount; }
538 uint64_t fee() const { return m_fee; }
539
540 std::string to_string() const
541 {
542 std::ostringstream ss;
544 ", available = " << cryptonote::print_etn(m_available) <<
545 ", tx_amount = " << cryptonote::print_etn(m_tx_amount) <<
546 ", fee = " << cryptonote::print_etn(m_fee);
547 return ss.str();
548 }
549
550 private:
551 uint64_t m_available;
552 uint64_t m_tx_amount;
553 uint64_t m_fee;
554 };
555 //----------------------------------------------------------------------------------------------------
557 {
558 typedef std::unordered_map<uint64_t, uint64_t> scanty_outs_t;
559
560 explicit not_enough_outs_to_mix(std::string&& loc, const scanty_outs_t& scanty_outs, size_t mixin_count)
561 : transfer_error(std::move(loc), "not enough outputs to use")
562 , m_scanty_outs(scanty_outs)
563 , m_mixin_count(mixin_count)
564 {
565 }
566
567 const scanty_outs_t& scanty_outs() const { return m_scanty_outs; }
568 size_t mixin_count() const { return m_mixin_count; }
569
570 std::string to_string() const
571 {
572 std::ostringstream ss;
573 ss << transfer_error::to_string() << "scanty_outs:";
574 for (const auto& out: m_scanty_outs)
575 {
576 ss << '\n' << cryptonote::print_etn(out.first) << " - " << out.second;
577 }
578 return ss.str();
579 }
580
581 private:
582 scanty_outs_t m_scanty_outs;
583 size_t m_mixin_count;
584 };
585 //----------------------------------------------------------------------------------------------------
587 {
588 typedef std::vector<cryptonote::tx_source_entry> sources_t;
589 typedef std::vector<cryptonote::tx_destination_entry> destinations_t;
590
592 std::string && loc
593 , sources_t const & sources
597 )
598 : transfer_error(std::move(loc), "transaction was not constructed")
599 , m_sources(sources)
600 , m_destinations(destinations)
601 , m_unlock_time(unlock_time)
602 , m_nettype(nettype)
603 {
604 }
605
606 const sources_t& sources() const { return m_sources; }
607 const destinations_t& destinations() const { return m_destinations; }
608 uint64_t unlock_time() const { return m_unlock_time; }
609
610 std::string to_string() const
611 {
612 std::ostringstream ss;
614 ss << "\nSources:";
615 for (size_t i = 0; i < m_sources.size(); ++i)
616 {
617 const cryptonote::tx_source_entry& src = m_sources[i];
618 ss << "\n source " << i << ":";
619 ss << "\n amount: " << cryptonote::print_etn(src.amount);
620 // It's not good, if logs will contain such much data
621 //ss << "\n real_output: " << src.real_output;
622 //ss << "\n real_output_in_tx_index: " << src.real_output_in_tx_index;
623 //ss << "\n real_out_tx_key: " << epee::string_tools::pod_to_hex(src.real_out_tx_key);
624 //ss << "\n outputs:";
625 //for (size_t j = 0; j < src.outputs.size(); ++j)
626 //{
627 // const cryptonote::tx_source_entry::output_entry& out = src.outputs[j];
628 // ss << "\n " << j << ": " << out.first << ", " << epee::string_tools::pod_to_hex(out.second);
629 //}
630 }
631
632 ss << "\nDestinations:";
633 for (size_t i = 0; i < m_destinations.size(); ++i)
634 {
635 const cryptonote::tx_destination_entry& dst = m_destinations[i];
636 ss << "\n " << i << ": " << cryptonote::get_account_address_as_str(m_nettype, dst.is_subaddress, dst.addr) << " " <<
638 }
639
640 ss << "\nunlock_time: " << m_unlock_time;
641
642 return ss.str();
643 }
644
645 private:
646 sources_t m_sources;
647 destinations_t m_destinations;
648 uint64_t m_unlock_time;
649 cryptonote::network_type m_nettype;
650 };
651 //----------------------------------------------------------------------------------------------------
653 {
654 explicit tx_rejected(std::string&& loc, const cryptonote::transaction& tx, const std::string& status, const std::string& reason)
655 : transfer_error(std::move(loc), "transaction was rejected by daemon")
656 , m_tx(tx)
657 , m_status(status)
658 , m_reason(reason)
659 {
660 }
661
662 const cryptonote::transaction& tx() const { return m_tx; }
663 const std::string& status() const { return m_status; }
664 const std::string& reason() const { return m_reason; }
665
666 std::string to_string() const
667 {
668 std::ostringstream ss;
669 ss << transfer_error::to_string() << ", status = " << m_status << ", tx:\n";
672 if (!m_reason.empty())
673 {
674 ss << " (" << m_reason << ")";
675 }
676 return ss.str();
677 }
678
679 private:
681 std::string m_status;
682 std::string m_reason;
683 };
684 //----------------------------------------------------------------------------------------------------
686 {
688 std::string && loc
689 , const std::vector<cryptonote::tx_destination_entry>& destinations
690 , uint64_t fee
692 )
693 : transfer_error(std::move(loc), "transaction sum + fee exceeds " + cryptonote::print_etn(std::numeric_limits<uint64_t>::max()))
694 , m_destinations(destinations)
695 , m_fee(fee)
696 , m_nettype(nettype)
697 {
698 }
699
700 const std::vector<cryptonote::tx_destination_entry>& destinations() const { return m_destinations; }
701 uint64_t fee() const { return m_fee; }
702
703 std::string to_string() const
704 {
705 std::ostringstream ss;
707 ", fee = " << cryptonote::print_etn(m_fee) <<
708 ", destinations:";
709 for (const auto& dst : m_destinations)
710 {
711 ss << '\n' << cryptonote::print_etn(dst.amount) << " -> " << cryptonote::get_account_address_as_str(m_nettype, dst.is_subaddress, dst.addr);
712 }
713 return ss.str();
714 }
715
716 private:
717 std::vector<cryptonote::tx_destination_entry> m_destinations;
718 uint64_t m_fee;
719 cryptonote::network_type m_nettype;
720 };
721 //----------------------------------------------------------------------------------------------------
723 {
724 explicit tx_too_big(std::string&& loc, const cryptonote::transaction& tx, uint64_t tx_weight_limit)
725 : transfer_error(std::move(loc), "transaction is too big")
726 , m_tx(tx)
727 , m_tx_valid(true)
728 , m_tx_weight(cryptonote::get_transaction_weight(tx))
729 , m_tx_weight_limit(tx_weight_limit)
730 {
731 }
732
734 : transfer_error(std::move(loc), "transaction would be too big")
735 , m_tx_valid(false)
736 , m_tx_weight(tx_weight)
737 , m_tx_weight_limit(tx_weight_limit)
738 {
739 }
740
741 bool tx_valid() const { return m_tx_valid; }
742 const cryptonote::transaction& tx() const { return m_tx; }
743 uint64_t tx_weight() const { return m_tx_weight; }
744 uint64_t tx_weight_limit() const { return m_tx_weight_limit; }
745
746 std::string to_string() const
747 {
748 std::ostringstream ss;
750 ", tx_weight_limit = " << m_tx_weight_limit <<
751 ", tx weight = " << m_tx_weight;
752 if (m_tx_valid)
753 {
755 ss << ", tx:\n" << cryptonote::obj_to_json_str(tx);
756 }
757 return ss.str();
758 }
759
760 private:
762 bool m_tx_valid;
763 uint64_t m_tx_weight;
764 uint64_t m_tx_weight_limit;
765 };
766 //----------------------------------------------------------------------------------------------------
768 {
769 explicit zero_destination(std::string&& loc)
770 : transfer_error(std::move(loc), "destination amount is zero")
771 {
772 }
773 };
774 //----------------------------------------------------------------------------------------------------
776 {
777 const std::string& request() const { return m_request; }
778
779 std::string to_string() const
780 {
781 std::ostringstream ss;
782 ss << wallet_logic_error::to_string() << ", request = " << m_request;
783 return ss.str();
784 }
785
786 protected:
787 explicit wallet_rpc_error(std::string&& loc, const std::string& message, const std::string& request)
788 : wallet_logic_error(std::move(loc), message)
789 , m_request(request)
790 {
791 }
792
793 private:
794 std::string m_request;
795 };
796 //----------------------------------------------------------------------------------------------------
798 {
799 explicit wallet_generic_rpc_error(std::string&& loc, const std::string& request, const std::string& status)
800 : wallet_rpc_error(std::move(loc), std::string("error in ") + request + " RPC: " + status, request),
801 m_status(status)
802 {
803 }
804 const std::string& status() const { return m_status; }
805 private:
806 const std::string m_status;
807 };
808 //----------------------------------------------------------------------------------------------------
810 {
811 explicit daemon_busy(std::string&& loc, const std::string& request)
812 : wallet_rpc_error(std::move(loc), "daemon is busy", request)
813 {
814 }
815 };
816 //----------------------------------------------------------------------------------------------------
818 {
819 explicit no_connection_to_daemon(std::string&& loc, const std::string& request)
820 : wallet_rpc_error(std::move(loc), "no connection to daemon", request)
821 {
822 }
823 };
824 //----------------------------------------------------------------------------------------------------
826 {
827 explicit is_key_image_spent_error(std::string&& loc, const std::string& request)
828 : wallet_rpc_error(std::move(loc), "error from is_key_image_spent call", request)
829 {
830 }
831 };
832 //----------------------------------------------------------------------------------------------------
834 {
835 explicit is_public_output_spent_error(std::string&& loc, const std::string& request)
836 : wallet_rpc_error(std::move(loc), "error from is_public_output_spent call", request)
837 {
838 }
839 };
840 //----------------------------------------------------------------------------------------------------
842 {
843 explicit get_histogram_error(std::string&& loc, const std::string& request)
844 : wallet_rpc_error(std::move(loc), "failed to get output histogram", request)
845 {
846 }
847 };
848 //----------------------------------------------------------------------------------------------------
850 {
851 explicit get_output_distribution(std::string&& loc, const std::string& request)
852 : wallet_rpc_error(std::move(loc), "failed to get output distribution", request)
853 {
854 }
855 };
856 //----------------------------------------------------------------------------------------------------
858 {
859 explicit wallet_files_doesnt_correspond(std::string&& loc, const std::string& keys_file, const std::string& wallet_file)
860 : wallet_logic_error(std::move(loc), "file " + wallet_file + " does not correspond to " + keys_file)
861 {
862 }
863
864 const std::string& keys_file() const { return m_keys_file; }
865 const std::string& wallet_file() const { return m_wallet_file; }
866
867 std::string to_string() const { return wallet_logic_error::to_string(); }
868
869 private:
870 std::string m_keys_file;
871 std::string m_wallet_file;
872 };
873 //----------------------------------------------------------------------------------------------------
875 {
876 protected:
877 explicit mms_error(std::string&& loc, const std::string& message)
878 : wallet_logic_error(std::move(loc), message)
879 {
880 }
881 };
882 //----------------------------------------------------------------------------------------------------
884 {
885 explicit no_connection_to_bitmessage(std::string&& loc, const std::string& address)
886 : mms_error(std::move(loc), "no connection to PyBitmessage at address " + address)
887 {
888 }
889 };
890 //----------------------------------------------------------------------------------------------------
892 {
893 explicit bitmessage_api_error(std::string&& loc, const std::string& error_string)
894 : mms_error(std::move(loc), "PyBitmessage returned " + error_string)
895 {
896 }
897 };
898 //----------------------------------------------------------------------------------------------------
899
900#if !defined(_MSC_VER)
901
902 template<typename TException, typename... TArgs>
903 void throw_wallet_ex(std::string&& loc, const TArgs&... args)
904 {
905 TException e(std::move(loc), args...);
906 LOG_PRINT_L0(e.to_string());
907 throw e;
908 }
909
910#else
911 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
912 #include <boost/preprocessor/repetition/enum_params.hpp>
913 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
914
915 template<typename TException>
916 void throw_wallet_ex(std::string&& loc)
917 {
918 TException e(std::move(loc));
919 LOG_PRINT_L0(e.to_string());
920 throw e;
921 }
922
923#define GEN_throw_wallet_ex(z, n, data) \
924 template<typename TException, BOOST_PP_ENUM_PARAMS(n, typename TArg)> \
925 void throw_wallet_ex(std::string&& loc, BOOST_PP_ENUM_BINARY_PARAMS(n, const TArg, &arg)) \
926 { \
927 TException e(std::move(loc), BOOST_PP_ENUM_PARAMS(n, arg)); \
928 LOG_PRINT_L0(e.to_string()); \
929 throw e; \
930 }
931
932 BOOST_PP_REPEAT_FROM_TO(1, 6, GEN_throw_wallet_ex, ~)
933#endif
934 }
935}
936
937#define STRINGIZE_DETAIL(x) #x
938#define STRINGIZE(x) STRINGIZE_DETAIL(x)
939
940#define THROW_WALLET_EXCEPTION(err_type, ...) \
941 do { \
942 LOG_ERROR("THROW EXCEPTION: " << #err_type); \
943 tools::error::throw_wallet_ex<err_type>(std::string(__FILE__ ":" STRINGIZE(__LINE__)), ## __VA_ARGS__); \
944 } while(0)
945
946#define THROW_WALLET_EXCEPTION_IF(cond, err_type, ...) \
947 if (cond) \
948 { \
949 LOG_ERROR(#cond << ". THROW EXCEPTION: " << #err_type); \
950 tools::error::throw_wallet_ex<err_type>(std::string(__FILE__ ":" STRINGIZE(__LINE__)), ## __VA_ARGS__); \
951 }
std::string message("Message requiring signing")
#define LOG_PRINT_L0(x)
Definition misc_log_ex.h:99
POD_CLASS public_key
Definition crypto.h:79
Holds cryptonote related classes and helpers.
Definition ban.cpp:40
std::string obj_to_json_str(T &obj)
std::string get_account_address_as_str(network_type nettype, bool subaddress, account_public_address const &adr)
std::string blobdata
std::string print_etn(uint64_t amount, unsigned int decimal_point)
STL namespace.
@ file_save_error_message_index
@ file_read_error_message_index
@ file_not_found_message_index
const char *const file_error_messages[]
file_error_base< file_save_error_message_index > file_save_error
failed_rpc_request_message_indices
@ get_out_indices_error_message_index
@ get_blocks_error_message_index
@ get_hashes_error_message_index
@ get_outs_error_message_index
const char *const failed_rpc_request_messages[]
file_error_base< file_not_found_message_index > file_not_found
failed_rpc_request< refresh_error, get_hashes_error_message_index > get_hashes_error
void throw_wallet_ex(std::string &&loc, const TArgs &... args)
file_error_base< file_exists_message_index > file_exists
failed_rpc_request< refresh_error, get_blocks_error_message_index > get_blocks_error
failed_rpc_request< refresh_error, get_out_indices_error_message_index > get_out_indices_error
failed_rpc_request< transfer_error, get_outs_error_message_index > get_outs_error
file_error_base< file_read_error_message_index > file_read_error
wallet_error_base< std::logic_error > wallet_logic_error
wallet_error_base< std::runtime_error > wallet_runtime_error
Various Tools.
Definition tools.cpp:31
#define true
#define false
unsigned __int64 uint64_t
Definition stdint.h:136
bool is_subaddress
uint64_t amount
account_public_address addr
uint64_t amount
acc_outs_lookup_error(std::string &&loc, const cryptonote::transaction &tx, const crypto::public_key &tx_pub_key, const cryptonote::account_keys &acc_keys)
const crypto::public_key & tx_pub_key() const
const cryptonote::account_keys & acc_keys() const
const cryptonote::transaction & tx() const
bitmessage_api_error(std::string &&loc, const std::string &error_string)
block_parse_error(std::string &&loc, const cryptonote::blobdata &block_data)
const cryptonote::blobdata & block_blob() const
daemon_busy(std::string &&loc, const std::string &request)
failed_rpc_request(std::string &&loc, const std::string &status)
file_error_base(std::string &&loc, const std::string &file)
std::string to_string() const
get_histogram_error(std::string &&loc, const std::string &request)
get_output_distribution(std::string &&loc, const std::string &request)
get_tx_pool_error(std::string &&loc)
index_outofbound(std::string &&loc, const std::string &message)
invalid_password(std::string &&loc)
std::string to_string() const
invalid_priority(std::string &&loc)
std::string to_string() const
is_key_image_spent_error(std::string &&loc, const std::string &request)
is_public_output_spent_error(std::string &&loc, const std::string &request)
mms_error(std::string &&loc, const std::string &message)
no_connection_to_bitmessage(std::string &&loc, const std::string &address)
no_connection_to_daemon(std::string &&loc, const std::string &request)
std::string to_string() const
not_enough_etn(std::string &&loc, uint64_t available, uint64_t tx_amount, uint64_t fee)
not_enough_outs_to_mix(std::string &&loc, const scanty_outs_t &scanty_outs, size_t mixin_count)
const scanty_outs_t & scanty_outs() const
std::unordered_map< uint64_t, uint64_t > scanty_outs_t
not_enough_unlocked_etn(std::string &&loc, uint64_t available, uint64_t tx_amount, uint64_t fee)
password_entry_failed(std::string &&loc, const std::string &msg="Password entry failed")
password_needed(std::string &&loc, const std::string &msg="Password needed")
refresh_error(std::string &&loc, const std::string &message)
signature_check_failed(std::string &&loc, const std::string &message)
transfer_error(std::string &&loc, const std::string &message)
std::vector< cryptonote::tx_source_entry > sources_t
tx_not_constructed(std::string &&loc, sources_t const &sources, destinations_t const &destinations, uint64_t unlock_time, cryptonote::network_type nettype)
std::vector< cryptonote::tx_destination_entry > destinations_t
const sources_t & sources() const
const destinations_t & destinations() const
std::string to_string() const
tx_not_possible(std::string &&loc, uint64_t available, uint64_t tx_amount, uint64_t fee)
const cryptonote::blobdata & tx_blob() const
tx_parse_error(std::string &&loc, const cryptonote::blobdata &tx_blob)
std::string to_string() const
const cryptonote::transaction & tx() const
const std::string & reason() const
std::string to_string() const
tx_rejected(std::string &&loc, const cryptonote::transaction &tx, const std::string &status, const std::string &reason)
const std::string & status() const
const std::vector< cryptonote::tx_destination_entry > & destinations() const
tx_sum_overflow(std::string &&loc, const std::vector< cryptonote::tx_destination_entry > &destinations, uint64_t fee, cryptonote::network_type nettype)
std::string to_string() const
std::string to_string() const
tx_too_big(std::string &&loc, uint64_t tx_weight, uint64_t tx_weight_limit)
uint64_t tx_weight() const
tx_too_big(std::string &&loc, const cryptonote::transaction &tx, uint64_t tx_weight_limit)
const cryptonote::transaction & tx() const
uint64_t tx_weight_limit() const
unexpected_txin_type(std::string &&loc, const cryptonote::transaction &tx)
const cryptonote::transaction & tx() const
const cryptonote::transaction & tx() const
unexpected_txout_type(std::string &&loc, const cryptonote::transaction &tx)
wallet_error_base(std::string &&loc, const std::string &message)
const std::string & location() const
wallet_files_doesnt_correspond(std::string &&loc, const std::string &keys_file, const std::string &wallet_file)
const std::string & status() const
wallet_generic_rpc_error(std::string &&loc, const std::string &request, const std::string &status)
wallet_internal_error(std::string &&loc, const std::string &message)
const std::string & request() const
std::string to_string() const
wallet_rpc_error(std::string &&loc, const std::string &message, const std::string &request)
zero_destination(std::string &&loc)
const char * address
Definition multisig.cpp:37