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