lotus/chain/types/signedmessage.go
Steven Allen 5733c71c50 Lint everything
We were ignoring quite a few error cases, and had one case where we weren't
actually updating state where we wanted to. Unfortunately, if the linter doesn't
pass, nobody has any reason to actually check lint failures in CI.

There are three remaining XXXs marked in the code for lint.
2020-08-20 20:46:36 -07:00

86 lines
1.5 KiB
Go

package types
import (
"bytes"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/crypto"
block "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
)
func (sm *SignedMessage) ToStorageBlock() (block.Block, error) {
if sm.Signature.Type == crypto.SigTypeBLS {
return sm.Message.ToStorageBlock()
}
data, err := sm.Serialize()
if err != nil {
return nil, err
}
c, err := abi.CidBuilder.Sum(data)
if err != nil {
return nil, err
}
return block.NewBlockWithCid(data, c)
}
func (sm *SignedMessage) Cid() cid.Cid {
if sm.Signature.Type == crypto.SigTypeBLS {
return sm.Message.Cid()
}
sb, err := sm.ToStorageBlock()
if err != nil {
panic(err)
}
return sb.Cid()
}
type SignedMessage struct {
Message Message
Signature crypto.Signature
}
func DecodeSignedMessage(data []byte) (*SignedMessage, error) {
var msg SignedMessage
if err := msg.UnmarshalCBOR(bytes.NewReader(data)); err != nil {
return nil, err
}
return &msg, nil
}
func (sm *SignedMessage) Serialize() ([]byte, error) {
buf := new(bytes.Buffer)
if err := sm.MarshalCBOR(buf); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
func (sm *SignedMessage) ChainLength() int {
ser, err := sm.Serialize()
if err != nil {
panic(err)
}
return len(ser)
}
func (sm *SignedMessage) Size() int {
serdata, err := sm.Serialize()
if err != nil {
log.Errorf("serializing message failed: %s", err)
return 0
}
return len(serdata)
}
func (sm *SignedMessage) VMMessage() *Message {
return &sm.Message
}