2018-04-09 08:18:22 +00:00
|
|
|
package sign
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
2018-06-08 11:29:50 +00:00
|
|
|
"github.com/status-im/status-go/account"
|
2018-04-09 08:18:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2018-04-10 10:02:54 +00:00
|
|
|
//ErrSignReqNotFound - error sign request hash not found
|
|
|
|
ErrSignReqNotFound = errors.New("sign request not found")
|
|
|
|
//ErrSignReqInProgress - error sign request is in progress
|
|
|
|
ErrSignReqInProgress = errors.New("sign request is in progress")
|
|
|
|
//ErrSignReqTimedOut - error sign request sending timed out
|
|
|
|
ErrSignReqTimedOut = errors.New("sign request sending timed out")
|
|
|
|
//ErrSignReqDiscarded - error sign request discarded
|
|
|
|
ErrSignReqDiscarded = errors.New("sign request has been discarded")
|
2018-04-09 08:18:22 +00:00
|
|
|
)
|
|
|
|
|
2018-04-10 10:02:54 +00:00
|
|
|
// TransientError means that the sign request won't be removed from the list of
|
|
|
|
// pending if it happens. There are a few built-in transient errors, and this
|
|
|
|
// struct can be used to wrap any error to be transient.
|
|
|
|
type TransientError struct {
|
|
|
|
Reason error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Error returns the string representation of the underlying error.
|
|
|
|
func (e TransientError) Error() string {
|
|
|
|
return e.Reason.Error()
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewTransientError wraps an error into a TransientError structure.
|
|
|
|
func NewTransientError(reason error) TransientError {
|
|
|
|
return TransientError{reason}
|
|
|
|
}
|
|
|
|
|
2018-04-09 08:18:22 +00:00
|
|
|
// remove from queue on any error (except for transient ones) and propagate
|
|
|
|
// defined as map[string]bool because errors from ethclient returned wrapped as jsonError
|
|
|
|
var transientErrs = map[string]bool{
|
|
|
|
keystore.ErrDecrypt.Error(): true, // wrong password
|
|
|
|
account.ErrNoAccountSelected.Error(): true, // account not selected
|
|
|
|
}
|
|
|
|
|
|
|
|
func isTransient(err error) bool {
|
2018-04-10 10:02:54 +00:00
|
|
|
_, ok := err.(TransientError)
|
|
|
|
if ok {
|
|
|
|
return true
|
|
|
|
}
|
2018-04-09 08:18:22 +00:00
|
|
|
_, transient := transientErrs[err.Error()]
|
|
|
|
return transient
|
|
|
|
}
|