/
status.go
150 lines (139 loc) · 3.91 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
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
package mongodb
import (
"errors"
"fmt"
"github.com/anyswap/CrossChain-Router/v3/tokens"
)
// -----------------------------------------------
// swap status change graph
// symbol '--->' mean transfer only under checked condition (eg. manual process)
//
// -----------------------------------------------
// 1. swap register status change graph
//
// TxNotStable -> |- TxVerifyFailed -> manual
// |- TxWithWrongValue -> manual
// |- SwapInBlacklist -> manual
// |- TxWithBigValue ---> TxNotSwapped
// |- TxNotSwapped -> |- TxProcessed (->MatchTxNotStable)
// -----------------------------------------------
// 2. swap result status change graph
//
// TxWithBigValue ---> MatchTxEmpty
// MatchTxEmpty -> | MatchTxNotStable -> |- MatchTxStable
// |- MatchTxFailed -> manual
// -----------------------------------------------
// SwapStatus swap status
type SwapStatus uint16
// swap status values
const (
TxNotStable SwapStatus = 0
TxVerifyFailed SwapStatus = 1
TxWithWrongValue SwapStatus = 3
TxNotSwapped SwapStatus = 5
TxProcessed SwapStatus = 7
MatchTxEmpty SwapStatus = 8
MatchTxNotStable SwapStatus = 9
MatchTxStable SwapStatus = 10
TxWithBigValue SwapStatus = 12
MatchTxFailed SwapStatus = 14
SwapInBlacklist SwapStatus = 15
ManualMakeFail SwapStatus = 16
TxWithWrongPath SwapStatus = 19
MissTokenConfig SwapStatus = 20
NoUnderlyingToken SwapStatus = 21
TxMaybeUnsafe SwapStatus = 22
SwapoutForbidden SwapStatus = 23
KeepStatus SwapStatus = 255
Reswapping SwapStatus = 256
)
// IsResultStatus is swap result status
func (status SwapStatus) IsResultStatus() bool {
switch status {
case MatchTxEmpty, MatchTxNotStable, MatchTxStable,
MatchTxFailed, Reswapping, ManualMakeFail,
SwapoutForbidden:
return true
default:
return false
}
}
// IsRegisteredOk is successfully registered
func (status SwapStatus) IsRegisteredOk() bool {
switch status {
case TxNotStable, TxNotSwapped, TxProcessed,
TxMaybeUnsafe, ManualMakeFail:
return true
default:
return false
}
}
// nolint:gocyclo // allow big simple switch
func (status SwapStatus) String() string {
switch status {
case TxNotStable:
return "TxNotStable"
case TxVerifyFailed:
return "TxVerifyFailed"
case TxWithWrongValue:
return "TxWithWrongValue"
case TxNotSwapped:
return "TxNotSwapped"
case TxProcessed:
return "TxProcessed"
case MatchTxEmpty:
return "MatchTxEmpty"
case MatchTxNotStable:
return "MatchTxNotStable"
case MatchTxStable:
return "MatchTxStable"
case TxWithBigValue:
return "TxWithBigValue"
case MatchTxFailed:
return "MatchTxFailed"
case SwapInBlacklist:
return "SwapInBlacklist"
case ManualMakeFail:
return "ManualMakeFail"
case TxWithWrongPath:
return "TxWithWrongPath"
case MissTokenConfig:
return "MissTokenConfig"
case NoUnderlyingToken:
return "NoUnderlyingToken"
case TxMaybeUnsafe:
return "TxMaybeUnsafe"
case SwapoutForbidden:
return "SwapoutForbidden"
case KeepStatus:
return "KeepStatus"
case Reswapping:
return "Reswapping"
default:
return fmt.Sprintf("unknown swap status %d", status)
}
}
// GetRouterSwapStatusByVerifyError get router swap status by verify error
func GetRouterSwapStatusByVerifyError(err error) SwapStatus {
if !tokens.ShouldRegisterRouterSwapForError(err) {
return TxVerifyFailed
}
switch {
case err == nil:
return TxNotStable
case errors.Is(err, tokens.ErrTxWithWrongValue):
return TxWithWrongValue
case errors.Is(err, tokens.ErrTxWithWrongPath):
return TxWithWrongPath
case errors.Is(err, tokens.ErrMissTokenConfig):
return MissTokenConfig
case errors.Is(err, tokens.ErrNoUnderlyingToken):
return NoUnderlyingToken
case errors.Is(err, tokens.ErrVerifyTxUnsafe):
return TxMaybeUnsafe
case errors.Is(err, tokens.ErrSwapoutForbidden):
return SwapoutForbidden
default:
return TxVerifyFailed
}
}