-
Notifications
You must be signed in to change notification settings - Fork 204
/
common.go
70 lines (57 loc) · 1.55 KB
/
common.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 dataRetriever
import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-go/process/factory"
)
// SetEpochHandlerToHdrResolver sets the epoch handler to the metablock hdr resolver
func SetEpochHandlerToHdrResolver(
resolversContainer ResolversContainer,
epochHandler EpochHandler,
) error {
resolver, err := resolversContainer.Get(factory.MetachainBlocksTopic)
if err != nil {
return err
}
hdrResolver, ok := resolver.(HeaderResolver)
if !ok {
return ErrWrongTypeInContainer
}
err = hdrResolver.SetEpochHandler(epochHandler)
if err != nil {
return err
}
return nil
}
// SetEpochHandlerToHdrRequester sets the epoch handler to the metablock hdr requester
func SetEpochHandlerToHdrRequester(
requestersContainer RequestersContainer,
epochHandler EpochHandler,
) error {
requester, err := requestersContainer.Get(factory.MetachainBlocksTopic)
if err != nil {
return err
}
hdrRequester, ok := requester.(HeaderRequester)
if !ok {
return ErrWrongTypeInContainer
}
err = hdrRequester.SetEpochHandler(epochHandler)
if err != nil {
return err
}
return nil
}
// GetHdrNonceHashDataUnit gets the HdrNonceHashDataUnit by shard
func GetHdrNonceHashDataUnit(shard uint32) UnitType {
if shard == core.MetachainShardId {
return MetaHdrNonceHashDataUnit
}
return ShardHdrNonceHashDataUnit + UnitType(shard)
}
// GetHeadersDataUnit gets the unit for block headers, by shard
func GetHeadersDataUnit(shard uint32) UnitType {
if shard == core.MetachainShardId {
return MetaBlockUnit
}
return BlockHeaderUnit
}