Skip to content

Commit

Permalink
R4R: Remove unused bank.MsgIssue (and prevent possible panic) (#2855)
Browse files Browse the repository at this point in the history
* Remove all bank.MsgIssue code
  • Loading branch information
cwgoes authored and jackzampolin committed Nov 19, 2018
1 parent 9676ce7 commit fd968f7
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 114 deletions.
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ BUG FIXES
* SDK

- \#2733 [x/gov, x/mock/simulation] Fix governance simulation, update x/gov import/export
- \#2854 [x/bank] Remove unused bank.MsgIssue, prevent possible panic

* Tendermint
* [\#2797](https://github.com/tendermint/tendermint/pull/2797) AddressBook requires addresses to have IDs; Do not crap out immediately after sending pex addrs in seed mode
1 change: 0 additions & 1 deletion x/bank/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
// Register concrete types on codec codec
func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterConcrete(MsgSend{}, "cosmos-sdk/Send", nil)
cdc.RegisterConcrete(MsgIssue{}, "cosmos-sdk/Issue", nil)
}

var msgCdc = codec.New()
Expand Down
7 changes: 0 additions & 7 deletions x/bank/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ func NewHandler(k Keeper) sdk.Handler {
switch msg := msg.(type) {
case MsgSend:
return handleMsgSend(ctx, k, msg)
case MsgIssue:
return handleMsgIssue(ctx, k, msg)
default:
errMsg := "Unrecognized bank Msg type: %s" + msg.Type()
return sdk.ErrUnknownRequest(errMsg).Result()
Expand All @@ -32,8 +30,3 @@ func handleMsgSend(ctx sdk.Context, k Keeper, msg MsgSend) sdk.Result {
Tags: tags,
}
}

// Handle MsgIssue.
func handleMsgIssue(ctx sdk.Context, k Keeper, msg MsgIssue) sdk.Result {
panic("not implemented yet")
}
59 changes: 0 additions & 59 deletions x/bank/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,65 +86,6 @@ func (msg MsgSend) GetSigners() []sdk.AccAddress {
return addrs
}

//----------------------------------------
// MsgIssue

// MsgIssue - high level transaction of the coin module
type MsgIssue struct {
Banker sdk.AccAddress `json:"banker"`
Outputs []Output `json:"outputs"`
}

var _ sdk.Msg = MsgIssue{}

// NewMsgIssue - construct arbitrary multi-in, multi-out send msg.
func NewMsgIssue(banker sdk.AccAddress, out []Output) MsgIssue {
return MsgIssue{Banker: banker, Outputs: out}
}

// Implements Msg.
// nolint
func (msg MsgIssue) Route() string { return "bank" } // TODO: "bank/issue"
func (msg MsgIssue) Type() string { return "issue" }

// Implements Msg.
func (msg MsgIssue) ValidateBasic() sdk.Error {
// XXX
if len(msg.Outputs) == 0 {
return ErrNoOutputs(DefaultCodespace).TraceSDK("")
}
for _, out := range msg.Outputs {
if err := out.ValidateBasic(); err != nil {
return err.TraceSDK("")
}
}
return nil
}

// Implements Msg.
func (msg MsgIssue) GetSignBytes() []byte {
var outputs []json.RawMessage
for _, output := range msg.Outputs {
outputs = append(outputs, output.GetSignBytes())
}
b, err := msgCdc.MarshalJSON(struct {
Banker sdk.AccAddress `json:"banker"`
Outputs []json.RawMessage `json:"outputs"`
}{
Banker: msg.Banker,
Outputs: outputs,
})
if err != nil {
panic(err)
}
return sdk.MustSortJSON(b)
}

// Implements Msg.
func (msg MsgIssue) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.Banker}
}

//----------------------------------------
// Input

Expand Down
45 changes: 0 additions & 45 deletions x/bank/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,48 +223,3 @@ func TestMsgSendSigners(t *testing.T) {
require.Equal(t, signers, tx.Signers())
}
*/

// ----------------------------------------
// MsgIssue Tests

func TestNewMsgIssue(t *testing.T) {
// TODO
}

func TestMsgIssueRoute(t *testing.T) {
// Construct an MsgIssue
addr := sdk.AccAddress([]byte("loan-from-bank"))
coins := sdk.Coins{sdk.NewInt64Coin("atom", 10)}
var msg = MsgIssue{
Banker: sdk.AccAddress([]byte("input")),
Outputs: []Output{NewOutput(addr, coins)},
}

// TODO some failures for bad result
require.Equal(t, msg.Route(), "bank")
}

func TestMsgIssueValidation(t *testing.T) {
// TODO
}

func TestMsgIssueGetSignBytes(t *testing.T) {
addr := sdk.AccAddress([]byte("loan-from-bank"))
coins := sdk.Coins{sdk.NewInt64Coin("atom", 10)}
var msg = MsgIssue{
Banker: sdk.AccAddress([]byte("input")),
Outputs: []Output{NewOutput(addr, coins)},
}
res := msg.GetSignBytes()

expected := `{"banker":"cosmos1d9h8qat57ljhcm","outputs":[{"address":"cosmos1d3hkzm3dveex7mfdvfsku6cjngpcj","coins":[{"amount":"10","denom":"atom"}]}]}`
require.Equal(t, expected, string(res))
}

func TestMsgIssueGetSigners(t *testing.T) {
var msg = MsgIssue{
Banker: sdk.AccAddress([]byte("onlyone")),
}
res := msg.GetSigners()
require.Equal(t, fmt.Sprintf("%v", res), "[6F6E6C796F6E65]")
}
1 change: 0 additions & 1 deletion x/ibc/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func makeCodec() *codec.Codec {
// Register Msgs
cdc.RegisterInterface((*sdk.Msg)(nil), nil)
cdc.RegisterConcrete(bank.MsgSend{}, "test/ibc/Send", nil)
cdc.RegisterConcrete(bank.MsgIssue{}, "test/ibc/Issue", nil)
cdc.RegisterConcrete(IBCTransferMsg{}, "test/ibc/IBCTransferMsg", nil)
cdc.RegisterConcrete(IBCReceiveMsg{}, "test/ibc/IBCReceiveMsg", nil)

Expand Down
1 change: 0 additions & 1 deletion x/stake/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func MakeTestCodec() *codec.Codec {
// Register Msgs
cdc.RegisterInterface((*sdk.Msg)(nil), nil)
cdc.RegisterConcrete(bank.MsgSend{}, "test/stake/Send", nil)
cdc.RegisterConcrete(bank.MsgIssue{}, "test/stake/Issue", nil)
cdc.RegisterConcrete(types.MsgCreateValidator{}, "test/stake/CreateValidator", nil)
cdc.RegisterConcrete(types.MsgEditValidator{}, "test/stake/EditValidator", nil)
cdc.RegisterConcrete(types.MsgBeginUnbonding{}, "test/stake/BeginUnbonding", nil)
Expand Down

0 comments on commit fd968f7

Please sign in to comment.