-
Notifications
You must be signed in to change notification settings - Fork 179
/
accounts.go
117 lines (96 loc) · 3.26 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
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
package errors
import (
"errors"
"fmt"
"github.com/onflow/flow-go/model/flow"
)
// AccountNotFoundError is returned when account doesn't exist for the given address
type AccountNotFoundError struct {
address flow.Address
}
// NewAccountNotFoundError constructs a new AccountNotFoundError
func NewAccountNotFoundError(address flow.Address) error {
return &AccountNotFoundError{}
}
func (e AccountNotFoundError) Error() string {
return fmt.Sprintf(
"%s account not found for address %s",
e.Code().String(),
e.address.String(),
)
}
// Code returns the error code for this error type
func (e AccountNotFoundError) Code() ErrorCode {
return ErrCodeAccountNotFoundError
}
// IsAccountNotFoundError returns true if error has this type
func IsAccountNotFoundError(err error) bool {
var t *AccountNotFoundError
return errors.As(err, &t)
}
// AccountAlreadyExistsError 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
type AccountAlreadyExistsError struct {
address flow.Address
}
// NewAccountAlreadyExistsError constructs a new AccountAlreadyExistsError
func NewAccountAlreadyExistsError(address flow.Address) error {
return &AccountAlreadyExistsError{address: address}
}
func (e AccountAlreadyExistsError) Error() string {
return fmt.Sprintf(
"%s account with address %s already exists",
e.Code().String(),
e.address,
)
}
// Code returns the error code for this error type
func (e AccountAlreadyExistsError) Code() ErrorCode {
return ErrCodeAccountAlreadyExistsError
}
// AccountPublicKeyNotFoundError is returned when a public key not found for the given address and key index
type AccountPublicKeyNotFoundError struct {
address flow.Address
keyIndex uint64
}
// NewAccountPublicKeyNotFoundError constructs a new AccountPublicKeyNotFoundError
func NewAccountPublicKeyNotFoundError(address flow.Address, keyIndex uint64) *AccountPublicKeyNotFoundError {
return &AccountPublicKeyNotFoundError{address: address, keyIndex: keyIndex}
}
// IsAccountAccountPublicKeyNotFoundError returns true if error has this type
func IsAccountAccountPublicKeyNotFoundError(err error) bool {
var t *AccountPublicKeyNotFoundError
return errors.As(err, &t)
}
func (e AccountPublicKeyNotFoundError) Error() string {
return fmt.Sprintf(
"%s account public key not found for address %s and key index %d",
e.Code().String(),
e.address,
e.keyIndex,
)
}
// Code returns the error code for this error type
func (e AccountPublicKeyNotFoundError) Code() ErrorCode {
return ErrCodeAccountPublicKeyNotFoundError
}
// FrozenAccountError is returned when a frozen account signs a transaction
type FrozenAccountError struct {
address flow.Address
}
// NewFrozenAccountError constructs a new FrozenAccountError
func NewFrozenAccountError(address flow.Address) error {
return &FrozenAccountError{address: address}
}
// Address returns the address of frozen account
func (e FrozenAccountError) Address() flow.Address {
return e.address
}
func (e FrozenAccountError) Error() string {
return fmt.Sprintf("%s account %s is frozen", e.Code().String(), e.address)
}
// Code returns the error code for this error type
func (e FrozenAccountError) Code() ErrorCode {
return ErrCodeFrozenAccountError
}