-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathevent.go
131 lines (123 loc) · 3.97 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
package eventindexer
import (
"context"
"database/sql"
"math/big"
"net/http"
"time"
"github.com/morkid/paginate"
"github.com/shopspring/decimal"
"gorm.io/datatypes"
)
var (
EventNameTransitionProved = "TransitionProved"
EventNameTransitionContested = "TransitionContested"
EventNameBlockProposed = "BlockProposed"
EventNameBatchProposed = "BatchProposed"
EventNameBatchesProven = "BatchesProved"
EventNameBatchesVerified = "BatchesVerified"
EventNameBlockAssigned = "BlockAssigned"
EventNameBlockVerified = "BlockVerified"
EventNameMessageSent = "MessageSent"
EventNameSwap = "Swap"
EventNameMint = "Mint"
EventNameNFTTransfer = "Transfer"
EventNameInstanceAdded = "InstanceAdded"
)
// 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"`
ChainID int64 `json:"chainID"`
Event string `json:"event"`
Address string `json:"address"`
BlockID sql.NullInt64 `json:"blockID"`
Amount decimal.NullDecimal `json:"amount"`
ProofReward decimal.NullDecimal `json:"proofReward"`
ProposerReward decimal.NullDecimal `json:"proposerReward"`
AssignedProver string `json:"assignedProver"`
To string `json:"to"`
TokenID sql.NullInt64 `json:"tokenID"`
ContractAddress string `json:"contractAddress"`
FeeTokenAddress string `json:"feeTokenAddress"`
TransactedAt time.Time `json:"transactedAt"`
Tier sql.NullInt16 `json:"tier"`
EmittedBlockID uint64 `json:"emittedBlockID"`
NumBlocks sql.NullInt64 `json:"numBlocks"`
BatchID sql.NullInt64 `json:"batchID"`
}
// SaveEventOpts
type SaveEventOpts struct {
Name string
Data string
ChainID *big.Int
Event string
Address string
BlockID *int64
Amount *big.Int
ProposerReward *big.Int
ProofReward *big.Int
AssignedProver *string
To *string
TokenID *int64
ContractAddress *string
FeeTokenAddress *string
TransactedAt time.Time
Tier *uint16
EmittedBlockID uint64
NumBlocks *int64
BatchID *int64
}
type UniqueProversResponse struct {
Address string `json:"address"`
Count int `json:"count"`
}
type UniqueProposersResponse struct {
Address string `json:"address"`
Count int `json:"count"`
}
// EventRepository is used to interact with events in the store
type EventRepository interface {
Save(ctx context.Context, opts SaveEventOpts) (*Event, error)
FindUniqueProvers(
ctx context.Context,
) ([]UniqueProversResponse, error)
FindUniqueProposers(
ctx context.Context,
) ([]UniqueProposersResponse, error)
FindByEventTypeAndBlockID(
ctx context.Context,
eventType string,
blockID int64) (*Event, error)
Delete(
ctx context.Context,
id int,
) error
GetCountByAddressAndEventName(ctx context.Context, address string, event string) (int, error)
GetByAddressAndEventName(
ctx context.Context,
req *http.Request,
address string,
event string,
) (paginate.Page, error)
FirstByAddressAndEventName(
ctx context.Context,
address string,
event string,
) (*Event, error)
GetAssignedBlocksByProverAddress(
ctx context.Context,
req *http.Request,
address string,
) (paginate.Page, error)
DeleteAllAfterBlockID(ctx context.Context, blockID uint64, srcChainID uint64) error
FindLatestBlockID(
ctx context.Context,
srcChainID uint64,
) (uint64, error)
GetBlockProvenBy(ctx context.Context, blockID int) ([]*Event, error)
GetBlockProposedBy(ctx context.Context, blockID int) (*Event, error)
}