github.com/koko1123/flow-go-1@v0.29.6/fvm/errors/accounts.go (about)

     1  package errors
     2  
     3  import (
     4  	"github.com/koko1123/flow-go-1/model/flow"
     5  )
     6  
     7  func NewAccountNotFoundError(address flow.Address) CodedError {
     8  	return NewCodedError(
     9  		ErrCodeAccountNotFoundError,
    10  		"account not found for address %s",
    11  		address.String())
    12  }
    13  
    14  // IsAccountNotFoundError returns true if error has this type
    15  func IsAccountNotFoundError(err error) bool {
    16  	return HasErrorCode(err, ErrCodeAccountNotFoundError)
    17  }
    18  
    19  // NewAccountAlreadyExistsError constructs a new CodedError. It is returned
    20  // when account creation fails because another account already exist at that
    21  // address.
    22  //
    23  // TODO maybe this should be failure since user has no control over this
    24  func NewAccountAlreadyExistsError(address flow.Address) CodedError {
    25  	return NewCodedError(
    26  		ErrCodeAccountAlreadyExistsError,
    27  		"account with address %s already exists",
    28  		address)
    29  }
    30  
    31  // NewAccountPublicKeyNotFoundError constructs a new CodedError. It is returned
    32  // when a public key not found for the given address and key index.
    33  func NewAccountPublicKeyNotFoundError(
    34  	address flow.Address,
    35  	keyIndex uint64,
    36  ) CodedError {
    37  	return NewCodedError(
    38  		ErrCodeAccountPublicKeyNotFoundError,
    39  		"account public key not found for address %s and key index %d",
    40  		address,
    41  		keyIndex)
    42  }
    43  
    44  // IsAccountAccountPublicKeyNotFoundError returns true if error has this type
    45  func IsAccountAccountPublicKeyNotFoundError(err error) bool {
    46  	return HasErrorCode(err, ErrCodeAccountPublicKeyNotFoundError)
    47  }
    48  
    49  // FrozenAccountError is returned when a frozen account signs a transaction
    50  type FrozenAccountError struct {
    51  	address flow.Address
    52  
    53  	CodedError
    54  }
    55  
    56  // NewFrozenAccountError constructs a new FrozenAccountError
    57  func NewFrozenAccountError(address flow.Address) CodedError {
    58  	return FrozenAccountError{
    59  		address: address,
    60  		CodedError: NewCodedError(
    61  			ErrCodeFrozenAccountError,
    62  			"account %s is frozen",
    63  			address),
    64  	}
    65  }
    66  
    67  // Address returns the address of frozen account
    68  func (e FrozenAccountError) Address() flow.Address {
    69  	return e.address
    70  }
    71  
    72  // NewAccountPublicKeyLimitError constructs a new CodedError.  It is returned
    73  // when an account tries to add public keys over the limit.
    74  func NewAccountPublicKeyLimitError(
    75  	address flow.Address,
    76  	counts uint64,
    77  	limit uint64,
    78  ) CodedError {
    79  	return NewCodedError(
    80  		ErrCodeAccountPublicKeyLimitError,
    81  		"account's (%s) public key count (%d) exceeded the limit (%d)",
    82  		address,
    83  		counts,
    84  		limit)
    85  }