danicoin/src/Wallet/WalletErrors.h

118 lines
4 KiB
C
Raw Normal View History

2015-05-27 12:08:46 +00:00
// Copyright (c) 2012-2015, The CryptoNote developers, The Bytecoin developers
2014-08-13 10:38:35 +00:00
//
// This file is part of Bytecoin.
//
// Bytecoin is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Bytecoin is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Bytecoin. If not, see <http://www.gnu.org/licenses/>.
2014-06-25 17:21:42 +00:00
#pragma once
#include <string>
#include <system_error>
2015-05-27 12:08:46 +00:00
namespace CryptoNote {
2014-06-25 17:21:42 +00:00
namespace error {
// custom error conditions enum type:
enum WalletErrorCodes {
NOT_INITIALIZED = 1,
ALREADY_INITIALIZED,
WRONG_STATE,
WRONG_PASSWORD,
INTERNAL_WALLET_ERROR,
MIXIN_COUNT_TOO_BIG,
BAD_ADDRESS,
TRANSACTION_SIZE_TOO_BIG,
WRONG_AMOUNT,
SUM_OVERFLOW,
ZERO_DESTINATION,
TX_CANCEL_IMPOSSIBLE,
TX_CANCELLED,
OPERATION_CANCELLED,
2015-07-30 15:22:07 +00:00
TX_TRANSFER_IMPOSSIBLE,
2015-08-11 14:33:19 +00:00
WRONG_VERSION,
FEE_TOO_SMALL,
2015-08-27 18:55:14 +00:00
KEY_GENERATION_ERROR,
INDEX_OUT_OF_RANGE,
ADDRESS_ALREADY_EXISTS,
2015-10-01 15:27:18 +00:00
TRACKING_MODE,
2015-12-09 13:19:03 +00:00
WRONG_PARAMETERS,
OBJECT_NOT_FOUND,
WALLET_NOT_FOUND,
CHANGE_ADDRESS_REQUIRED,
CHANGE_ADDRESS_NOT_FOUND
2014-06-25 17:21:42 +00:00
};
// custom category:
class WalletErrorCategory : public std::error_category {
public:
static WalletErrorCategory INSTANCE;
virtual const char* name() const throw() {
return "WalletErrorCategory";
}
virtual std::error_condition default_error_condition(int ev) const throw() {
return std::error_condition(ev, *this);
}
virtual std::string message(int ev) const {
switch (ev) {
2015-08-27 18:55:14 +00:00
case NOT_INITIALIZED: return "Object was not initialized";
case WRONG_PASSWORD: return "The password is wrong";
case ALREADY_INITIALIZED: return "The object is already initialized";
2015-10-01 15:27:18 +00:00
case INTERNAL_WALLET_ERROR: return "Internal error occurred";
2015-08-27 18:55:14 +00:00
case MIXIN_COUNT_TOO_BIG: return "MixIn count is too big";
case BAD_ADDRESS: return "Bad address";
2014-06-25 17:21:42 +00:00
case TRANSACTION_SIZE_TOO_BIG: return "Transaction size is too big";
2015-08-27 18:55:14 +00:00
case WRONG_AMOUNT: return "Wrong amount";
case SUM_OVERFLOW: return "Sum overflow";
case ZERO_DESTINATION: return "The destination is empty";
case TX_CANCEL_IMPOSSIBLE: return "Impossible to cancel transaction";
case WRONG_STATE: return "The wallet is in wrong state (maybe loading or saving), try again later";
case OPERATION_CANCELLED: return "The operation you've requested has been cancelled";
case TX_TRANSFER_IMPOSSIBLE: return "Transaction transfer impossible";
case WRONG_VERSION: return "Wrong version";
case FEE_TOO_SMALL: return "Transaction fee is too small";
case KEY_GENERATION_ERROR: return "Cannot generate new key";
case INDEX_OUT_OF_RANGE: return "Index is out of range";
case ADDRESS_ALREADY_EXISTS: return "Address already exists";
case TRACKING_MODE: return "The wallet is in tracking mode";
2015-10-01 15:27:18 +00:00
case WRONG_PARAMETERS: return "Wrong parameters passed";
2015-12-09 13:19:03 +00:00
case OBJECT_NOT_FOUND: return "Object not found";
case WALLET_NOT_FOUND: return "Requested wallet not found";
case CHANGE_ADDRESS_REQUIRED: return "Change address required";
case CHANGE_ADDRESS_NOT_FOUND: return "Change address not found";
2015-08-27 18:55:14 +00:00
default: return "Unknown error";
2014-06-25 17:21:42 +00:00
}
}
private:
WalletErrorCategory() {
}
};
}
}
2015-05-27 12:08:46 +00:00
inline std::error_code make_error_code(CryptoNote::error::WalletErrorCodes e) {
return std::error_code(static_cast<int>(e), CryptoNote::error::WalletErrorCategory::INSTANCE);
2014-06-25 17:21:42 +00:00
}
2015-12-09 13:19:03 +00:00
namespace std {
template <>
struct is_error_code_enum<CryptoNote::error::WalletErrorCodes>: public true_type {};
}