-
Notifications
You must be signed in to change notification settings - Fork 179
/
base.go
104 lines (93 loc) · 2.91 KB
/
base.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
package errors
import (
"github.com/onflow/cadence/runtime"
"github.com/onflow/flow-go/model/flow"
)
// NewInvalidAddressErrorf constructs a new CodedError which indicates that a
// transaction references an invalid flow Address in either the Authorizers or
// Payer field.
func NewInvalidAddressErrorf(
address flow.Address,
msg string,
args ...interface{},
) CodedError {
return NewCodedError(
ErrCodeInvalidAddressError,
"invalid address (%s): "+msg,
append([]interface{}{address.String()}, args...)...)
}
// NewInvalidArgumentErrorf constructs a new CodedError which indicates that a
// transaction includes invalid arguments. This error is the result of failure
// in any of the following conditions:
// - number of arguments doesn't match the template
//
// TODO add more cases like argument size
func NewInvalidArgumentErrorf(msg string, args ...interface{}) CodedError {
return NewCodedError(
ErrCodeInvalidArgumentError,
"transaction arguments are invalid: ("+msg+")",
args...)
}
func IsInvalidArgumentError(err error) bool {
return HasErrorCode(err, ErrCodeInvalidArgumentError)
}
// NewInvalidLocationErrorf constructs a new CodedError which indicates an
// invalid location is passed.
func NewInvalidLocationErrorf(
location runtime.Location,
msg string,
args ...interface{},
) CodedError {
locationStr := ""
if location != nil {
locationStr = location.String()
}
return NewCodedError(
ErrCodeInvalidLocationError,
"location (%s) is not a valid location: "+msg,
append([]interface{}{locationStr}, args...)...)
}
// NewValueErrorf constructs a new CodedError which indicates a value is not
// valid value.
func NewValueErrorf(
valueStr string,
msg string,
args ...interface{},
) CodedError {
return NewCodedError(
ErrCodeValueError,
"invalid value (%s): "+msg,
append([]interface{}{valueStr}, args...)...)
}
func IsValueError(err error) bool {
return HasErrorCode(err, ErrCodeValueError)
}
// NewOperationAuthorizationErrorf constructs a new CodedError which indicates
// not enough authorization to perform an operations like account creation or
// smart contract deployment.
func NewOperationAuthorizationErrorf(
operation string,
msg string,
args ...interface{},
) CodedError {
return NewCodedError(
ErrCodeOperationAuthorizationError,
"(%s) is not authorized: "+msg,
append([]interface{}{operation}, args...)...)
}
// NewAccountAuthorizationErrorf constructs a new CodedError which indicates
// that an authorization issue either:
// - a transaction is missing a required signature to authorize access to an
// account, or
// - a transaction doesn't have authorization to performe some operations like
// account creation.
func NewAccountAuthorizationErrorf(
address flow.Address,
msg string,
args ...interface{},
) CodedError {
return NewCodedError(
ErrCodeAccountAuthorizationError,
"authorization failed for account %s: "+msg,
append([]interface{}{address}, args...)...)
}