2019-07-25 22:15:03 +00:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
2019-08-21 17:15:28 +00:00
|
|
|
"bytes"
|
2019-08-15 02:30:21 +00:00
|
|
|
|
2019-07-25 22:15:03 +00:00
|
|
|
block "github.com/ipfs/go-block-format"
|
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
"github.com/multiformats/go-multihash"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-lotus/chain/address"
|
|
|
|
)
|
|
|
|
|
2019-08-15 02:30:21 +00:00
|
|
|
type Ticket struct {
|
|
|
|
VRFProof []byte
|
|
|
|
VDFResult []byte
|
|
|
|
VDFProof []byte
|
2019-07-25 22:15:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ElectionProof []byte
|
|
|
|
|
|
|
|
type BlockHeader struct {
|
|
|
|
Miner address.Address
|
|
|
|
|
2019-08-15 02:30:21 +00:00
|
|
|
Tickets []*Ticket
|
2019-07-25 22:15:03 +00:00
|
|
|
|
|
|
|
ElectionProof []byte
|
|
|
|
|
|
|
|
Parents []cid.Cid
|
|
|
|
|
|
|
|
ParentWeight BigInt
|
|
|
|
|
|
|
|
Height uint64
|
|
|
|
|
|
|
|
StateRoot cid.Cid
|
|
|
|
|
|
|
|
Messages cid.Cid
|
|
|
|
|
|
|
|
BLSAggregate Signature
|
|
|
|
|
|
|
|
MessageReceipts cid.Cid
|
|
|
|
}
|
|
|
|
|
2019-08-01 20:40:47 +00:00
|
|
|
type MsgMeta struct {
|
|
|
|
BlsMessages cid.Cid
|
|
|
|
SecpkMessages cid.Cid
|
|
|
|
}
|
|
|
|
|
2019-07-25 22:15:03 +00:00
|
|
|
func (b *BlockHeader) ToStorageBlock() (block.Block, error) {
|
|
|
|
data, err := b.Serialize()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-08-21 17:15:28 +00:00
|
|
|
pref := cid.NewPrefixV1(cid.DagCBOR, multihash.BLAKE2B_MIN+31)
|
2019-07-25 22:15:03 +00:00
|
|
|
c, err := pref.Sum(data)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return block.NewBlockWithCid(data, c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *BlockHeader) Cid() cid.Cid {
|
|
|
|
sb, err := b.ToStorageBlock()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return sb.Cid()
|
|
|
|
}
|
|
|
|
|
|
|
|
func DecodeBlock(b []byte) (*BlockHeader, error) {
|
|
|
|
var blk BlockHeader
|
2019-08-21 17:15:28 +00:00
|
|
|
if err := blk.UnmarshalCBOR(bytes.NewReader(b)); err != nil {
|
2019-07-25 22:15:03 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &blk, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (blk *BlockHeader) Serialize() ([]byte, error) {
|
2019-08-21 17:15:28 +00:00
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
if err := blk.MarshalCBOR(buf); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
func (blk *BlockHeader) MarshalCBOR(w io.Writer) error {
|
|
|
|
panic("no")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (blk *BlockHeader) UnmarshalCBOR(r io.Reader) error {
|
|
|
|
panic("no")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (blk *Message) MarshalCBOR(w io.Writer) error {
|
|
|
|
panic("no")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (blk *Message) UnmarshalCBOR(r io.Reader) error {
|
|
|
|
panic("no")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (blk *SignedMessage) MarshalCBOR(w io.Writer) error {
|
|
|
|
panic("no")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (blk *SignedMessage) UnmarshalCBOR(r io.Reader) error {
|
|
|
|
panic("no")
|
2019-07-25 22:15:03 +00:00
|
|
|
}
|
2019-08-21 17:15:28 +00:00
|
|
|
*/
|