-
Notifications
You must be signed in to change notification settings - Fork 175
/
chunkLocator.go
53 lines (43 loc) · 1.46 KB
/
chunkLocator.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
package chunks
import (
"github.com/onflow/flow-go/model/flow"
)
// Locator is used to locate a chunk by providing the execution result the chunk belongs to as well as the chunk index within that execution result.
// Since a chunk is unique by the result ID and its index in the result's chunk list.
type Locator struct {
ResultID flow.Identifier // execution result id that chunk belongs to
Index uint64 // index of chunk in the execution result
}
// ID returns a unique id for chunk locator.
func (c Locator) ID() flow.Identifier {
return flow.MakeID(c)
}
// Checksum provides a cryptographic commitment for a chunk locator content.
func (c Locator) Checksum() flow.Identifier {
return flow.MakeID(c)
}
// ChunkLocatorID is a util function that returns identifier of corresponding chunk locator to
// the specified result and chunk index.
func ChunkLocatorID(resultID flow.Identifier, chunkIndex uint64) flow.Identifier {
return Locator{
ResultID: resultID,
Index: chunkIndex,
}.ID()
}
// LocatorMap maps keeps chunk locators based on their locator id.
type LocatorMap map[flow.Identifier]*Locator
func (l LocatorMap) ToList() LocatorList {
locatorList := LocatorList{}
for _, locator := range l {
locatorList = append(locatorList, locator)
}
return locatorList
}
type LocatorList []*Locator
func (l LocatorList) ToMap() LocatorMap {
locatorMap := make(LocatorMap)
for _, locator := range l {
locatorMap[locator.ID()] = locator
}
return locatorMap
}