tendermint/types/proposal.go

47 lines
1.5 KiB
Go
Raw Normal View History

package types
2014-09-14 15:37:32 -07:00
import (
"errors"
2014-10-25 14:27:53 -07:00
"fmt"
2014-09-14 15:37:32 -07:00
"io"
. "github.com/tendermint/go-common"
2015-11-01 11:34:08 -08:00
"github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire"
2014-09-14 15:37:32 -07:00
)
var (
ErrInvalidBlockPartSignature = errors.New("Error invalid block part signature")
ErrInvalidBlockPartHash = errors.New("Error invalid block part hash")
)
type Proposal struct {
2015-11-01 11:34:08 -08:00
Height int `json:"height"`
Round int `json:"round"`
BlockPartsHeader PartSetHeader `json:"block_parts_header"`
POLRound int `json:"pol_round"` // -1 if null.
Signature crypto.SignatureEd25519 `json:"signature"`
2014-09-14 15:37:32 -07:00
}
func NewProposal(height int, round int, blockPartsHeader PartSetHeader, polRound int) *Proposal {
2014-09-14 15:37:32 -07:00
return &Proposal{
2015-06-22 19:04:31 -07:00
Height: height,
Round: round,
BlockPartsHeader: blockPartsHeader,
POLRound: polRound,
2014-09-14 15:37:32 -07:00
}
}
2014-10-25 14:27:53 -07:00
func (p *Proposal) String() string {
2014-10-30 03:32:09 -07:00
return fmt.Sprintf("Proposal{%v/%v %v %v %v}", p.Height, p.Round,
2015-06-22 19:04:31 -07:00
p.BlockPartsHeader, p.POLRound, p.Signature)
2014-10-25 14:27:53 -07:00
}
2015-05-29 14:53:57 -07:00
func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
2015-07-25 15:45:45 -07:00
wire.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
wire.WriteTo([]byte(`,"proposal":{"block_parts_header":`), w, n, err)
2015-06-22 19:04:31 -07:00
p.BlockPartsHeader.WriteSignBytes(w, n, err)
2015-07-25 15:45:45 -07:00
wire.WriteTo([]byte(Fmt(`,"height":%v,"pol_round":%v`, p.Height, p.POLRound)), w, n, err)
wire.WriteTo([]byte(Fmt(`,"round":%v}}`, p.Round)), w, n, err)
}