github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/fvm/errors/accounts.go (about)

     1  package errors
     2  
     3  import (
     4  	"github.com/onflow/flow-go/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  // IsAccountPublicKeyNotFoundError returns true if error has this type
    45  func IsAccountPublicKeyNotFoundError(err error) bool {
    46  	return HasErrorCode(err, ErrCodeAccountPublicKeyNotFoundError)
    47  }
    48  
    49  // NewAccountPublicKeyLimitError constructs a new CodedError.  It is returned
    50  // when an account tries to add public keys over the limit.
    51  func NewAccountPublicKeyLimitError(
    52  	address flow.Address,
    53  	counts uint64,
    54  	limit uint64,
    55  ) CodedError {
    56  	return NewCodedError(
    57  		ErrCodeAccountPublicKeyLimitError,
    58  		"account's (%s) public key count (%d) exceeded the limit (%d)",
    59  		address,
    60  		counts,
    61  		limit)
    62  }