sort *all* GetSignBytes:

- call MustSortJSON before return JSON bytes to guarantee alphabetic
ordering

- moved SortJSON and MustSortJSON to types package to avoid cyclic
package dep
This commit is contained in:
Liamsi
2018-07-06 01:12:57 +01:00
parent 0f1ceb073e
commit b7f902fba5
20 changed files with 100 additions and 143 deletions
+2 -2
View File
@@ -58,7 +58,7 @@ func (msg MsgSetTrend) GetSignBytes() []byte {
if err != nil {
panic(err)
}
return b
return sdk.MustSortJSON(b)
}
//_______________________________________________________________________
@@ -102,5 +102,5 @@ func (msg MsgQuiz) GetSignBytes() []byte {
if err != nil {
panic(err)
}
return b
return sdk.MustSortJSON(b)
}
+1 -1
View File
@@ -18,7 +18,7 @@ func (msg Msg) GetSignBytes() []byte {
if err != nil {
panic(err)
}
return bz
return sdk.MustSortJSON(bz)
}
// GetSigners implements sdk.Msg
+1 -1
View File
@@ -76,5 +76,5 @@ func (msg MsgMine) GetSignBytes() []byte {
if err != nil {
panic(err)
}
return b
return sdk.MustSortJSON(b)
}
+1 -1
View File
@@ -62,7 +62,7 @@ func TestMsgMineGetSignBytes(t *testing.T) {
addr := sdk.Address([]byte("sender"))
msg := MsgMine{addr, 1, 1, 1, []byte("abc")}
res := msg.GetSignBytes()
require.Equal(t, string(res), `{"sender":"73656E646572","difficulty":1,"count":1,"nonce":1,"proof":"YWJj"}`)
require.Equal(t, string(res), `{"count":1,"difficulty":1,"nonce":1,"proof":"YWJj","sender":"73656E646572"}`)
}
func TestMsgMineGetSigners(t *testing.T) {
+1 -1
View File
@@ -48,7 +48,7 @@ func (msg MsgBond) GetSignBytes() []byte {
if err != nil {
panic(err)
}
return bz
return sdk.MustSortJSON(bz)
}
//_______________________________________________________________
+1 -1
View File
@@ -27,7 +27,7 @@ func (tx kvstoreTx) GetMemo() string {
}
func (tx kvstoreTx) GetSignBytes() []byte {
return tx.bytes
return sdk.MustSortJSON(tx.bytes)
}
// Should the app be calling this? Or only handlers?