2014-09-14 15:37:32 -07:00
|
|
|
package consensus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2014-10-25 14:27:53 -07:00
|
|
|
"fmt"
|
2014-09-14 15:37:32 -07:00
|
|
|
"io"
|
|
|
|
|
2015-04-01 17:30:16 -07:00
|
|
|
"github.com/tendermint/tendermint/account"
|
|
|
|
"github.com/tendermint/tendermint/binary"
|
2015-04-27 20:55:28 -07:00
|
|
|
. "github.com/tendermint/tendermint/common"
|
2015-04-01 17:30:16 -07:00
|
|
|
"github.com/tendermint/tendermint/types"
|
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-05-01 17:26:49 -07:00
|
|
|
Height uint `json:"height"`
|
|
|
|
Round uint `json:"round"`
|
|
|
|
BlockParts types.PartSetHeader `json:"block_parts"`
|
|
|
|
POLParts types.PartSetHeader `json:"pol_parts"`
|
|
|
|
Signature account.SignatureEd25519 `json:"signature"`
|
2014-09-14 15:37:32 -07:00
|
|
|
}
|
|
|
|
|
2015-03-22 19:00:08 -07:00
|
|
|
func NewProposal(height uint, round uint, blockParts, polParts types.PartSetHeader) *Proposal {
|
2014-09-14 15:37:32 -07:00
|
|
|
return &Proposal{
|
2014-10-30 03:32:09 -07:00
|
|
|
Height: height,
|
|
|
|
Round: round,
|
|
|
|
BlockParts: blockParts,
|
|
|
|
POLParts: polParts,
|
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,
|
|
|
|
p.BlockParts, p.POLParts, p.Signature)
|
2014-10-25 14:27:53 -07:00
|
|
|
}
|
2014-12-09 18:49:04 -08:00
|
|
|
|
|
|
|
func (p *Proposal) WriteSignBytes(w io.Writer, n *int64, err *error) {
|
2015-05-29 14:13:45 -04:00
|
|
|
// We hex encode the chain_id name so we don't deal with escaping issues.
|
|
|
|
binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, config.GetString("chain_id"))), w, n, err)
|
2015-05-01 17:26:49 -07:00
|
|
|
binary.WriteTo([]byte(`,"proposal":{"block_parts":`), w, n, err)
|
2015-04-27 20:55:28 -07:00
|
|
|
p.BlockParts.WriteSignBytes(w, n, err)
|
2015-05-01 17:26:49 -07:00
|
|
|
binary.WriteTo([]byte(Fmt(`,"height":%v,"pol_parts":`, p.Height)), w, n, err)
|
2015-04-27 20:55:28 -07:00
|
|
|
p.POLParts.WriteSignBytes(w, n, err)
|
2015-05-01 17:26:49 -07:00
|
|
|
binary.WriteTo([]byte(Fmt(`,"round":%v}}`, p.Round)), w, n, err)
|
2014-12-09 18:49:04 -08:00
|
|
|
}
|