Browse Source

sign bytes w struct literals

pull/325/head
zachary balder 8 years ago
committed by Ethan Buchman
parent
commit
da8b043612
3 changed files with 78 additions and 19 deletions
  1. +9
    -1
      types/part_set.go
  2. +35
    -14
      types/proposal.go
  3. +34
    -4
      types/vote.go

+ 9
- 1
types/part_set.go View File

@ -74,7 +74,15 @@ func (psh PartSetHeader) Equals(other PartSetHeader) bool {
}
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)
}
//-------------------------------------


+ 35
- 14
types/proposal.go View File

@ -5,7 +5,7 @@ import (
"fmt"
"io"
. "github.com/tendermint/go-common"
//. "github.com/tendermint/go-common"
"github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire"
)
@ -16,12 +16,12 @@ var (
)
type Proposal struct {
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.SignatureEd25519 `json:"signature"`
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"`
}
// 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) {
wire.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
wire.WriteTo([]byte(`,"proposal":{"block_parts_header":`), w, n, err)
p.BlockPartsHeader.WriteSignBytes(w, n, err)
wire.WriteTo([]byte(Fmt(`,"height":%v,"pol_block_id":`, p.Height)), w, n, err)
p.POLBlockID.WriteSignBytes(w, n, err)
wire.WriteTo([]byte(Fmt(`,"pol_round":%v`, p.POLRound)), w, n, err)
wire.WriteTo([]byte(Fmt(`,"round":%v}}`, p.Round)), w, n, err)
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)
}

+ 34
- 4
types/vote.go View File

@ -57,10 +57,40 @@ type Vote struct {
}
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)
vote.BlockID.WriteSignBytes(w, n, err)
wire.WriteTo([]byte(Fmt(`,"height":%v,"round":%v,"type":%v}}`, vote.Height, vote.Round, vote.Type)), w, n, err)
wire.WriteJSON(
struct {
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 {


Loading…
Cancel
Save