sign bytes w struct literals

This commit is contained in:
zachary balder
2016-11-16 17:20:44 -06:00
committed by Ethan Buchman
parent ed42f70248
commit da8b043612
3 changed files with 78 additions and 19 deletions

View File

@ -74,7 +74,15 @@ func (psh PartSetHeader) Equals(other PartSetHeader) bool {
} }
func (psh PartSetHeader) WriteSignBytes(w io.Writer, n *int, err *error) { func (psh PartSetHeader) WriteSignBytes(w io.Writer, n *int, err *error) {
wire.WriteTo([]byte(Fmt(`{"hash":"%X","total":%v}`, psh.Hash, psh.Total)), w, n, err) wire.WriteJSON(
struct {
Hash []byte `json:"hash"`
Total int `json:"total"`
}{
psh.Hash,
psh.Total,
},
w, n, err)
} }
//------------------------------------- //-------------------------------------

View File

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"io" "io"
. "github.com/tendermint/go-common" //. "github.com/tendermint/go-common"
"github.com/tendermint/go-crypto" "github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire" "github.com/tendermint/go-wire"
) )
@ -16,12 +16,12 @@ var (
) )
type Proposal struct { type Proposal struct {
Height int `json:"height"` Height int `json:"height"`
Round int `json:"round"` Round int `json:"round"`
BlockPartsHeader PartSetHeader `json:"block_parts_header"` BlockPartsHeader PartSetHeader `json:"block_parts_header"`
POLRound int `json:"pol_round"` // -1 if null. POLRound int `json:"pol_round"` // -1 if null.
POLBlockID BlockID `json:"pol_block_id"` // zero if null. POLBlockID BlockID `json:"pol_block_id"` // zero if null.
Signature crypto.SignatureEd25519 `json:"signature"` Signature crypto.Signature `json:"signature"`
} }
// polRound: -1 if no polRound. // polRound: -1 if no polRound.
@ -41,11 +41,32 @@ func (p *Proposal) String() string {
} }
func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) { func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) {
wire.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
wire.WriteTo([]byte(`,"proposal":{"block_parts_header":`), w, n, err) wire.WriteJSON(
p.BlockPartsHeader.WriteSignBytes(w, n, err) struct {
wire.WriteTo([]byte(Fmt(`,"height":%v,"pol_block_id":`, p.Height)), w, n, err) ChainID string `json:"chain_id"`
p.POLBlockID.WriteSignBytes(w, n, err) Proposal struct {
wire.WriteTo([]byte(Fmt(`,"pol_round":%v`, p.POLRound)), w, n, err) BlockPartsHeader PartSetHeader `json:"block_parts_header"`
wire.WriteTo([]byte(Fmt(`,"round":%v}}`, p.Round)), w, n, err) 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)
} }

View File

@ -57,10 +57,40 @@ type Vote struct {
} }
func (vote *Vote) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) { func (vote *Vote) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) {
wire.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
wire.WriteTo([]byte(`,"vote":{"block_id":`), w, n, err) wire.WriteJSON(
vote.BlockID.WriteSignBytes(w, n, err) struct {
wire.WriteTo([]byte(Fmt(`,"height":%v,"round":%v,"type":%v}}`, vote.Height, vote.Round, vote.Type)), w, n, err) ChainID string `json:"chain_id"`
Vote struct {
BlockID BlockID `json:"block_id"`
Height int `json:"height"`
Round int `json:"round"`
Signature crypto.Signature `json:"signature"`
Type byte `json:"type"`
ValidatorAddress []byte `json:"validator_address"`
ValidatorIndex int `json:"validator_index"`
} `json: "vote"`
}{
chainID,
struct {
BlockID BlockID `json:"block_id"`
Height int `json:"height"`
Round int `json:"round"`
Signature crypto.Signature `json:"signature"`
Type byte `json:"type"`
ValidatorAddress []byte `json:"validator_address"`
ValidatorIndex int `json:"validator_index"`
}{
vote.BlockID,
vote.Height,
vote.Round,
vote.Signature,
vote.Type,
vote.ValidatorAddress,
vote.ValidatorIndex,
},
},
w, n, err)
} }
func (vote *Vote) Copy() *Vote { func (vote *Vote) Copy() *Vote {