-
Notifications
You must be signed in to change notification settings - Fork 178
/
txVerifier.go
268 lines (224 loc) · 9.09 KB
/
txVerifier.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
package errors
import (
"fmt"
"github.com/onflow/flow-go/model/flow"
)
// InvalidTxByteSizeError indicates that a transaction byte size exceeds the maximum limit.
// this error is the result of failure in any of the following conditions:
// - the total tx byte size is bigger than the limit set by the network
type InvalidTxByteSizeError struct {
txByteSize uint64
maximum uint64
}
// NewInvalidTxByteSizeError constructs a new InvalidTxByteSizeError
func NewInvalidTxByteSizeError(txByteSize, maximum uint64) *InvalidTxByteSizeError {
return &InvalidTxByteSizeError{txByteSize: txByteSize, maximum: maximum}
}
func (e InvalidTxByteSizeError) Error() string {
return fmt.Sprintf("%s transaction byte size (%d) exceeds the maximum byte size allowed for a transaction (%d)", e.Code().String(), e.txByteSize, e.maximum)
}
// Code returns the error code for this error type
func (e InvalidTxByteSizeError) Code() ErrorCode {
return ErrCodeInvalidTxByteSizeError
}
// InvalidReferenceBlockError indicates that the transaction's ReferenceBlockID is not acceptable.
// this error is the result of failure in any of the following conditions:
// - ReferenceBlockID refer to a non-existing block
// - ReferenceBlockID == ZeroID (if configured by the network)
type InvalidReferenceBlockError struct {
referenceBlockID string
}
// NewInvalidReferenceBlockError constructs a new InvalidReferenceBlockError
func NewInvalidReferenceBlockError(referenceBlockID string) *InvalidReferenceBlockError {
return &InvalidReferenceBlockError{referenceBlockID: referenceBlockID}
}
func (e InvalidReferenceBlockError) Error() string {
return fmt.Sprintf("%s reference block is pointing to an invalid block: %s", e.Code().String(), e.referenceBlockID)
}
// Code returns the error code for this error type
func (e InvalidReferenceBlockError) Code() ErrorCode {
return ErrCodeInvalidReferenceBlockError
}
// ExpiredTransactionError indicates that a transaction has expired.
// this error is the result of failure in any of the following conditions:
// - ReferenceBlock.Height - CurrentBlock.Height < Expiry Limit (Transaction is Expired)
type ExpiredTransactionError struct {
refHeight, finalHeight uint64
}
// NewExpiredTransactionError constructs a new ExpiredTransactionError
func NewExpiredTransactionError(refHeight, finalHeight uint64) *ExpiredTransactionError {
return &ExpiredTransactionError{refHeight: refHeight, finalHeight: finalHeight}
}
func (e ExpiredTransactionError) Error() string {
return fmt.Sprintf("%s transaction is expired: ref_height=%d final_height=%d", e.Code().String(), e.refHeight, e.finalHeight)
}
// Code returns the error code for this error type
func (e ExpiredTransactionError) Code() ErrorCode {
return ErrCodeInvalidReferenceBlockError
}
// InvalidScriptError indicates that a transaction contains an invalid Cadence script.
// this error is the result of failure in any of the following conditions:
// - script is empty
// - script can not be parsed by the cadence parser
// - comment-only script, len(program.Declarations) == 0
type InvalidScriptError struct {
err error
}
// NewInvalidScriptError constructs a new InvalidScriptError
func NewInvalidScriptError(err error) *InvalidScriptError {
return &InvalidScriptError{err: err}
}
func (e InvalidScriptError) Error() string {
return fmt.Sprintf("%s failed to parse transaction Cadence script: %s", e.Code().String(), e.err.Error())
}
// Code returns the error code for this error type
func (e InvalidScriptError) Code() ErrorCode {
return ErrCodeInvalidScriptError
}
// Unwrap unwraps the error
func (e InvalidScriptError) Unwrap() error {
return e.err
}
// InvalidGasLimitError indicates that a transaction specifies a gas limit that exceeds the maximum allowed by the network.
type InvalidGasLimitError struct {
actual uint64
maximum uint64
}
// NewInvalidGasLimitError constructs a new InvalidGasLimitError
func NewInvalidGasLimitError(actual, maximum uint64) *InvalidGasLimitError {
return &InvalidGasLimitError{actual: actual, maximum: maximum}
}
func (e InvalidGasLimitError) Error() string {
return fmt.Sprintf("%s transaction gas limit (%d) exceeds the maximum gas limit (%d)", e.Code().String(), e.actual, e.maximum)
}
// Code returns the error code for this error type
func (e InvalidGasLimitError) Code() ErrorCode {
return ErrCodeInvalidGasLimitError
}
// InvalidProposalSignatureError indicates that no valid signature is provided for the proposal key.
type InvalidProposalSignatureError struct {
address flow.Address
keyIndex uint64
err error
}
// NewInvalidProposalSignatureError constructs a new InvalidProposalSignatureError
func NewInvalidProposalSignatureError(address flow.Address, keyIndex uint64, err error) *InvalidProposalSignatureError {
return &InvalidProposalSignatureError{address: address, keyIndex: keyIndex, err: err}
}
func (e InvalidProposalSignatureError) Error() string {
return fmt.Sprintf(
"%s invalid proposal key: public key %d on account %s does not have a valid signature: %s",
e.Code().String(),
e.keyIndex,
e.address,
e.err.Error(),
)
}
// Code returns the error code for this error type
func (e InvalidProposalSignatureError) Code() ErrorCode {
return ErrCodeInvalidProposalSignatureError
}
// Unwrap unwraps the error
func (e InvalidProposalSignatureError) Unwrap() error {
return e.err
}
// InvalidProposalSeqNumberError indicates that proposal key sequence number does not match the on-chain value.
type InvalidProposalSeqNumberError struct {
address flow.Address
keyIndex uint64
currentSeqNumber uint64
providedSeqNumber uint64
}
// NewInvalidProposalSeqNumberError constructs a new InvalidProposalSeqNumberError
func NewInvalidProposalSeqNumberError(address flow.Address, keyIndex uint64, currentSeqNumber uint64, providedSeqNumber uint64) *InvalidProposalSeqNumberError {
return &InvalidProposalSeqNumberError{address: address,
keyIndex: keyIndex,
currentSeqNumber: currentSeqNumber,
providedSeqNumber: providedSeqNumber}
}
// CurrentSeqNumber returns the current sequence number
func (e InvalidProposalSeqNumberError) CurrentSeqNumber() uint64 {
return e.currentSeqNumber
}
// ProvidedSeqNumber returns the provided sequence number
func (e InvalidProposalSeqNumberError) ProvidedSeqNumber() uint64 {
return e.providedSeqNumber
}
func (e InvalidProposalSeqNumberError) Error() string {
return fmt.Sprintf(
"%s invalid proposal key: public key %d on account %s has sequence number %d, but given %d",
e.Code().String(),
e.keyIndex,
e.address.String(),
e.currentSeqNumber,
e.providedSeqNumber,
)
}
// Code returns the error code for this error type
func (e InvalidProposalSeqNumberError) Code() ErrorCode {
return ErrCodeInvalidProposalSeqNumberError
}
// InvalidPayloadSignatureError indicates that signature verification for a key in this transaction has failed.
// this error is the result of failure in any of the following conditions:
// - provided hashing method is not supported
// - signature size is wrong
// - signature verification failed
// - public key doesn't match the one in the signature
type InvalidPayloadSignatureError struct {
address flow.Address
keyIndex uint64
err error
}
// NewInvalidPayloadSignatureError constructs a new InvalidPayloadSignatureError
func NewInvalidPayloadSignatureError(address flow.Address, keyIndex uint64, err error) *InvalidPayloadSignatureError {
return &InvalidPayloadSignatureError{address: address, keyIndex: keyIndex, err: err}
}
func (e InvalidPayloadSignatureError) Error() string {
return fmt.Sprintf(
"%s invalid payload signature: public key %d on account %s does not have a valid signature: %s",
e.Code().String(),
e.keyIndex,
e.address,
e.err.Error(),
)
}
// Code returns the error code for this error type
func (e InvalidPayloadSignatureError) Code() ErrorCode {
return ErrCodeInvalidPayloadSignatureError
}
// Unwrap unwraps the error
func (e InvalidPayloadSignatureError) Unwrap() error {
return e.err
}
// InvalidEnvelopeSignatureError indicates that signature verification for a envelope key in this transaction has failed.
// this error is the result of failure in any of the following conditions:
// - provided hashing method is not supported
// - signature size is wrong
// - signature verification failed
// - public key doesn't match the one in the signature
type InvalidEnvelopeSignatureError struct {
address flow.Address
keyIndex uint64
err error
}
// NewInvalidEnvelopeSignatureError constructs a new InvalidEnvelopeSignatureError
func NewInvalidEnvelopeSignatureError(address flow.Address, keyIndex uint64, err error) *InvalidEnvelopeSignatureError {
return &InvalidEnvelopeSignatureError{address: address, keyIndex: keyIndex, err: err}
}
func (e InvalidEnvelopeSignatureError) Error() string {
return fmt.Sprintf(
"%s invalid envelope key: public key %d on account %s does not have a valid signature: %s",
e.Code().String(),
e.keyIndex,
e.address,
e.err.Error(),
)
}
// Code returns the error code for this error type
func (e InvalidEnvelopeSignatureError) Code() ErrorCode {
return ErrCodeInvalidEnvelopeSignatureError
}
// Unwrap unwraps the error
func (e InvalidEnvelopeSignatureError) Unwrap() error {
return e.err
}