forked from taikoxyz/taiko-mono
-
Notifications
You must be signed in to change notification settings - Fork 1
/
event.go
110 lines (97 loc) · 3.03 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
package relayer
import (
"context"
"math/big"
"net/http"
"github.com/ethereum/go-ethereum/common"
"github.com/morkid/paginate"
"gorm.io/datatypes"
)
var (
EventNameMessageSent = "MessageSent"
EventNameMessageStatusChanged = "MessageStatusChanged"
)
// 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
EventStatusNewOnlyOwner
)
type EventType int
const (
EventTypeSendETH EventType = iota
EventTypeSendERC20
)
// String returns string representation of an event status for logging
func (e EventStatus) String() string {
return [...]string{"new", "retriable", "done", "failed", "onlyOwner"}[e]
}
func (e EventType) String() string {
return [...]string{"sendETH", "sendERC20"}[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"`
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"`
}
// SaveEventOpts
type SaveEventOpts struct {
Name string
Data string
ChainID *big.Int
Status EventStatus
EventType EventType
CanonicalTokenAddress string
CanonicalTokenSymbol string
CanonicalTokenName string
CanonicalTokenDecimals uint8
Amount string
MsgHash string
MessageOwner string
Event string
}
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 {
Save(ctx context.Context, opts SaveEventOpts) (*Event, error)
UpdateStatus(ctx context.Context, id int, status EventStatus) 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
}