2015-08-10 20:38:45 -07:00
|
|
|
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 17:20:44 -06:00
|
|
|
//. "github.com/tendermint/go-common"
|
2015-11-01 11:34:08 -08:00
|
|
|
"github.com/tendermint/go-crypto"
|
2015-10-22 17:39:06 -07:00
|
|
|
"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 17:20:44 -06: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.
|
2016-08-20 15:08:26 -07:00
|
|
|
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,
|
2016-08-20 15:08:26 -07:00
|
|
|
POLBlockID: polBlockID,
|
2014-09-14 15:37:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-25 14:27:53 -07:00
|
|
|
func (p *Proposal) String() string {
|
2016-08-20 15:08:26 -07:00
|
|
|
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
|
|
|
}
|
2014-12-09 18:49:04 -08: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 17:20:44 -06: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)
|
2014-12-09 18:49:04 -08:00
|
|
|
}
|