-
Notifications
You must be signed in to change notification settings - Fork 197
/
epochStartNotifierStub.go
65 lines (54 loc) · 1.72 KB
/
epochStartNotifierStub.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
package mock
import (
"github.com/ElrondNetwork/elrond-go-core/data"
"github.com/ElrondNetwork/elrond-go/epochStart"
)
// EpochStartNotifierStub -
type EpochStartNotifierStub struct {
RegisterHandlerCalled func(handler epochStart.ActionHandler)
UnregisterHandlerCalled func(handler epochStart.ActionHandler)
NotifyAllCalled func(hdr data.HeaderHandler)
NotifyAllPrepareCalled func(hdr data.HeaderHandler, body data.BodyHandler)
epochStartHdls []epochStart.ActionHandler
}
// RegisterHandler -
func (esnm *EpochStartNotifierStub) RegisterHandler(handler epochStart.ActionHandler) {
if esnm.RegisterHandlerCalled != nil {
esnm.RegisterHandlerCalled(handler)
}
esnm.epochStartHdls = append(esnm.epochStartHdls, handler)
}
// UnregisterHandler -
func (esnm *EpochStartNotifierStub) UnregisterHandler(handler epochStart.ActionHandler) {
if esnm.UnregisterHandlerCalled != nil {
esnm.UnregisterHandlerCalled(handler)
}
for i, hdl := range esnm.epochStartHdls {
if hdl == handler {
esnm.epochStartHdls = append(esnm.epochStartHdls[:i], esnm.epochStartHdls[i+1:]...)
break
}
}
}
// NotifyAllPrepare -
func (esnm *EpochStartNotifierStub) NotifyAllPrepare(metaHdr data.HeaderHandler, body data.BodyHandler) {
if esnm.NotifyAllPrepareCalled != nil {
esnm.NotifyAllPrepareCalled(metaHdr, body)
}
for _, hdl := range esnm.epochStartHdls {
hdl.EpochStartPrepare(metaHdr, body)
}
}
// NotifyAll -
func (esnm *EpochStartNotifierStub) NotifyAll(hdr data.HeaderHandler) {
if esnm.NotifyAllCalled != nil {
esnm.NotifyAllCalled(hdr)
}
for _, hdl := range esnm.epochStartHdls {
hdl.EpochStartAction(hdr)
}
}
// IsInterfaceNil -
func (esnm *EpochStartNotifierStub) IsInterfaceNil() bool {
return esnm == nil
}