tendermint/types/proposal.go

73 lines
2.1 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"
2016-11-16 15:20:44 -08:00
//. "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 {
2016-11-16 15:20:44 -08:00
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"`
2014-09-14 15:37:32 -07:00
}
2015-12-01 20:12:01 -08:00
// polRound: -1 if no polRound.
func NewProposal(height int, round int, blockPartsHeader PartSetHeader, polRound int, polBlockID BlockID) *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,
POLBlockID: polBlockID,
2014-09-14 15:37:32 -07:00
}
}
2014-10-25 14:27:53 -07:00
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)
2014-10-25 14:27:53 -07:00
}
2015-11-10 13:10:43 -08:00
func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) {
2016-11-16 15:20:44 -08:00
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)
}