-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
fts.go
55 lines (44 loc) · 1.01 KB
/
fts.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
package store
import (
"github.com/ipfs/go-cid"
"github.com/filecoin-project/lotus/chain/types"
)
// FullTipSet is an expanded version of the TipSet that contains all the blocks and messages
type FullTipSet struct {
Blocks []*types.FullBlock
tipset *types.TipSet
cids []cid.Cid
}
func NewFullTipSet(blks []*types.FullBlock) *FullTipSet {
return &FullTipSet{
Blocks: blks,
}
}
func (fts *FullTipSet) Cids() []cid.Cid {
if fts.cids != nil {
return fts.cids
}
var cids []cid.Cid
for _, b := range fts.Blocks {
cids = append(cids, b.Cid())
}
fts.cids = cids
return cids
}
// TipSet returns a narrower view of this FullTipSet elliding the block
// messages.
func (fts *FullTipSet) TipSet() *types.TipSet {
if fts.tipset != nil {
// FIXME: fts.tipset is actually never set. Should it memoize?
return fts.tipset
}
var headers []*types.BlockHeader
for _, b := range fts.Blocks {
headers = append(headers, b.Header)
}
ts, err := types.NewTipSet(headers)
if err != nil {
panic(err)
}
return ts
}