Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuvubk committed Sep 23, 2024
1 parent 1fa11c9 commit 829c03c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 33 deletions.
7 changes: 6 additions & 1 deletion simapp/v2/simdv2/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,9 @@ func initGenFiles[T transaction.Tx](

var bankV2GenState bankv2types.GenesisState
clientCtx.Codec.MustUnmarshalJSON(appGenState[bankv2types.ModuleName], &bankV2GenState)
bankV2GenState = getBankV2GenesisFromV1(bankGenState)
if len(bankV2GenState.Balances) == 0 {
bankV2GenState = getBankV2GenesisFromV1(bankGenState)
}
appGenState[bankv2types.ModuleName] = clientCtx.Codec.MustMarshalJSON(&bankV2GenState)

appGenStateJSON, err := json.MarshalIndent(appGenState, "", " ")
Expand Down Expand Up @@ -511,6 +513,9 @@ func writeFile(name, dir string, contents []byte) error {
return os.WriteFile(file, contents, 0o600)
}

// getBankV2GenesisFromV1 clones bank/v1 state to bank/v2
// since we not migrate yet
// TODO: Remove
func getBankV2GenesisFromV1(v1GenesisState banktypes.GenesisState) bankv2types.GenesisState {
var v2GenesisState bankv2types.GenesisState
for _, balance := range v1GenesisState.Balances {
Expand Down
14 changes: 5 additions & 9 deletions x/bank/v2/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (am AppModule) RegisterQueryHandlers(router appmodulev2.QueryRouter) {
}
}

// GetQueryDecoders registers the query handlers for the bank module.
// GetQueryDecoders returns grpc request and the corresponding decoder.
func (am AppModule) GetQueryDecoders() map[string]func() gogoproto.Message {
decodeMaps := make(map[string]func() gogoproto.Message)
var errs error
Expand All @@ -171,18 +171,14 @@ func (am AppModule) GetQueryDecoders() map[string]func() gogoproto.Message {
return decodeMaps
}

// GetTxCmd returns the root tx command for the bank module.
// GetTxCmd returns the root tx command for the bank/v2 module.
// TODO: Remove & use autocli
func (AppModule) GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}

// GetTxCmd returns the root query command for the bank/v2 module.
// TODO: Remove & use autocli
func (AppModule) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}

// // RegisterServices registers module services.
// func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
// am.RegisterMsgHandlers(registrar)

// return nil
// }
23 changes: 0 additions & 23 deletions x/bank/v2/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package types

import (
coretransaction "cosmossdk.io/core/transaction"
errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

var _ coretransaction.Msg = &MsgSend{}
Expand All @@ -14,24 +12,3 @@ var _ coretransaction.Msg = &MsgSend{}
func NewMsgSend(fromAddr, toAddr string, amount sdk.Coins) *MsgSend {
return &MsgSend{FromAddress: fromAddr, ToAddress: toAddr, Amount: amount}
}

// ValidateBasic Implements Msg.
func (msg MsgSend) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.FromAddress); err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid from address: %s", err)
}

if _, err := sdk.AccAddressFromBech32(msg.ToAddress); err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid to address: %s", err)
}

if !msg.Amount.IsValid() {
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, msg.Amount.String())
}

if !msg.Amount.IsAllPositive() {
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, msg.Amount.String())
}

return nil
}

0 comments on commit 829c03c

Please sign in to comment.