-
Notifications
You must be signed in to change notification settings - Fork 0
/
epochStartHandler.go
70 lines (56 loc) · 1.66 KB
/
epochStartHandler.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
package block
import (
"github.com/bhagyaraj1208117/andes-core-go/data"
)
// GetLastFinalizedHeaderHandlers returns the last finalized header handlers
func (es *EpochStart) GetLastFinalizedHeaderHandlers() []data.EpochStartShardDataHandler {
if es == nil {
return nil
}
epochStartShardDataHandlers := make([]data.EpochStartShardDataHandler, len(es.LastFinalizedHeaders))
for i := range es.LastFinalizedHeaders {
epochStartShardDataHandlers[i] = &es.LastFinalizedHeaders[i]
}
return epochStartShardDataHandlers
}
// GetEconomicsHandler returns the economics handler
func (es *EpochStart) GetEconomicsHandler() data.EconomicsHandler {
if es == nil {
return nil
}
return &es.Economics
}
// SetLastFinalizedHeaders sets the last finalized header
func (es *EpochStart) SetLastFinalizedHeaders(epochStartDataHandlers []data.EpochStartShardDataHandler) error {
if es == nil {
return data.ErrNilPointerReceiver
}
epochStartData := make([]EpochStartShardData, len(epochStartDataHandlers))
for i := range epochStartDataHandlers {
shardData, ok := epochStartDataHandlers[i].(*EpochStartShardData)
if !ok {
return data.ErrInvalidTypeAssertion
}
if shardData == nil {
return data.ErrNilPointerDereference
}
epochStartData[i] = *shardData
}
es.LastFinalizedHeaders = epochStartData
return nil
}
// SetEconomics sets the economics data
func (es *EpochStart) SetEconomics(economicsHandler data.EconomicsHandler) error {
if es == nil {
return data.ErrNilPointerReceiver
}
ec, ok := economicsHandler.(*Economics)
if !ok {
return data.ErrInvalidTypeAssertion
}
if ec == nil {
return data.ErrNilPointerDereference
}
es.Economics = *ec
return nil
}