mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-15 06:11:20 +00:00
Proposal WriteSignBytes is JSON
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
"github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
@ -39,9 +40,11 @@ func (p *Proposal) String() string {
|
||||
}
|
||||
|
||||
func (p *Proposal) WriteSignBytes(w io.Writer, n *int64, err *error) {
|
||||
binary.WriteString(config.App().GetString("Network"), w, n, err)
|
||||
binary.WriteUvarint(p.Height, w, n, err)
|
||||
binary.WriteUvarint(p.Round, w, n, err)
|
||||
binary.WriteBinary(p.BlockParts, w, n, err)
|
||||
binary.WriteBinary(p.POLParts, w, n, err)
|
||||
// We hex encode the network name so we don't deal with escaping issues.
|
||||
binary.WriteTo([]byte(Fmt(`{"Network":"%X"`, config.App().GetString("Network"))), w, n, err)
|
||||
binary.WriteTo([]byte(`,"Proprosal":{"BlockParts":`), w, n, err)
|
||||
p.BlockParts.WriteSignBytes(w, n, err)
|
||||
binary.WriteTo([]byte(Fmt(`,"Height":%v,"POLParts":`, p.Height)), w, n, err)
|
||||
p.POLParts.WriteSignBytes(w, n, err)
|
||||
binary.WriteTo([]byte(Fmt(`,"Round":%v}}`, p.Round)), w, n, err)
|
||||
}
|
||||
|
27
consensus/types/proposal_test.go
Normal file
27
consensus/types/proposal_test.go
Normal file
@ -0,0 +1,27 @@
|
||||
package consensus
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/tendermint/tendermint/account"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
"github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
func TestProposalSignable(t *testing.T) {
|
||||
proposal := &Proposal{
|
||||
Height: 12345,
|
||||
Round: 23456,
|
||||
BlockParts: types.PartSetHeader{111, []byte("blockparts")},
|
||||
POLParts: types.PartSetHeader{222, []byte("polparts")},
|
||||
Signature: nil,
|
||||
}
|
||||
signBytes := account.SignBytes(proposal)
|
||||
signStr := string(signBytes)
|
||||
expected := Fmt(`{"Network":"%X","Proprosal":{"BlockParts":{"Hash":"626C6F636B7061727473","Total":111},"Height":12345,"POLParts":{"Hash":"706F6C7061727473","Total":222},"Round":23456}}`,
|
||||
config.App().GetString("Network"))
|
||||
if signStr != expected {
|
||||
t.Errorf("Got unexpected sign string for SendTx. Expected:\n%v\nGot:\n%v", expected, signStr)
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
"github.com/tendermint/tendermint/merkle"
|
||||
)
|
||||
@ -84,6 +85,10 @@ func (psh PartSetHeader) Equals(other PartSetHeader) bool {
|
||||
return psh.Total == other.Total && bytes.Equal(psh.Hash, other.Hash)
|
||||
}
|
||||
|
||||
func (psh PartSetHeader) WriteSignBytes(w io.Writer, n *int64, err *error) {
|
||||
binary.WriteTo([]byte(Fmt(`{"Hash":"%X","Total":%v}`, psh.Hash, psh.Total)), w, n, err)
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
type PartSet struct {
|
||||
|
Reference in New Issue
Block a user