Browse Source

Proposal WriteSignBytes is JSON

pull/67/head
Jae Kwon 9 years ago
parent
commit
5366d808ba
3 changed files with 40 additions and 5 deletions
  1. +8
    -5
      consensus/types/proposal.go
  2. +27
    -0
      consensus/types/proposal_test.go
  3. +5
    -0
      types/part_set.go

+ 8
- 5
consensus/types/proposal.go View File

@ -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
- 0
consensus/types/proposal_test.go View 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)
}
}

+ 5
- 0
types/part_set.go View File

@ -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 {


Loading…
Cancel
Save