tendermint/types/proposal.go
2016-12-17 21:21:27 -05:00

73 lines
2.1 KiB
Go

package types
import (
"errors"
"fmt"
"io"
//. "github.com/tendermint/go-common"
"github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire"
)
var (
ErrInvalidBlockPartSignature = errors.New("Error invalid block part signature")
ErrInvalidBlockPartHash = errors.New("Error invalid block part hash")
)
type Proposal struct {
Height int `json:"height"`
Round int `json:"round"`
BlockPartsHeader PartSetHeader `json:"block_parts_header"`
POLRound int `json:"pol_round"` // -1 if null.
POLBlockID BlockID `json:"pol_block_id"` // zero if null.
Signature crypto.Signature `json:"signature"`
}
// polRound: -1 if no polRound.
func NewProposal(height int, round int, blockPartsHeader PartSetHeader, polRound int, polBlockID BlockID) *Proposal {
return &Proposal{
Height: height,
Round: round,
BlockPartsHeader: blockPartsHeader,
POLRound: polRound,
POLBlockID: polBlockID,
}
}
func (p *Proposal) String() string {
return fmt.Sprintf("Proposal{%v/%v %v (%v,%v) %v}", p.Height, p.Round,
p.BlockPartsHeader, p.POLRound, p.POLBlockID, p.Signature)
}
func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) {
wire.WriteJSON(
struct {
ChainID string `json:"chain_id"`
Proposal struct {
BlockPartsHeader PartSetHeader `json:"block_parts_header"`
Height int `json:"height"`
POLBlockID BlockID `json:"pol_block_id"`
POLRound int `json:"pol_round"`
Round int `json:"round"`
} `json:"proposal"`
}{
chainID,
struct {
BlockPartsHeader PartSetHeader `json:"block_parts_header"`
Height int `json:"height"`
POLBlockID BlockID `json:"pol_block_id"`
POLRound int `json:"pol_round"`
Round int `json:"round"`
}{
p.BlockPartsHeader,
p.Height,
p.POLBlockID,
p.POLRound,
p.Round,
},
},
w, n, err)
}