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
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Copyright 2021 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3.
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. Please review the Licences for the specific language governing
// permissions and limitations relating to use of the SAFE Network Software.

use crdts::Dot;
use sn_data_types::{Credit, Debit, Error as DtError, PublicKey, Token};
use thiserror::Error;
#[derive(Error, Debug, PartialEq)]
#[non_exhaustive]
/// SafeNetwork Transfers error type
pub enum Error {
    /// Missing sender actor
    #[error("Sender missing from actors")]
    MissingSender,
    /// Missing recipient
    #[error("Recipient missing from actors")]
    MissingRecipient,
    /// Sender and receiver are the same
    #[error("Sender and recipient are the same")]
    SameSenderAndRecipient,
    /// A debit is awaiting completion. A new debit cannot be started.
    #[error("Current pending debit has not been completed")]
    DebitPending,
    /// The provided PublicKey does not correlate with any key in the section chain history.
    #[error("PublicKey provided by the transfer was never a part of the section chain.")]
    SectionKeyNeverExisted,
    /// The proposed debit has already been seen, or is not the next expected debit
    #[error("Debit already proposed or out of order")]
    DebitProposed,
    /// Credit Id and debit Id do not match
    #[error("Credit and debit ids do not match")]
    CreditDebitIdMismatch,
    /// Credit and debits do not have the same value
    #[error("Credit and debit value do not match")]
    CreditDebitValueMismatch,
    /// This is not the correct actor to validate
    #[error("Validation not intended for this actor")]
    WrongValidationActor,
    /// No pending transfer could be found awaiting accumulation
    #[error("Could not find the expected transfer id among accumulating validations")]
    PendingTransferNotFound,
    /// Validation is not for this actor
    #[error("Validation not expected at this actor {0:?}")]
    NoSetForDebitId(Dot<PublicKey>),
    /// Transer is not for this actor
    #[error("Transfer not expected for this actor {0:?}")]
    NoSetForTransferId(Dot<PublicKey>),
    /// Proposed operation is not the next in sequence. The debit op should be current actor count + 1
    #[error(
        "Operation out of order: debit's counter is '{0}', actor next expected op count is '{1}'"
    )]
    OperationOutOfOrder(u64, u64),
    /// This account has not seen any debits yet. Sent debit should be 0 but was not.
    #[error("Operation out of order debit counter should be 0")]
    ShouldBeInitialOperation,
    /// No credits or debits were found to sync
    #[error("There was no valid history found for provided actor.")]
    NoActorHistory,
    /// 0-value transfers are invalid
    #[error("Transfer amount must be greater than zero")]
    ZeroValueTransfer,
    /// The validation has already been received
    #[error("Validation already received")]
    ValidatedAlready,
    /// Debit is not from this wallet
    #[error("Debit is not from wallet {0}. Debit: {1:?}")]
    DebitDoesNotBelong(PublicKey, Debit),
    /// Credit is not to this wallet
    #[error("Credit is not to wallet {0}. Credit: {1:?}")]
    CreditDoesNotBelong(PublicKey, Credit),
    /// Subtracting this transfer would cause an overlow
    #[error("Overflow when subtracting {0} from balance of: {1}")]
    SubtractionOverflow(Token, Token),
    /// Adding this transfer would cause an overflow
    #[error("Overflow when adding balance {0} and credit of: {1}")]
    AdditionOverflow(Token, Token),
    /// Receive validation failed..
    #[error("Receive validation failed")]
    ReceiveValidationFailed,
    /// TransferCreationFailed..
    #[error("TransferCreationFailed")]
    TransferCreationFailed,
    /// SenderValidationFailed..
    #[error("SenderValidationFailed")]
    SenderValidationFailed,
    /// RegisterProofFailed..
    #[error("RegisterProofFailed")]
    RegisterProofFailed,
    /// InvalidCreditOrDebit..
    #[error("InvalidCreditOrDebit")]
    InvalidCreditOrDebit,
    /// CouldNotGetWalletForReplica..
    #[error("CouldNotGetWalletForReplica")]
    CouldNotGetWalletForReplica,
    /// CouldNotFindGroup..
    #[error("CouldNotFindGroup")]
    CouldNotFindGroup,
    /// ReceivePropagationFailed..
    #[error("ReceivePropagationFailed")]
    ReceivePropagationFailed,
    /// SyncFailed..
    #[error("SyncFailed")]
    SyncFailed,
    /// ValidationFailed..
    #[error("ValidationFailed")]
    ValidationFailed,
    /// GetGenesisFailed..
    #[error("GenesisFailed")]
    GenesisFailed,
    /// Unknown error
    #[error("Unknown error: {0}")]
    Unknown(String),
    /// Wallet not found
    #[error("{0} Wallet not found locally.")]
    WalletNotFound(PublicKey),
    /// Signature shares are insufficient for BLS aggregation
    #[error("Could not aggregate with given signature shares")]
    CannotAggregate,
    /// Signature is not valid
    #[error("Signature is not valid")]
    InvalidSignature,
    /// Operation is not valid
    #[error("Operation is not valid")]
    InvalidOperation,
    /// Owner is not valid
    #[error("Owner is not valid")]
    InvalidOwner,
    /// Insufficient coins.
    #[error("Insufficient balance to complete this operation")]
    InsufficientBalance,
    /// Inexistent sender balance.
    #[error("No such sender key balance")]
    NoSuchSender,
    /// Inexistent recipient balance. Currently only thrown during network genesis
    #[error("No such recipient key balance")]
    NoSuchRecipient,
    /// Balance key already exists.
    #[error("Key already exists")]
    KeyExists,
    /// Other sn_data_types errors
    #[error(transparent)]
    NetworkDataError(#[from] DtError),
    /// Serialisation
    #[error("Serialisation error. {0}")]
    Serialisation(String),
}