-
Notifications
You must be signed in to change notification settings - Fork 178
/
accounts.go
85 lines (74 loc) · 2.34 KB
/
accounts.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
package errors
import (
"github.com/onflow/flow-go/model/flow"
)
func NewAccountNotFoundError(address flow.Address) CodedError {
return NewCodedError(
ErrCodeAccountNotFoundError,
"account not found for address %s",
address.String())
}
// IsAccountNotFoundError returns true if error has this type
func IsAccountNotFoundError(err error) bool {
return HasErrorCode(err, ErrCodeAccountNotFoundError)
}
// NewAccountAlreadyExistsError constructs a new CodedError. It is returned
// when account creation fails because another account already exist at that
// address.
//
// TODO maybe this should be failure since user has no control over this
func NewAccountAlreadyExistsError(address flow.Address) CodedError {
return NewCodedError(
ErrCodeAccountAlreadyExistsError,
"account with address %s already exists",
address)
}
// NewAccountPublicKeyNotFoundError constructs a new CodedError. It is returned
// when a public key not found for the given address and key index.
func NewAccountPublicKeyNotFoundError(
address flow.Address,
keyIndex uint64,
) CodedError {
return NewCodedError(
ErrCodeAccountPublicKeyNotFoundError,
"account public key not found for address %s and key index %d",
address,
keyIndex)
}
// IsAccountAccountPublicKeyNotFoundError returns true if error has this type
func IsAccountAccountPublicKeyNotFoundError(err error) bool {
return HasErrorCode(err, ErrCodeAccountPublicKeyNotFoundError)
}
// FrozenAccountError is returned when a frozen account signs a transaction
type FrozenAccountError struct {
address flow.Address
CodedError
}
// NewFrozenAccountError constructs a new FrozenAccountError
func NewFrozenAccountError(address flow.Address) CodedError {
return FrozenAccountError{
address: address,
CodedError: NewCodedError(
ErrCodeFrozenAccountError,
"account %s is frozen",
address),
}
}
// Address returns the address of frozen account
func (e FrozenAccountError) Address() flow.Address {
return e.address
}
// NewAccountPublicKeyLimitError constructs a new CodedError. It is returned
// when an account tries to add public keys over the limit.
func NewAccountPublicKeyLimitError(
address flow.Address,
counts uint64,
limit uint64,
) CodedError {
return NewCodedError(
ErrCodeAccountPublicKeyLimitError,
"account's (%s) public key count (%d) exceeded the limit (%d)",
address,
counts,
limit)
}