lotus/chain/types/blockmsg.go

39 lines
722 B
Go
Raw Normal View History

package types
2019-08-22 19:30:57 +00:00
import (
"bytes"
"fmt"
2019-08-22 19:30:57 +00:00
"github.com/ipfs/go-cid"
)
type BlockMsg struct {
Header *BlockHeader
2019-08-22 19:30:57 +00:00
BlsMessages []cid.Cid
SecpkMessages []cid.Cid
}
func DecodeBlockMsg(b []byte) (*BlockMsg, error) {
var bm BlockMsg
data := bytes.NewReader(b)
if err := bm.UnmarshalCBOR(data); err != nil {
2019-08-22 19:30:57 +00:00
return nil, err
}
if l := data.Len(); l != 0 {
return nil, fmt.Errorf("extraneous data in BlockMsg CBOR encoding: got %d unexpected bytes", l)
}
2019-08-22 19:30:57 +00:00
return &bm, nil
}
func (bm *BlockMsg) Cid() cid.Cid {
return bm.Header.Cid()
}
func (bm *BlockMsg) Serialize() ([]byte, error) {
buf := new(bytes.Buffer)
if err := bm.MarshalCBOR(buf); err != nil {
return nil, err
}
return buf.Bytes(), nil
}