Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,102 changes: 1,041 additions & 61 deletions api/cosmos/bank/v1beta1/tx.pulsar.go

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions api/cosmos/bank/v1beta1/tx_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions proto/cosmos/bank/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ service Msg {
//
// Since: cosmos-sdk 0.47
rpc SetSendEnabled(MsgSetSendEnabled) returns (MsgSetSendEnabledResponse);
// SetMetadata is an admin operation for setting the Metadata for
// a given denom. The authority is defined in the keeper.
//
// Since: cosmos-sdk 0.47
rpc SetMetadata(MsgSetMetadata) returns (MsgSetMetadataResponse);
}

// MsgSend represents a message to send coins from one account to another.
Expand Down Expand Up @@ -122,3 +127,20 @@ message MsgSetSendEnabled {
//
// Since: cosmos-sdk 0.47
message MsgSetSendEnabledResponse {}

// MsgSetMetadata is the Msg/MsgSetMetadata request type.
//
//
// Since: cosmos-sdk 0.47-saga.2
message MsgSetMetadata {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "cosmos-sdk/MsgSetMetadata";

string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
Metadata metadata = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}

// SetMetadataResponse defines the Msg/MsgSetMetadata response type.
//
// Since: cosmos-sdk 0.47-saga.2
message MsgSetMetadataResponse {}
1 change: 1 addition & 0 deletions simapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ var (
Name: banktypes.ModuleName,
Config: appconfig.WrapAny(&bankmodulev1.Module{
BlockedModuleAccountsOverride: blockAccAddrs,
Authority: "cosmos1f707nyjehspmlajxnm3zjnm2h0ssqqp3h070pu",
}),
},
{
Expand Down
4 changes: 4 additions & 0 deletions x/authz/testutil/bank_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ func (k MockBankKeeper) UpdateParams(goCtx context.Context, req *bank.MsgUpdateP
func (k MockBankKeeper) SetSendEnabled(goCtx context.Context, req *bank.MsgSetSendEnabled) (*bank.MsgSetSendEnabledResponse, error) {
return nil, nil
}

func (k MockBankKeeper) SetMetadata(goCtx context.Context, req *bank.MsgSetMetadata) (*bank.MsgSetMetadataResponse, error) {
return nil, nil
}
1 change: 1 addition & 0 deletions x/bank/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func NewTxCmd(ac address.Codec) *cobra.Command {
txCmd.AddCommand(
NewSendTxCmd(ac),
NewMultiSendTxCmd(ac),
NewSetMetadataCmd(ac),
)

return txCmd
Expand Down
67 changes: 67 additions & 0 deletions x/bank/client/cli/tx_saga.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package cli

import (
"fmt"
"os"

"cosmossdk.io/core/address"
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/x/bank/types"
)

func NewSetMetadataCmd(ac address.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "set-metadata [metadata-file | metadata-json]",
Short: "Set metadata for a bank denomination",
Long: `Set metadata for a bank denomination. Metadata can be provided either as a JSON file or as a JSON string.
Example:
# From a file
$ simd tx bank set-metadata metadata.json
metadata.json:
{
"description": "The native staking token of an arbitrary cosmos sdk chain.",
"denom_units": [{ "denom": "stake", "exponent": 0, "aliases": ["stake"] }],
"base": "stake",
"display": "stake",
"name": "stake",
"symbol": "stake"
}
`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

var metadataBytes []byte
input := args[0]

if _, err := os.Stat(input); err == nil {
metadataBytes, err = os.ReadFile(input)
if err != nil {
return fmt.Errorf("failed to read metadata file: %w", err)
}
} else {
metadataBytes = []byte(input)
}

var metadata types.Metadata
if err := clientCtx.Codec.UnmarshalJSON(metadataBytes, &metadata); err != nil {
return fmt.Errorf("failed to parse metadata JSON: %w", err)
}

msg := types.NewMsgSetMetadata(clientCtx.GetFromAddress(), metadata)

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
25 changes: 25 additions & 0 deletions x/bank/keeper/msg_server_saga.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package keeper

import (
"context"

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

func (k msgServer) SetMetadata(goCtx context.Context, msg *types.MsgSetMetadata) (*types.MsgSetMetadataResponse, error) {
if k.GetAuthority() != msg.Authority {
return nil, sdkerrors.ErrInvalidRequest.Wrapf("invalid authority; expected %s, got %s", k.GetAuthority(), msg.Authority)
}

ctx := sdk.UnwrapSDKContext(goCtx)
err := msg.Metadata.Validate()
if err != nil {
return nil, err
}

k.SetDenomMetaData(ctx, msg.Metadata)

return &types.MsgSetMetadataResponse{}, nil
}
2 changes: 2 additions & 0 deletions x/bank/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
legacy.RegisterAminoMsg(cdc, &MsgMultiSend{}, "cosmos-sdk/MsgMultiSend")
legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "cosmos-sdk/x/bank/MsgUpdateParams")
legacy.RegisterAminoMsg(cdc, &MsgSetSendEnabled{}, "cosmos-sdk/MsgSetSendEnabled")
legacy.RegisterAminoMsg(cdc, &MsgSetMetadata{}, "cosmos-sdk/MsgSetMetadata")

cdc.RegisterConcrete(&SendAuthorization{}, "cosmos-sdk/SendAuthorization", nil)
cdc.RegisterConcrete(&Params{}, "cosmos-sdk/x/bank/Params", nil)
Expand All @@ -26,6 +27,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&MsgSend{},
&MsgMultiSend{},
&MsgUpdateParams{},
&MsgSetMetadata{},
)
registry.RegisterImplementations(
(*authz.Authorization)(nil),
Expand Down
51 changes: 51 additions & 0 deletions x/bank/types/msg_saga.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package types

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// bank message types
// const (
// TypeMsgSetMetadata = "set_metadata"
// )

var (
_ sdk.Msg = &MsgSetMetadata{}
)

// NewMsgSetMetadata - construct a msg to send coins from one account to another.
//
//nolint:interfacer
func NewMsgSetMetadata(authority sdk.AccAddress, metadata Metadata) *MsgSetMetadata {
return &MsgSetMetadata{Authority: authority.String(), Metadata: metadata}
}

// // Route Implements Msg.
// func (msg MsgSetMetadata) Route() string { return RouterKey }

// // Type Implements Msg.
// func (msg MsgSetMetadata) Type() string { return TypeMsgSetMetadata }

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

// if err := msg.Metadata.Validate(); err != nil {
// return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid metadata: %v", err)
// }

// return nil
// }

// // GetSignBytes Implements Msg.
// func (msg MsgSetMetadata) GetSignBytes() []byte {
// return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
// }

// // GetSigners Implements Msg.
// func (msg MsgSetMetadata) GetSigners() []sdk.AccAddress {
// signer, _ := sdk.AccAddressFromBech32(msg.Authority)
// return []sdk.AccAddress{signer}
// }
Loading
Loading