2019-07-26 04:54:22 +00:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2019-07-26 04:54:22 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fts *FullTipSet) TipSet() *types.TipSet {
|
|
|
|
if fts.tipset != nil {
|
|
|
|
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
|
|
|
|
}
|