mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-15 06:11:20 +00:00
sign bytes w struct literals
This commit is contained in:
committed by
Ethan Buchman
parent
ed42f70248
commit
da8b043612
@ -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)
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
@ -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"
|
||||
)
|
||||
@ -21,7 +21,7 @@ type Proposal struct {
|
||||
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"`
|
||||
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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user