OSDN Git Service

add query
[bytom/bytom.git] / types / proposal.go
1 package types
2
3 import (
4         "errors"
5         "fmt"
6         "io"
7
8         //. "github.com/tendermint/tmlibs/common"
9         "github.com/tendermint/go-crypto"
10         "github.com/tendermint/go-wire"
11 )
12
13 var (
14         ErrInvalidBlockPartSignature = errors.New("Error invalid block part signature")
15         ErrInvalidBlockPartHash      = errors.New("Error invalid block part hash")
16 )
17
18 type Proposal struct {
19         Height           int              `json:"height"`
20         Round            int              `json:"round"`
21         BlockPartsHeader PartSetHeader    `json:"block_parts_header"`
22         POLRound         int              `json:"pol_round"`    // -1 if null.
23         POLBlockID       BlockID          `json:"pol_block_id"` // zero if null.
24         Signature        crypto.Signature `json:"signature"`
25 }
26
27 // polRound: -1 if no polRound.
28 func NewProposal(height int, round int, blockPartsHeader PartSetHeader, polRound int, polBlockID BlockID) *Proposal {
29         return &Proposal{
30                 Height:           height,
31                 Round:            round,
32                 BlockPartsHeader: blockPartsHeader,
33                 POLRound:         polRound,
34                 POLBlockID:       polBlockID,
35         }
36 }
37
38 func (p *Proposal) String() string {
39         return fmt.Sprintf("Proposal{%v/%v %v (%v,%v) %v}", p.Height, p.Round,
40                 p.BlockPartsHeader, p.POLRound, p.POLBlockID, p.Signature)
41 }
42
43 func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) {
44         wire.WriteJSON(CanonicalJSONOnceProposal{
45                 ChainID:  chainID,
46                 Proposal: CanonicalProposal(p),
47         }, w, n, err)
48 }