/
task.go
157 lines (130 loc) · 4.05 KB
/
task.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
package eventhandler
import (
"github.com/attestantio/go-eth2-client/spec/phase0"
spectypes "github.com/bloxapp/ssv-spec/types"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/bloxapp/ssv/protocol/v2/types"
)
type Task interface {
Execute() error
}
type startValidatorExecutor interface {
StartValidator(share *types.SSVShare) error
}
type StartValidatorTask struct {
executor startValidatorExecutor
share *types.SSVShare
}
func NewStartValidatorTask(executor startValidatorExecutor, share *types.SSVShare) *StartValidatorTask {
return &StartValidatorTask{
executor: executor,
share: share,
}
}
func (t StartValidatorTask) Execute() error {
return t.executor.StartValidator(t.share)
}
type stopValidatorExecutor interface {
StopValidator(pubKey spectypes.ValidatorPK) error
}
type StopValidatorTask struct {
executor stopValidatorExecutor
pubKey spectypes.ValidatorPK
}
func NewStopValidatorTask(executor stopValidatorExecutor, pubKey spectypes.ValidatorPK) *StopValidatorTask {
return &StopValidatorTask{
executor: executor,
pubKey: pubKey,
}
}
func (t StopValidatorTask) Execute() error {
return t.executor.StopValidator(t.pubKey)
}
type liquidateClusterExecutor interface {
LiquidateCluster(owner ethcommon.Address, operatorIDs []spectypes.OperatorID, toLiquidate []*types.SSVShare) error
}
type LiquidateClusterTask struct {
executor liquidateClusterExecutor
owner ethcommon.Address
operatorIDs []spectypes.OperatorID
toLiquidate []*types.SSVShare
}
func NewLiquidateClusterTask(
executor liquidateClusterExecutor,
owner ethcommon.Address,
operatorIDs []spectypes.OperatorID,
toLiquidate []*types.SSVShare,
) *LiquidateClusterTask {
return &LiquidateClusterTask{
executor: executor,
owner: owner,
operatorIDs: operatorIDs,
toLiquidate: toLiquidate,
}
}
func (t LiquidateClusterTask) Execute() error {
return t.executor.LiquidateCluster(t.owner, t.operatorIDs, t.toLiquidate)
}
type reactivateClusterExecutor interface {
ReactivateCluster(owner ethcommon.Address, operatorIDs []spectypes.OperatorID, toReactivate []*types.SSVShare) error
}
type ReactivateClusterTask struct {
executor reactivateClusterExecutor
owner ethcommon.Address
operatorIDs []spectypes.OperatorID
toReactivate []*types.SSVShare
}
func NewReactivateClusterTask(
executor reactivateClusterExecutor,
owner ethcommon.Address,
operatorIDs []spectypes.OperatorID,
toReactivate []*types.SSVShare,
) *ReactivateClusterTask {
return &ReactivateClusterTask{
executor: executor,
owner: owner,
operatorIDs: operatorIDs,
toReactivate: toReactivate,
}
}
func (t ReactivateClusterTask) Execute() error {
return t.executor.ReactivateCluster(t.owner, t.operatorIDs, t.toReactivate)
}
type updateFeeRecipientExecutor interface {
UpdateFeeRecipient(owner, feeRecipient ethcommon.Address) error
}
type UpdateFeeRecipientTask struct {
executor updateFeeRecipientExecutor
owner ethcommon.Address
recipient ethcommon.Address
}
func NewUpdateFeeRecipientTask(executor updateFeeRecipientExecutor, owner, recipient ethcommon.Address) *UpdateFeeRecipientTask {
return &UpdateFeeRecipientTask{
executor: executor,
owner: owner,
recipient: recipient,
}
}
func (t UpdateFeeRecipientTask) Execute() error {
return t.executor.UpdateFeeRecipient(t.owner, t.recipient)
}
type exitValidatorExecutor interface {
ExitValidator(pubKey phase0.BLSPubKey, blockNumber uint64, validatorIndex phase0.ValidatorIndex) error
}
type ExitValidatorTask struct {
executor exitValidatorExecutor
pubKey phase0.BLSPubKey
blockNumber uint64
validatorIndex phase0.ValidatorIndex
}
func NewExitValidatorTask(executor exitValidatorExecutor, pubKey phase0.BLSPubKey, blockNumber uint64, validatorIndex phase0.ValidatorIndex) *ExitValidatorTask {
return &ExitValidatorTask{
executor: executor,
pubKey: pubKey,
blockNumber: blockNumber,
validatorIndex: validatorIndex,
}
}
func (t ExitValidatorTask) Execute() error {
return t.executor.ExitValidator(t.pubKey, t.blockNumber, t.validatorIndex)
}