-
Notifications
You must be signed in to change notification settings - Fork 225
/
status.go
82 lines (73 loc) · 1.49 KB
/
status.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
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package evm
import (
"errors"
"fmt"
)
var (
errUnknownStatus = errors.New("unknown status")
)
// Status ...
type Status uint32
// List of possible status values
// [Unknown] Zero value, means the status is not known
// [Dropped] means the transaction was in the mempool, but was dropped because it failed verification
// [Processing] means the transaction is in the mempool
// [Accepted] means the transaction was accepted
const (
Unknown Status = iota
Dropped
Processing
Accepted
)
// MarshalJSON ...
func (s Status) MarshalJSON() ([]byte, error) {
if err := s.Valid(); err != nil {
return nil, err
}
return []byte(fmt.Sprintf("%q", s)), nil
}
// UnmarshalJSON ...
func (s *Status) UnmarshalJSON(b []byte) error {
str := string(b)
if str == "null" {
return nil
}
switch str {
case `"Unknown"`:
*s = Unknown
case `"Dropped"`:
*s = Dropped
case `"Processing"`:
*s = Processing
case `"Accepted"`:
*s = Accepted
default:
return errUnknownStatus
}
return nil
}
// Valid returns nil if the status is a valid status.
func (s Status) Valid() error {
switch s {
case Unknown, Dropped, Processing, Accepted:
return nil
default:
return errUnknownStatus
}
}
func (s Status) String() string {
switch s {
case Unknown:
return "Unknown"
case Dropped:
return "Dropped"
case Processing:
return "Processing"
case Accepted:
return "Accepted"
default:
return "Invalid status"
}
}