-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
event.go
168 lines (154 loc) · 5.25 KB
/
event.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
package relayer
import (
"context"
"math/big"
"net/http"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/morkid/paginate"
"gorm.io/datatypes"
)
var (
EventNameMessageSent = "MessageSent"
EventNameMessageStatusChanged = "MessageStatusChanged"
EventNameMessageProcessed = "MessageProcessed"
EventNameChainDataSynced = "ChainDataSynced"
)
// EventStatus is used to indicate whether processing has been attempted
// for this particular event, and it's success
type EventStatus int
const (
EventStatusNew EventStatus = iota
EventStatusRetriable
EventStatusDone
EventStatusFailed
EventStatusRecalled
)
type EventType int
const (
EventTypeSendETH EventType = iota
EventTypeSendERC20
EventTypeSendERC721
EventTypeSendERC1155
)
// String returns string representation of an event status for logging
func (e EventStatus) String() string {
return [...]string{"new", "retriable", "done", "failed", "recalled"}[e]
}
func (e EventType) String() string {
return [...]string{"sendETH", "sendERC20", "sendERC721", "sendERC1155"}[e]
}
// Event represents a stored EVM event. The fields will be serialized
// into the Data field to be unmarshalled into a concrete struct
// dependant on the name of the event
type Event struct {
ID int `json:"id"`
Name string `json:"name"`
Data datatypes.JSON `json:"data"`
Status EventStatus `json:"status"`
EventType EventType `json:"eventType"`
ChainID int64 `json:"chainID"`
DestChainID int64 `json:"destChainID"`
SyncedChainID uint64 `json:"syncedChainID"`
EmittedBlockID uint64 `json:"emittedBlockID"`
BlockID uint64 `json:"blockID"`
SyncedInBlockID uint64 `json:"syncedInBlockID"`
SyncData string `json:"syncData"`
Kind string `json:"kind"`
CanonicalTokenAddress string `json:"canonicalTokenAddress"`
CanonicalTokenSymbol string `json:"canonicalTokenSymbol"`
CanonicalTokenName string `json:"canonicalTokenName"`
CanonicalTokenDecimals uint8 `json:"canonicalTokenDecimals"`
Amount string `json:"amount"`
MsgHash string `json:"msgHash"`
MessageOwner string `json:"messageOwner"`
Event string `json:"event"`
ClaimedBy string `json:"claimedBy" gorm:"-"`
ProcessedTxHash string `json:"processedTxHash" gorm:"-"`
Fee *uint64 `json:"fee"`
DestChainBaseFee *uint64 `json:"destChainBaseFee"`
GasTipCap *uint64 `json:"gasTipCap"`
GasLimit *uint64 `json:"gasLimit"`
IsProfitable *bool `json:"isProfitable"`
EstimatedOnchainFee *uint64 `json:"estimatedOnchainFee"`
IsProfitableEvaluatedAt *time.Time `json:"isProfitableEvaluatedAt"`
}
// SaveEventOpts
type SaveEventOpts struct {
Name string
Data string
ChainID *big.Int
DestChainID *big.Int
Status EventStatus
EventType EventType
CanonicalTokenAddress string
CanonicalTokenSymbol string
CanonicalTokenName string
CanonicalTokenDecimals uint8
Amount string
MsgHash string
MessageOwner string
Event string
SyncedChainID uint64
BlockID uint64
EmittedBlockID uint64
SyncData string
Kind string
SyncedInBlockID uint64
}
type UpdateFeesAndProfitabilityOpts struct {
Fee uint64
DestChainBaseFee uint64
GasTipCap uint64
GasLimit uint64
IsProfitable bool
EstimatedOnchainFee uint64
IsProfitableEvaluatedAt time.Time
}
type FindAllByAddressOpts struct {
Address common.Address
EventType *EventType
Event *string
MsgHash *string
ChainID *big.Int
}
// EventRepository is used to interact with events in the store
type EventRepository interface {
Close() error
Save(ctx context.Context, opts *SaveEventOpts) (*Event, error)
UpdateStatus(ctx context.Context, id int, status EventStatus) error
UpdateFeesAndProfitability(ctx context.Context, id int, opts *UpdateFeesAndProfitabilityOpts) error
FindAllByAddress(
ctx context.Context,
req *http.Request,
opts FindAllByAddressOpts,
) (*paginate.Page, error)
FirstByMsgHash(
ctx context.Context,
msgHash string,
) (*Event, error)
FirstByEventAndMsgHash(
ctx context.Context,
event string,
msgHash string,
) (*Event, error)
Delete(ctx context.Context, id int) error
ChainDataSyncedEventByBlockNumberOrGreater(
ctx context.Context,
srcChainId uint64,
syncedChainId uint64,
blockNumber uint64,
) (*Event, error)
LatestChainDataSyncedEvent(
ctx context.Context,
srcChainId uint64,
syncedChainId uint64,
) (uint64, error)
DeleteAllAfterBlockID(blockID uint64, srcChainID uint64, destChainID uint64) error
FindLatestBlockID(
ctx context.Context,
event string,
srcChainID uint64,
destChainID uint64,
) (uint64, error)
}