Change to go-wire UnmarshalJSON for bank transactions
The bank module now uses it's own codec to encode and decode Bank Msgs into JSON.
This commit is contained in:
parent
f36eb2209e
commit
2d87563856
11
CHANGELOG.md
11
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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue