Electroneum
wallet_errors.h
Go to the documentation of this file.
1 // Copyrights(c) 2017-2020, 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 
45 namespace 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  // wallet_not_initialized
55  // multisig_export_needed
56  // multisig_import_needed
57  // password_needed
58  // std::logic_error
59  // wallet_logic_error *
60  // file_exists
61  // file_not_found
62  // file_read_error
63  // file_save_error
64  // invalid_password
65  // invalid_priority
66  // invalid_multisig_seed
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_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  // wallet_files_doesnt_correspond
95  //
96  // * - class with protected ctor
97 
98  //----------------------------------------------------------------------------------------------------
99  template<typename Base>
100  struct wallet_error_base : public Base
101  {
102  const std::string& location() const { return m_loc; }
103 
104  std::string to_string() const
105  {
106  std::ostringstream ss;
107  ss << m_loc << ':' << typeid(*this).name() << ": " << Base::what();
108  return ss.str();
109  }
110 
111  protected:
112  wallet_error_base(std::string&& loc, const std::string& message)
113  : Base(message)
114  , m_loc(loc)
115  {
116  }
117 
118  private:
119  std::string m_loc;
120  };
121  //----------------------------------------------------------------------------------------------------
122  const char* const failed_rpc_request_messages[] = {
123  "failed to get blocks",
124  "failed to get hashes",
125  "failed to get out indices",
126  "failed to get random outs"
127  };
129  {
134  };
135 
136  template<typename Base, int msg_index>
137  struct failed_rpc_request : public Base
138  {
139  explicit failed_rpc_request(std::string&& loc, const std::string& status)
140  : Base(std::move(loc), failed_rpc_request_messages[msg_index])
141  , m_status(status)
142  {
143  }
144 
145  const std::string& status() const { return m_status; }
146 
147  std::string to_string() const
148  {
149  std::ostringstream ss;
150  ss << Base::to_string() << ", status = " << status();
151  return ss.str();
152  }
153 
154  private:
155  std::string m_status;
156  };
157  //----------------------------------------------------------------------------------------------------
160  //----------------------------------------------------------------------------------------------------
162  {
163  explicit wallet_internal_error(std::string&& loc, const std::string& message)
164  : wallet_runtime_error(std::move(loc), message)
165  {
166  }
167  };
168  //----------------------------------------------------------------------------------------------------
170  {
171  explicit unexpected_txin_type(std::string&& loc, const cryptonote::transaction& tx)
172  : wallet_internal_error(std::move(loc), "one of tx inputs has unexpected type")
173  , m_tx(tx)
174  {
175  }
176 
177  const cryptonote::transaction& tx() const { return m_tx; }
178 
179  std::string to_string() const
180  {
181  std::ostringstream ss;
184  return ss.str();
185  }
186 
187  private:
189  };
190  //----------------------------------------------------------------------------------------------------
192  {
193  explicit wallet_not_initialized(std::string&& loc)
194  : wallet_internal_error(std::move(loc), "wallet is not initialized")
195  {
196  }
197  };
198  //----------------------------------------------------------------------------------------------------
200  {
201  explicit multisig_export_needed(std::string&& loc)
202  : wallet_runtime_error(std::move(loc), "This signature was made with stale data: export fresh multisig data, which other participants must then use")
203  {
204  }
205  };
206  //----------------------------------------------------------------------------------------------------
208  {
209  explicit multisig_import_needed(std::string&& loc)
210  : wallet_runtime_error(std::move(loc), "Not enough multisig data was found to sign: import multisig data from more other participants")
211  {
212  }
213  };
214  //----------------------------------------------------------------------------------------------------
216  {
217  explicit password_needed(std::string&& loc, const std::string &msg = "Password needed")
218  : wallet_runtime_error(std::move(loc), msg)
219  {
220  }
221  };
222  //----------------------------------------------------------------------------------------------------
224  {
225  explicit password_entry_failed(std::string&& loc, const std::string &msg = "Password entry failed")
226  : wallet_runtime_error(std::move(loc), msg)
227  {
228  }
229  };
230  //----------------------------------------------------------------------------------------------------
231  const char* const file_error_messages[] = {
232  "file already exists",
233  "file not found",
234  "failed to read file",
235  "failed to save file"
236  };
238  {
243  };
244 
245  template<int msg_index>
247  {
248  explicit file_error_base(std::string&& loc, const std::string& file)
249  : wallet_logic_error(std::move(loc), std::string(file_error_messages[msg_index]) + " \"" + file + '\"')
250  , m_file(file)
251  {
252  }
253 
254  explicit file_error_base(std::string&& loc, const std::string& file, const std::error_code &e)
255  : wallet_logic_error(std::move(loc), std::string(file_error_messages[msg_index]) + " \"" + file + "\": " + e.message())
256  , m_file(file)
257  {
258  }
259 
260  const std::string& file() const { return m_file; }
261 
262  std::string to_string() const { return wallet_logic_error::to_string(); }
263 
264  private:
265  std::string m_file;
266  };
267  //----------------------------------------------------------------------------------------------------
272  //----------------------------------------------------------------------------------------------------
274  {
275  explicit invalid_password(std::string&& loc)
276  : wallet_logic_error(std::move(loc), "invalid password")
277  {
278  }
279 
280  std::string to_string() const { return wallet_logic_error::to_string(); }
281  };
283  {
284  explicit invalid_priority(std::string&& loc)
285  : wallet_logic_error(std::move(loc), "invalid priority")
286  {
287  }
288 
289  std::string to_string() const { return wallet_logic_error::to_string(); }
290  };
291 
293  {
294  explicit invalid_multisig_seed(std::string&& loc)
295  : wallet_logic_error(std::move(loc), "invalid multisig seed")
296  {
297  }
298 
299  std::string to_string() const { return wallet_logic_error::to_string(); }
300  };
301 
302  //----------------------------------------------------------------------------------------------------
304  {
305  explicit invalid_pregenerated_random (std::string&& loc)
306  : wallet_logic_error(std::move(loc), "invalid pregenerated random for wallet creation/recovery")
307  {
308  }
309 
310  std::string to_string() const { return wallet_logic_error::to_string(); }
311  };
312  //----------------------------------------------------------------------------------------------------
314  {
315  protected:
316  explicit refresh_error(std::string&& loc, const std::string& message)
317  : wallet_logic_error(std::move(loc), message)
318  {
319  }
320  };
321  //----------------------------------------------------------------------------------------------------
323  {
324  explicit index_outofbound(std::string&& loc, const std::string& message)
325  : wallet_logic_error(std::move(loc), message)
326  {
327  }
328  };
330  {
331  explicit account_index_outofbound(std::string&& loc)
332  : index_outofbound(std::move(loc), "account index is out of bound")
333  {
334  }
335  };
337  {
338  explicit address_index_outofbound(std::string&& loc)
339  : index_outofbound(std::move(loc), "address index is out of bound")
340  {
341  }
342  };
343  //----------------------------------------------------------------------------------------------------
345  {
346  explicit acc_outs_lookup_error(std::string&& loc, const cryptonote::transaction& tx,
348  : refresh_error(std::move(loc), "account outs lookup error")
349  , m_tx(tx)
352  {
353  }
354 
355  const cryptonote::transaction& tx() const { return m_tx; }
356  const crypto::public_key& tx_pub_key() const { return m_tx_pub_key; }
357  const cryptonote::account_keys& acc_keys() const { return m_acc_keys; }
358 
359  std::string to_string() const
360  {
361  std::ostringstream ss;
364  return ss.str();
365  }
366 
367  private:
371  };
372  //----------------------------------------------------------------------------------------------------
374  {
375  explicit block_parse_error(std::string&& loc, const cryptonote::blobdata& block_data)
376  : refresh_error(std::move(loc), "block parse error")
377  , m_block_blob(block_data)
378  {
379  }
380 
381  const cryptonote::blobdata& block_blob() const { return m_block_blob; }
382 
383  std::string to_string() const { return refresh_error::to_string(); }
384 
385  private:
387  };
388  //----------------------------------------------------------------------------------------------------
390  //----------------------------------------------------------------------------------------------------
392  //----------------------------------------------------------------------------------------------------
394  //----------------------------------------------------------------------------------------------------
396  {
397  explicit tx_parse_error(std::string&& loc, const cryptonote::blobdata& tx_blob)
398  : refresh_error(std::move(loc), "transaction parse error")
399  , m_tx_blob(tx_blob)
400  {
401  }
402 
403  const cryptonote::blobdata& tx_blob() const { return m_tx_blob; }
404 
405  std::string to_string() const { return refresh_error::to_string(); }
406 
407  private:
409  };
410  //----------------------------------------------------------------------------------------------------
412  {
413  explicit get_tx_pool_error(std::string&& loc)
414  : refresh_error(std::move(loc), "error getting transaction pool")
415  {
416  }
417 
418  std::string to_string() const { return refresh_error::to_string(); }
419  };
420  //----------------------------------------------------------------------------------------------------
422  {
423  explicit out_of_hashchain_bounds_error(std::string&& loc)
424  : refresh_error(std::move(loc), "Index out of bounds of of hashchain")
425  {
426  }
427 
428  std::string to_string() const { return refresh_error::to_string(); }
429  };
430  //----------------------------------------------------------------------------------------------------
432  {
433  explicit signature_check_failed(std::string&& loc, const std::string& message)
434  : wallet_logic_error(std::move(loc), "Signature check failed " + message)
435  {
436  }
437  };
438  //----------------------------------------------------------------------------------------------------
440  {
441  protected:
442  explicit transfer_error(std::string&& loc, const std::string& message)
443  : wallet_logic_error(std::move(loc), message)
444  {
445  }
446  };
447  //----------------------------------------------------------------------------------------------------
449  //----------------------------------------------------------------------------------------------------
451  {
452  explicit not_enough_unlocked_money(std::string&& loc, uint64_t available, uint64_t tx_amount, uint64_t fee)
453  : transfer_error(std::move(loc), "not enough unlocked money")
456  {
457  }
458 
459  uint64_t available() const { return m_available; }
460  uint64_t tx_amount() const { return m_tx_amount; }
461 
462  std::string to_string() const
463  {
464  std::ostringstream ss;
465  ss << transfer_error::to_string() <<
466  ", available = " << cryptonote::print_money(m_available) <<
467  ", tx_amount = " << cryptonote::print_money(m_tx_amount);
468  return ss.str();
469  }
470 
471  private:
472  uint64_t m_available;
473  uint64_t m_tx_amount;
474  };
475  //----------------------------------------------------------------------------------------------------
477  {
478  explicit not_enough_money(std::string&& loc, uint64_t available, uint64_t tx_amount, uint64_t fee)
479  : transfer_error(std::move(loc), "not enough money")
482  {
483  }
484 
485  uint64_t available() const { return m_available; }
486  uint64_t tx_amount() const { return m_tx_amount; }
487 
488  std::string to_string() const
489  {
490  std::ostringstream ss;
491  ss << transfer_error::to_string() <<
492  ", available = " << cryptonote::print_money(m_available) <<
493  ", tx_amount = " << cryptonote::print_money(m_tx_amount);
494  return ss.str();
495  }
496 
497  private:
498  uint64_t m_available;
499  uint64_t m_tx_amount;
500  };
501  //----------------------------------------------------------------------------------------------------
503  {
504  explicit tx_not_possible(std::string&& loc, uint64_t available, uint64_t tx_amount, uint64_t fee)
505  : transfer_error(std::move(loc), "tx not possible")
508  , m_fee(fee)
509  {
510  }
511 
512  uint64_t available() const { return m_available; }
513  uint64_t tx_amount() const { return m_tx_amount; }
514  uint64_t fee() const { return m_fee; }
515 
516  std::string to_string() const
517  {
518  std::ostringstream ss;
519  ss << transfer_error::to_string() <<
520  ", available = " << cryptonote::print_money(m_available) <<
521  ", tx_amount = " << cryptonote::print_money(m_tx_amount) <<
522  ", fee = " << cryptonote::print_money(m_fee);
523  return ss.str();
524  }
525 
526  private:
527  uint64_t m_available;
528  uint64_t m_tx_amount;
529  uint64_t m_fee;
530  };
531  //----------------------------------------------------------------------------------------------------
533  {
534  typedef std::unordered_map<uint64_t, uint64_t> scanty_outs_t;
535 
536  explicit not_enough_outs_to_mix(std::string&& loc, const scanty_outs_t& scanty_outs, size_t mixin_count)
537  : transfer_error(std::move(loc), "not enough outputs to use")
540  {
541  }
542 
543  const scanty_outs_t& scanty_outs() const { return m_scanty_outs; }
544  size_t mixin_count() const { return m_mixin_count; }
545 
546  std::string to_string() const
547  {
548  std::ostringstream ss;
549  ss << transfer_error::to_string() << "scanty_outs:";
550  for (const auto& out: m_scanty_outs)
551  {
552  ss << '\n' << cryptonote::print_money(out.first) << " - " << out.second;
553  }
554  return ss.str();
555  }
556 
557  private:
560  };
561  //----------------------------------------------------------------------------------------------------
563  {
564  typedef std::vector<cryptonote::tx_source_entry> sources_t;
565  typedef std::vector<cryptonote::tx_destination_entry> destinations_t;
566 
568  std::string && loc
569  , sources_t const & sources
570  , destinations_t const & destinations
571  , uint64_t unlock_time
572  , cryptonote::network_type nettype
573  )
574  : transfer_error(std::move(loc), "transaction was not constructed")
575  , m_sources(sources)
578  , m_nettype(nettype)
579  {
580  }
581 
582  const sources_t& sources() const { return m_sources; }
583  const destinations_t& destinations() const { return m_destinations; }
584  uint64_t unlock_time() const { return m_unlock_time; }
585 
586  std::string to_string() const
587  {
588  std::ostringstream ss;
590  ss << "\nSources:";
591  for (size_t i = 0; i < m_sources.size(); ++i)
592  {
593  const cryptonote::tx_source_entry& src = m_sources[i];
594  ss << "\n source " << i << ":";
595  ss << "\n amount: " << cryptonote::print_money(src.amount);
596  // It's not good, if logs will contain such much data
597  //ss << "\n real_output: " << src.real_output;
598  //ss << "\n real_output_in_tx_index: " << src.real_output_in_tx_index;
599  //ss << "\n real_out_tx_key: " << epee::string_tools::pod_to_hex(src.real_out_tx_key);
600  //ss << "\n outputs:";
601  //for (size_t j = 0; j < src.outputs.size(); ++j)
602  //{
603  // const cryptonote::tx_source_entry::output_entry& out = src.outputs[j];
604  // ss << "\n " << j << ": " << out.first << ", " << epee::string_tools::pod_to_hex(out.second);
605  //}
606  }
607 
608  ss << "\nDestinations:";
609  for (size_t i = 0; i < m_destinations.size(); ++i)
610  {
612  ss << "\n " << i << ": " << cryptonote::get_account_address_as_str(m_nettype, dst.is_subaddress, dst.addr) << " " <<
614  }
615 
616  ss << "\nunlock_time: " << m_unlock_time;
617 
618  return ss.str();
619  }
620 
621  private:
624  uint64_t m_unlock_time;
626  };
627  //----------------------------------------------------------------------------------------------------
628  struct tx_rejected : public transfer_error
629  {
630  explicit tx_rejected(std::string&& loc, const cryptonote::transaction& tx, const std::string& status, const std::string& reason)
631  : transfer_error(std::move(loc), "transaction was rejected by daemon")
632  , m_tx(tx)
633  , m_status(status)
634  , m_reason(reason)
635  {
636  }
637 
638  const cryptonote::transaction& tx() const { return m_tx; }
639  const std::string& status() const { return m_status; }
640  const std::string& reason() const { return m_reason; }
641 
642  std::string to_string() const
643  {
644  std::ostringstream ss;
645  ss << transfer_error::to_string() << ", status = " << m_status << ", tx:\n";
648  if (!m_reason.empty())
649  {
650  ss << " (" << m_reason << ")";
651  }
652  return ss.str();
653  }
654 
655  private:
657  std::string m_status;
658  std::string m_reason;
659  };
660  //----------------------------------------------------------------------------------------------------
662  {
663  explicit tx_sum_overflow(
664  std::string && loc
665  , const std::vector<cryptonote::tx_destination_entry>& destinations
666  , uint64_t fee
667  , cryptonote::network_type nettype
668  )
669  : transfer_error(std::move(loc), "transaction sum + fee exceeds " + cryptonote::print_money(std::numeric_limits<uint64_t>::max()))
671  , m_fee(fee)
672  , m_nettype(nettype)
673  {
674  }
675 
676  const std::vector<cryptonote::tx_destination_entry>& destinations() const { return m_destinations; }
677  uint64_t fee() const { return m_fee; }
678 
679  std::string to_string() const
680  {
681  std::ostringstream ss;
682  ss << transfer_error::to_string() <<
683  ", fee = " << cryptonote::print_money(m_fee) <<
684  ", destinations:";
685  for (const auto& dst : m_destinations)
686  {
687  ss << '\n' << cryptonote::print_money(dst.amount) << " -> " << cryptonote::get_account_address_as_str(m_nettype, dst.is_subaddress, dst.addr);
688  }
689  return ss.str();
690  }
691 
692  private:
693  std::vector<cryptonote::tx_destination_entry> m_destinations;
694  uint64_t m_fee;
696  };
697  //----------------------------------------------------------------------------------------------------
698  struct tx_too_big : public transfer_error
699  {
700  explicit tx_too_big(std::string&& loc, const cryptonote::transaction& tx, uint64_t tx_weight_limit)
701  : transfer_error(std::move(loc), "transaction is too big")
702  , m_tx(tx)
703  , m_tx_valid(true)
706  {
707  }
708 
709  explicit tx_too_big(std::string&& loc, uint64_t tx_weight, uint64_t tx_weight_limit)
710  : transfer_error(std::move(loc), "transaction would be too big")
711  , m_tx_valid(false)
714  {
715  }
716 
717  bool tx_valid() const { return m_tx_valid; }
718  const cryptonote::transaction& tx() const { return m_tx; }
719  uint64_t tx_weight() const { return m_tx_weight; }
720  uint64_t tx_weight_limit() const { return m_tx_weight_limit; }
721 
722  std::string to_string() const
723  {
724  std::ostringstream ss;
725  ss << transfer_error::to_string() <<
726  ", tx_weight_limit = " << m_tx_weight_limit <<
727  ", tx weight = " << m_tx_weight;
728  if (m_tx_valid)
729  {
731  ss << ", tx:\n" << cryptonote::obj_to_json_str(tx);
732  }
733  return ss.str();
734  }
735 
736  private:
739  uint64_t m_tx_weight;
741  };
742  //----------------------------------------------------------------------------------------------------
744  {
745  explicit zero_destination(std::string&& loc)
746  : transfer_error(std::move(loc), "destination amount is zero")
747  {
748  }
749  };
750  //----------------------------------------------------------------------------------------------------
752  {
753  const std::string& request() const { return m_request; }
754 
755  std::string to_string() const
756  {
757  std::ostringstream ss;
758  ss << wallet_logic_error::to_string() << ", request = " << m_request;
759  return ss.str();
760  }
761 
762  protected:
763  explicit wallet_rpc_error(std::string&& loc, const std::string& message, const std::string& request)
764  : wallet_logic_error(std::move(loc), message)
765  , m_request(request)
766  {
767  }
768 
769  private:
770  std::string m_request;
771  };
772  //----------------------------------------------------------------------------------------------------
774  {
775  explicit wallet_generic_rpc_error(std::string&& loc, const std::string& request, const std::string& status)
776  : wallet_rpc_error(std::move(loc), std::string("error in ") + request + " RPC: " + status, request),
778  {
779  }
780  const std::string& status() const { return m_status; }
781  private:
782  const std::string m_status;
783  };
784  //----------------------------------------------------------------------------------------------------
786  {
787  explicit daemon_busy(std::string&& loc, const std::string& request)
788  : wallet_rpc_error(std::move(loc), "daemon is busy", request)
789  {
790  }
791  };
792  //----------------------------------------------------------------------------------------------------
794  {
795  explicit no_connection_to_daemon(std::string&& loc, const std::string& request)
796  : wallet_rpc_error(std::move(loc), "no connection to daemon", request)
797  {
798  }
799  };
800  //----------------------------------------------------------------------------------------------------
802  {
803  explicit is_key_image_spent_error(std::string&& loc, const std::string& request)
804  : wallet_rpc_error(std::move(loc), "error from is_key_image_spent call", request)
805  {
806  }
807  };
808  //----------------------------------------------------------------------------------------------------
810  {
811  explicit get_histogram_error(std::string&& loc, const std::string& request)
812  : wallet_rpc_error(std::move(loc), "failed to get output histogram", request)
813  {
814  }
815  };
816  //----------------------------------------------------------------------------------------------------
818  {
819  explicit get_output_distribution(std::string&& loc, const std::string& request)
820  : wallet_rpc_error(std::move(loc), "failed to get output distribution", request)
821  {
822  }
823  };
824  //----------------------------------------------------------------------------------------------------
826  {
827  explicit wallet_files_doesnt_correspond(std::string&& loc, const std::string& keys_file, const std::string& wallet_file)
828  : wallet_logic_error(std::move(loc), "file " + wallet_file + " does not correspond to " + keys_file)
829  {
830  }
831 
832  const std::string& keys_file() const { return m_keys_file; }
833  const std::string& wallet_file() const { return m_wallet_file; }
834 
835  std::string to_string() const { return wallet_logic_error::to_string(); }
836 
837  private:
838  std::string m_keys_file;
839  std::string m_wallet_file;
840  };
841  //----------------------------------------------------------------------------------------------------
843  {
844  protected:
845  explicit mms_error(std::string&& loc, const std::string& message)
846  : wallet_logic_error(std::move(loc), message)
847  {
848  }
849  };
850  //----------------------------------------------------------------------------------------------------
852  {
853  explicit no_connection_to_bitmessage(std::string&& loc, const std::string& address)
854  : mms_error(std::move(loc), "no connection to PyBitmessage at address " + address)
855  {
856  }
857  };
858  //----------------------------------------------------------------------------------------------------
860  {
861  explicit bitmessage_api_error(std::string&& loc, const std::string& error_string)
862  : mms_error(std::move(loc), "PyBitmessage returned " + error_string)
863  {
864  }
865  };
866  //----------------------------------------------------------------------------------------------------
867 
868 #if !defined(_MSC_VER)
869 
870  template<typename TException, typename... TArgs>
871  void throw_wallet_ex(std::string&& loc, const TArgs&... args)
872  {
873  TException e(std::move(loc), args...);
874  LOG_PRINT_L0(e.to_string());
875  throw e;
876  }
877 
878 #else
879  #include <boost/preprocessor/repetition/enum_binary_params.hpp>
880  #include <boost/preprocessor/repetition/enum_params.hpp>
881  #include <boost/preprocessor/repetition/repeat_from_to.hpp>
882 
883  template<typename TException>
884  void throw_wallet_ex(std::string&& loc)
885  {
886  TException e(std::move(loc));
887  LOG_PRINT_L0(e.to_string());
888  throw e;
889  }
890 
891 #define GEN_throw_wallet_ex(z, n, data) \
892  template<typename TException, BOOST_PP_ENUM_PARAMS(n, typename TArg)> \
893  void throw_wallet_ex(std::string&& loc, BOOST_PP_ENUM_BINARY_PARAMS(n, const TArg, &arg)) \
894  { \
895  TException e(std::move(loc), BOOST_PP_ENUM_PARAMS(n, arg)); \
896  LOG_PRINT_L0(e.to_string()); \
897  throw e; \
898  }
899 
900  BOOST_PP_REPEAT_FROM_TO(1, 6, GEN_throw_wallet_ex, ~)
901 #endif
902  }
903 }
904 
905 #define STRINGIZE_DETAIL(x) #x
906 #define STRINGIZE(x) STRINGIZE_DETAIL(x)
907 
908 #define THROW_WALLET_EXCEPTION(err_type, ...) \
909  do { \
910  LOG_ERROR("THROW EXCEPTION: " << #err_type); \
911  tools::error::throw_wallet_ex<err_type>(std::string(__FILE__ ":" STRINGIZE(__LINE__)), ## __VA_ARGS__); \
912  } while(0)
913 
914 #define THROW_WALLET_EXCEPTION_IF(cond, err_type, ...) \
915  if (cond) \
916  { \
917  LOG_ERROR(#cond << ". THROW EXCEPTION: " << #err_type); \
918  tools::error::throw_wallet_ex<err_type>(std::string(__FILE__ ":" STRINGIZE(__LINE__)), ## __VA_ARGS__); \
919  }
Definition: cryptonote_basic.h:205
args
Definition: build_protob.py:10
POD_CLASS public_key
Definition: crypto.h:76
Holds cryptonote related classes and helpers.
Definition: db_bdb.cpp:226
std::string obj_to_json_str(T &obj)
Definition: cryptonote_format_utils.h:197
network_type
Definition: cryptonote_config.h:243
std::string print_money(uint64_t amount, unsigned int decimal_point)
Definition: cryptonote_format_utils.cpp:940
std::string get_account_address_as_str(network_type nettype, bool subaddress, account_public_address const &adr)
Definition: cryptonote_basic_impl.cpp:203
std::string blobdata
Definition: blobdatatype.h:39
uint64_t get_transaction_weight(const transaction &tx, size_t blob_size)
Definition: cryptonote_format_utils.cpp:392
error
Tracks LMDB error codes.
Definition: error.h:45
Definition: blockchain_ancestry.cpp:73
file_error_message_indices
Definition: wallet_errors.h:238
@ file_save_error_message_index
Definition: wallet_errors.h:242
@ file_read_error_message_index
Definition: wallet_errors.h:241
@ file_not_found_message_index
Definition: wallet_errors.h:240
@ file_exists_message_index
Definition: wallet_errors.h:239
const char *const file_error_messages[]
Definition: wallet_errors.h:231
file_error_base< file_save_error_message_index > file_save_error
Definition: wallet_errors.h:271
failed_rpc_request_message_indices
Definition: wallet_errors.h:129
@ get_out_indices_error_message_index
Definition: wallet_errors.h:132
@ get_blocks_error_message_index
Definition: wallet_errors.h:130
@ get_hashes_error_message_index
Definition: wallet_errors.h:131
@ get_outs_error_message_index
Definition: wallet_errors.h:133
const char *const failed_rpc_request_messages[]
Definition: wallet_errors.h:122
file_error_base< file_not_found_message_index > file_not_found
Definition: wallet_errors.h:269
failed_rpc_request< refresh_error, get_hashes_error_message_index > get_hashes_error
Definition: wallet_errors.h:391
void throw_wallet_ex(std::string &&loc, const TArgs &... args)
Definition: wallet_errors.h:871
file_error_base< file_exists_message_index > file_exists
Definition: wallet_errors.h:268
failed_rpc_request< refresh_error, get_blocks_error_message_index > get_blocks_error
Definition: wallet_errors.h:389
failed_rpc_request< refresh_error, get_out_indices_error_message_index > get_out_indices_error
Definition: wallet_errors.h:393
failed_rpc_request< transfer_error, get_outs_error_message_index > get_outs_error
Definition: wallet_errors.h:448
file_error_base< file_read_error_message_index > file_read_error
Definition: wallet_errors.h:270
wallet_error_base< std::logic_error > wallet_logic_error
Definition: wallet_errors.h:158
wallet_error_base< std::runtime_error > wallet_runtime_error
Definition: wallet_errors.h:159
Various Tools.
Definition: apply_permutation.h:40
#define true
Definition: stdbool.h:37
#define false
Definition: stdbool.h:38
Definition: account.h:42
Definition: cryptonote_tx_utils.h:76
bool is_subaddress
Definition: cryptonote_tx_utils.h:80
uint64_t amount
Definition: cryptonote_tx_utils.h:78
account_public_address addr
Definition: cryptonote_tx_utils.h:79
Definition: cryptonote_tx_utils.h:44
uint64_t amount
Definition: cryptonote_tx_utils.h:52
Definition: wallet_errors.h:345
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:346
const crypto::public_key m_tx_pub_key
Definition: wallet_errors.h:369
std::string to_string() const
Definition: wallet_errors.h:359
const cryptonote::account_keys m_acc_keys
Definition: wallet_errors.h:370
const cryptonote::account_keys & acc_keys() const
Definition: wallet_errors.h:357
const crypto::public_key & tx_pub_key() const
Definition: wallet_errors.h:356
const cryptonote::transaction m_tx
Definition: wallet_errors.h:368
const cryptonote::transaction & tx() const
Definition: wallet_errors.h:355
Definition: wallet_errors.h:330
account_index_outofbound(std::string &&loc)
Definition: wallet_errors.h:331
Definition: wallet_errors.h:337
address_index_outofbound(std::string &&loc)
Definition: wallet_errors.h:338
Definition: wallet_errors.h:860
bitmessage_api_error(std::string &&loc, const std::string &error_string)
Definition: wallet_errors.h:861
Definition: wallet_errors.h:374
block_parse_error(std::string &&loc, const cryptonote::blobdata &block_data)
Definition: wallet_errors.h:375
const cryptonote::blobdata & block_blob() const
Definition: wallet_errors.h:381
std::string to_string() const
Definition: wallet_errors.h:383
cryptonote::blobdata m_block_blob
Definition: wallet_errors.h:386
Definition: wallet_errors.h:786
daemon_busy(std::string &&loc, const std::string &request)
Definition: wallet_errors.h:787
Definition: wallet_errors.h:138
std::string to_string() const
Definition: wallet_errors.h:147
const std::string & status() const
Definition: wallet_errors.h:145
std::string m_status
Definition: wallet_errors.h:155
failed_rpc_request(std::string &&loc, const std::string &status)
Definition: wallet_errors.h:139
Definition: wallet_errors.h:247
std::string m_file
Definition: wallet_errors.h:265
const std::string & file() const
Definition: wallet_errors.h:260
file_error_base(std::string &&loc, const std::string &file)
Definition: wallet_errors.h:248
std::string to_string() const
Definition: wallet_errors.h:262
Definition: wallet_errors.h:810
get_histogram_error(std::string &&loc, const std::string &request)
Definition: wallet_errors.h:811
Definition: wallet_errors.h:818
get_output_distribution(std::string &&loc, const std::string &request)
Definition: wallet_errors.h:819
Definition: wallet_errors.h:412
get_tx_pool_error(std::string &&loc)
Definition: wallet_errors.h:413
std::string to_string() const
Definition: wallet_errors.h:418
Definition: wallet_errors.h:323
index_outofbound(std::string &&loc, const std::string &message)
Definition: wallet_errors.h:324
Definition: wallet_errors.h:293
invalid_multisig_seed(std::string &&loc)
Definition: wallet_errors.h:294
std::string to_string() const
Definition: wallet_errors.h:299
Definition: wallet_errors.h:274
invalid_password(std::string &&loc)
Definition: wallet_errors.h:275
std::string to_string() const
Definition: wallet_errors.h:280
Definition: wallet_errors.h:304
std::string to_string() const
Definition: wallet_errors.h:310
invalid_pregenerated_random(std::string &&loc)
Definition: wallet_errors.h:305
Definition: wallet_errors.h:283
invalid_priority(std::string &&loc)
Definition: wallet_errors.h:284
std::string to_string() const
Definition: wallet_errors.h:289
Definition: wallet_errors.h:802
is_key_image_spent_error(std::string &&loc, const std::string &request)
Definition: wallet_errors.h:803
Definition: wallet_errors.h:843
mms_error(std::string &&loc, const std::string &message)
Definition: wallet_errors.h:845
Definition: wallet_errors.h:200
multisig_export_needed(std::string &&loc)
Definition: wallet_errors.h:201
Definition: wallet_errors.h:208
multisig_import_needed(std::string &&loc)
Definition: wallet_errors.h:209
Definition: wallet_errors.h:852
no_connection_to_bitmessage(std::string &&loc, const std::string &address)
Definition: wallet_errors.h:853
Definition: wallet_errors.h:794
no_connection_to_daemon(std::string &&loc, const std::string &request)
Definition: wallet_errors.h:795
Definition: wallet_errors.h:477
std::string to_string() const
Definition: wallet_errors.h:488
uint64_t available() const
Definition: wallet_errors.h:485
uint64_t m_tx_amount
Definition: wallet_errors.h:499
uint64_t m_available
Definition: wallet_errors.h:498
not_enough_money(std::string &&loc, uint64_t available, uint64_t tx_amount, uint64_t fee)
Definition: wallet_errors.h:478
uint64_t tx_amount() const
Definition: wallet_errors.h:486
Definition: wallet_errors.h:533
not_enough_outs_to_mix(std::string &&loc, const scanty_outs_t &scanty_outs, size_t mixin_count)
Definition: wallet_errors.h:536
const scanty_outs_t & scanty_outs() const
Definition: wallet_errors.h:543
size_t mixin_count() const
Definition: wallet_errors.h:544
scanty_outs_t m_scanty_outs
Definition: wallet_errors.h:558
std::string to_string() const
Definition: wallet_errors.h:546
size_t m_mixin_count
Definition: wallet_errors.h:559
std::unordered_map< uint64_t, uint64_t > scanty_outs_t
Definition: wallet_errors.h:534
Definition: wallet_errors.h:451
not_enough_unlocked_money(std::string &&loc, uint64_t available, uint64_t tx_amount, uint64_t fee)
Definition: wallet_errors.h:452
uint64_t tx_amount() const
Definition: wallet_errors.h:460
uint64_t available() const
Definition: wallet_errors.h:459
std::string to_string() const
Definition: wallet_errors.h:462
uint64_t m_tx_amount
Definition: wallet_errors.h:473
uint64_t m_available
Definition: wallet_errors.h:472
Definition: wallet_errors.h:422
out_of_hashchain_bounds_error(std::string &&loc)
Definition: wallet_errors.h:423
std::string to_string() const
Definition: wallet_errors.h:428
Definition: wallet_errors.h:224
password_entry_failed(std::string &&loc, const std::string &msg="Password entry failed")
Definition: wallet_errors.h:225
Definition: wallet_errors.h:216
password_needed(std::string &&loc, const std::string &msg="Password needed")
Definition: wallet_errors.h:217
Definition: wallet_errors.h:314
refresh_error(std::string &&loc, const std::string &message)
Definition: wallet_errors.h:316
Definition: wallet_errors.h:432
signature_check_failed(std::string &&loc, const std::string &message)
Definition: wallet_errors.h:433
Definition: wallet_errors.h:440
transfer_error(std::string &&loc, const std::string &message)
Definition: wallet_errors.h:442
Definition: wallet_errors.h:563
sources_t m_sources
Definition: wallet_errors.h:622
std::vector< cryptonote::tx_source_entry > sources_t
Definition: wallet_errors.h:564
std::string to_string() const
Definition: wallet_errors.h:586
const sources_t & sources() const
Definition: wallet_errors.h:582
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:567
uint64_t m_unlock_time
Definition: wallet_errors.h:624
std::vector< cryptonote::tx_destination_entry > destinations_t
Definition: wallet_errors.h:565
destinations_t m_destinations
Definition: wallet_errors.h:623
const destinations_t & destinations() const
Definition: wallet_errors.h:583
cryptonote::network_type m_nettype
Definition: wallet_errors.h:625
uint64_t unlock_time() const
Definition: wallet_errors.h:584
Definition: wallet_errors.h:503
uint64_t m_fee
Definition: wallet_errors.h:529
uint64_t m_tx_amount
Definition: wallet_errors.h:528
uint64_t m_available
Definition: wallet_errors.h:527
std::string to_string() const
Definition: wallet_errors.h:516
uint64_t available() const
Definition: wallet_errors.h:512
uint64_t tx_amount() const
Definition: wallet_errors.h:513
tx_not_possible(std::string &&loc, uint64_t available, uint64_t tx_amount, uint64_t fee)
Definition: wallet_errors.h:504
uint64_t fee() const
Definition: wallet_errors.h:514
Definition: wallet_errors.h:396
tx_parse_error(std::string &&loc, const cryptonote::blobdata &tx_blob)
Definition: wallet_errors.h:397
std::string to_string() const
Definition: wallet_errors.h:405
cryptonote::blobdata m_tx_blob
Definition: wallet_errors.h:408
const cryptonote::blobdata & tx_blob() const
Definition: wallet_errors.h:403
Definition: wallet_errors.h:629
std::string m_reason
Definition: wallet_errors.h:658
const cryptonote::transaction & tx() const
Definition: wallet_errors.h:638
cryptonote::transaction m_tx
Definition: wallet_errors.h:656
const std::string & status() const
Definition: wallet_errors.h:639
std::string m_status
Definition: wallet_errors.h:657
std::string to_string() const
Definition: wallet_errors.h:642
const std::string & reason() const
Definition: wallet_errors.h:640
tx_rejected(std::string &&loc, const cryptonote::transaction &tx, const std::string &status, const std::string &reason)
Definition: wallet_errors.h:630
Definition: wallet_errors.h:662
uint64_t fee() const
Definition: wallet_errors.h:677
uint64_t m_fee
Definition: wallet_errors.h:694
cryptonote::network_type m_nettype
Definition: wallet_errors.h:695
std::vector< cryptonote::tx_destination_entry > m_destinations
Definition: wallet_errors.h:693
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:663
std::string to_string() const
Definition: wallet_errors.h:679
const std::vector< cryptonote::tx_destination_entry > & destinations() const
Definition: wallet_errors.h:676
Definition: wallet_errors.h:699
std::string to_string() const
Definition: wallet_errors.h:722
tx_too_big(std::string &&loc, uint64_t tx_weight, uint64_t tx_weight_limit)
Definition: wallet_errors.h:709
uint64_t tx_weight() const
Definition: wallet_errors.h:719
tx_too_big(std::string &&loc, const cryptonote::transaction &tx, uint64_t tx_weight_limit)
Definition: wallet_errors.h:700
cryptonote::transaction m_tx
Definition: wallet_errors.h:737
const cryptonote::transaction & tx() const
Definition: wallet_errors.h:718
uint64_t tx_weight_limit() const
Definition: wallet_errors.h:720
bool tx_valid() const
Definition: wallet_errors.h:717
uint64_t m_tx_weight
Definition: wallet_errors.h:739
bool m_tx_valid
Definition: wallet_errors.h:738
uint64_t m_tx_weight_limit
Definition: wallet_errors.h:740
Definition: wallet_errors.h:170
unexpected_txin_type(std::string &&loc, const cryptonote::transaction &tx)
Definition: wallet_errors.h:171
std::string to_string() const
Definition: wallet_errors.h:179
cryptonote::transaction m_tx
Definition: wallet_errors.h:188
const cryptonote::transaction & tx() const
Definition: wallet_errors.h:177
Definition: wallet_errors.h:101
wallet_error_base(std::string &&loc, const std::string &message)
Definition: wallet_errors.h:112
std::string to_string() const
Definition: wallet_errors.h:104
const std::string & location() const
Definition: wallet_errors.h:102
std::string m_loc
Definition: wallet_errors.h:119
Definition: wallet_errors.h:826
std::string to_string() const
Definition: wallet_errors.h:835
std::string m_keys_file
Definition: wallet_errors.h:838
const std::string & keys_file() const
Definition: wallet_errors.h:832
std::string m_wallet_file
Definition: wallet_errors.h:839
wallet_files_doesnt_correspond(std::string &&loc, const std::string &keys_file, const std::string &wallet_file)
Definition: wallet_errors.h:827
const std::string & wallet_file() const
Definition: wallet_errors.h:833
Definition: wallet_errors.h:774
const std::string & status() const
Definition: wallet_errors.h:780
wallet_generic_rpc_error(std::string &&loc, const std::string &request, const std::string &status)
Definition: wallet_errors.h:775
const std::string m_status
Definition: wallet_errors.h:782
Definition: wallet_errors.h:162
wallet_internal_error(std::string &&loc, const std::string &message)
Definition: wallet_errors.h:163
Definition: wallet_errors.h:192
wallet_not_initialized(std::string &&loc)
Definition: wallet_errors.h:193
Definition: wallet_errors.h:752
std::string to_string() const
Definition: wallet_errors.h:755
wallet_rpc_error(std::string &&loc, const std::string &message, const std::string &request)
Definition: wallet_errors.h:763
std::string m_request
Definition: wallet_errors.h:770
const std::string & request() const
Definition: wallet_errors.h:753
Definition: wallet_errors.h:744
zero_destination(std::string &&loc)
Definition: wallet_errors.h:745