diff --git a/CHANGELOG.md b/CHANGELOG.md index faacc6e34..f2f68824a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## Pending + +BREAKING CHANGES + +FEATURES + +IMPROVEMENTS +* bank module uses go-wire codec instead of 'encoding/json' + +FIXES + ## 0.18.1 BREAKING CHANGES diff --git a/x/bank/msgs.go b/x/bank/msgs.go index de7f2a8b1..c256b6de6 100644 --- a/x/bank/msgs.go +++ b/x/bank/msgs.go @@ -1,8 +1,6 @@ package bank import ( - "encoding/json" - sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -55,7 +53,8 @@ func (msg MsgSend) ValidateBasic() sdk.Error { // Implements Msg. func (msg MsgSend) GetSignBytes() []byte { - b, err := json.Marshal(msg) // XXX: ensure some canonical form + cdc := getCodec() + b, err := cdc.MarshalJSON(msg) // XXX: ensure some canonical form if err != nil { panic(err) } @@ -104,7 +103,8 @@ func (msg MsgIssue) ValidateBasic() sdk.Error { // Implements Msg. func (msg MsgIssue) GetSignBytes() []byte { - b, err := json.Marshal(msg) // XXX: ensure some canonical form + cdc := getCodec() + b, err := cdc.MarshalJSON(msg) // XXX: ensure some canonical form if err != nil { panic(err) } diff --git a/x/bank/msgs_test.go b/x/bank/msgs_test.go index 78de01f40..fd1992e3c 100644 --- a/x/bank/msgs_test.go +++ b/x/bank/msgs_test.go @@ -186,8 +186,15 @@ func TestMsgSendGetSignBytes(t *testing.T) { Outputs: []Output{NewOutput(addr2, coins)}, } res := msg.GetSignBytes() + + cdc := getCodec() + unmarshaledMsg := &MsgSend{} + cdc.UnmarshalJSON(res, unmarshaledMsg) + assert.Equal(t, &msg, unmarshaledMsg) + // TODO bad results - assert.Equal(t, string(res), `{"inputs":[{"address":"696E707574","coins":[{"denom":"atom","amount":10}]}],"outputs":[{"address":"6F7574707574","coins":[{"denom":"atom","amount":10}]}]}`) + expected := `{"type":"EAFDE32A2C87F8","value":{"inputs":[{"address":"696E707574","coins":[{"denom":"atom","amount":10}]}],"outputs":[{"address":"6F7574707574","coins":[{"denom":"atom","amount":10}]}]}}` + assert.Equal(t, expected, string(res)) } func TestMsgSendGetSigners(t *testing.T) { @@ -255,8 +262,15 @@ func TestMsgIssueGetSignBytes(t *testing.T) { Outputs: []Output{NewOutput(addr, coins)}, } res := msg.GetSignBytes() + + cdc := getCodec() + unmarshaledMsg := &MsgIssue{} + cdc.UnmarshalJSON(res, unmarshaledMsg) + assert.Equal(t, &msg, unmarshaledMsg) + // TODO bad results - assert.Equal(t, string(res), `{"banker":"696E707574","outputs":[{"address":"6C6F616E2D66726F6D2D62616E6B","coins":[{"denom":"atom","amount":10}]}]}`) + expected := `{"type":"72E617C06ABAD0","value":{"banker":"696E707574","outputs":[{"address":"6C6F616E2D66726F6D2D62616E6B","coins":[{"denom":"atom","amount":10}]}]}}` + assert.Equal(t, expected, string(res)) } func TestMsgIssueGetSigners(t *testing.T) { diff --git a/x/bank/wire.go b/x/bank/wire.go index fdb6c252b..49511ef0e 100644 --- a/x/bank/wire.go +++ b/x/bank/wire.go @@ -9,3 +9,9 @@ func RegisterWire(cdc *wire.Codec) { cdc.RegisterConcrete(MsgSend{}, "cosmos-sdk/Send", nil) cdc.RegisterConcrete(MsgIssue{}, "cosmos-sdk/Issue", nil) } + +func getCodec() *wire.Codec { + cdc := wire.NewCodec() + RegisterWire(cdc) + return cdc +}