-
Notifications
You must be signed in to change notification settings - Fork 16
/
error.go
122 lines (98 loc) · 5.87 KB
/
error.go
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
/*
*/
package status_codes
import (
"encoding/json"
"fmt"
)
/*
Protocol Error definition
*/
type ProtocolError struct {
Code int `json:"code"`
Msg string `json:"msg"`
}
func (se ProtocolError) Error() string {
return fmt.Sprintf("%d: %s", se.Code, se.Msg)
}
func (se ProtocolError) ErrorMsg() string {
return se.Msg
}
func (se ProtocolError) Wrap(err error) *ProtocolError {
return &ProtocolError{se.Code,
se.Msg + ": " + err.Error()}
}
func (se ProtocolError) Marshal() string {
errInByte, _ := json.Marshal(se)
return string(errInByte)
}
func UnMarshalError(str string) (ProtocolError, error) {
errByte := []byte(str)
errObj := ProtocolError{}
err := json.Unmarshal(errByte, &errObj)
return errObj, err
}
func WrapError(err error, code int, msg string) *ProtocolError {
return &ProtocolError{code, msg + ": " + err.Error()}
}
/*
Status declarations
*/
var (
ErrSerialization = ProtocolError{InternalErrorSerialization, "error in serialization"}
ErrLoadingNodeKey = ProtocolError{IOErrorNodeKey, "error reading node key file"}
ErrParsingAddress = ProtocolError{ParseErrorAddress, "error parsing address"}
ErrChainType = ProtocolError{ConfigurationErrorChainType, "error getting chain type"}
ErrAddingAccount = ProtocolError{WalletErrorAddingAccount, "error adding account to wallet"}
ErrGettingAccount = ProtocolError{WalletErrorGettingAccount, "error getting account from wallet"}
ErrDeletingAccount = ProtocolError{WalletErrorDeleteAccount, "error in deleting account"}
ErrGeneratingAccount = ProtocolError{AccountsErrorGeneratingNewAccount, "error generating new account"}
ErrAccountNotFound = ProtocolError{AccountNotFound, "account is not in wallet"}
ErrSigningError = ProtocolError{InternalErrorSigning, "error while signing"}
ErrKeyGeneration = ProtocolError{InternalErrorGeneratingKeyPair, "error generating key pair"}
ErrGettingTracker = ProtocolError{InternalErrorGettingTracker, "error getting tracker"}
ErrTrackerNotFound = ProtocolError{InternalErrorTrackerNotFound, "tracker not found"}
ErrTrackerBusy = ProtocolError{InternalErrorTrackerBusy, "tracker busy"}
ErrTrackerBalance = ProtocolError{InternalErrorTrackerInsufficientBalance, "insufficient balance in tracker"}
// Query errors
ErrBadAddress = ProtocolError{IncorrectAddress, "address incorrect"}
ErrGettingBalance = ProtocolError{InternalErrorGettingBalance, "error getting balance"}
ErrListValidators = ProtocolError{InternalErrorListValidators, "error getting list of validators"}
ErrListWitnesses = ProtocolError{InternalErrorListWitnesses, "error getting list of witnesses"}
ErrGetProposal = ProtocolError{InternalErrorGettingProposal, "error getting proposal"}
ErrFindingCurrency = ProtocolError{CurrencyNotFound, "error finding currency"}
ErrGetTx = ProtocolError{TxNotFound, "error get tx from tendermint"}
// ONS errors
ErrBadName = ProtocolError{ONSErrDomainMissing, "domain name not provided"}
ErrBadOwner = ProtocolError{ONSErrOwnerAddressMissing, "owner address not provided"}
ErrDomainNotFound = ProtocolError{DomainNotFound, "domain not found"}
ErrFlagNotSet = ProtocolError{ONSErrOnSaleFlagNotSet, "onsale flag not set"}
ErrDomainExists = ProtocolError{ONSErrDomainExists, "domain already exists"}
ErrDebitingFromAddress = ProtocolError{ONSErrDebitingFromAddress, "cannot debit from address"}
ErrAddingToFeePool = ProtocolError{ONSErrAddingToFeePool, "cannot add to fee pool"}
ErrInvalidUri = ProtocolError{ONSErrInvalidUri, "invalid uri"}
ErrGettingParentName = ProtocolError{ONSErrGettingParentName, "cannot get parent name"}
ErrParentDoesNotExist = ProtocolError{ONSErrParentDoesNotExist, "parent domain does not exist"}
ErrParentNotOwned = ProtocolError{ONSErrParentNotOwned, "parent domain not owned"}
ErrFailedToCalculateExpiry = ProtocolError{ONSErrFailedToCalculateExpiry, "failed to calculate expiry"}
ErrFailedToCreateDomain = ProtocolError{ONSErrFailedToCreateDomain, "failed to create domain"}
ErrFailedAddingDomainToStore = ProtocolError{ONSErrFailedAddingDomainToStore, "failed to add domain to store"}
ErrInvalidDomainName = ProtocolError{ONSErrInvalidDomainName, "invalid domain name"}
// Tx errors
// External Errors
ErrBTCTxNotFound = ProtocolError{ExternalErrBitcoinTxNotFound, "bitcoin txn not found"}
ErrBadBTCAddress = ProtocolError{ParseErrorBTCAddress, "bad btc address"}
ErrBTCNotEnoughConfirmations = ProtocolError{ExternalErrNotEnoughConfirmations, "not enough btc confirmations"}
ErrBTCNotSpendable = ProtocolError{ExternalErrNotSpendable, "btc source not spendable"}
ErrBTCReadingTxn = ProtocolError{ExternalErrGettingBTCTxn, "err getting btc txn"}
ErrBadBTCTxn = ProtocolError{ParseErrorBadBTCTxn, "bad btc txn"}
//Ethereum Errors
ErrPreparingETHLock = ProtocolError{Code: ExternalErrUnableToCreateEthTX, Msg: "Unable to create an unsigned lock transaction for Ethereum"}
ErrPreparingOLTLock = ProtocolError{Code: ExternalErrUnableToCreateOLTLockTX, Msg: "Unable to create OLT lock Tx for Ethereum"}
ErrPreparingErc20OLTLock = ProtocolError{Code: ExternalErrUnableToCreateErc20OLTLockTX, Msg: "Unable to create OLT lock Tx for ERC20 Token"}
ErrUnmarshaling = ProtocolError{Code: ErrUnmarshalingRedeem, Msg: "Unable to unmarshall the incoming transaction into struct ,Wrong Json data"}
//Tracker Error
ErrGettingTrackerStatusFailed = ProtocolError{Code: ETHTrackerNotFoundFailed, Msg: "Ethereum Tracker not found in the Failed tracker store"}
ErrGettingTrackerStatusSuccess = ProtocolError{Code: ETHTrackerNotFoundSuccess, Msg: "Ethereum Tracker not found in the Success tracker store"}
ErrGettingTrackerStatusOngoing = ProtocolError{Code: ETHTrackerNotFoundOngoing, Msg: "Ethereum Tracker not found in the Ongoing tracker store"}
)