Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Update CmdSubmitTopLevelDomainProposal #124

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
245 changes: 245 additions & 0 deletions docs/static/openapi.yml

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions proto/mycel/registry/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ service Msg {
rpc ExtendTopLevelDomainExpirationDate (MsgExtendTopLevelDomainExpirationDate ) returns (MsgExtendTopLevelDomainExpirationDateResponse );
rpc UpdateTextRecord (MsgUpdateTextRecord ) returns (MsgUpdateTextRecordResponse );
rpc UpdateTopLevelDomainRegistrationPolicy (MsgUpdateTopLevelDomainRegistrationPolicy) returns (MsgUpdateTopLevelDomainRegistrationPolicyResponse);
rpc SubmitTopLevelDomainProposal (MsgSubmitTopLevelDomainProposal ) returns (MsgSubmitTopLevelDomainProposalResponse );
}
message MsgUpdateWalletRecord {
string creator = 1;
Expand Down Expand Up @@ -97,3 +98,14 @@ message MsgUpdateTopLevelDomainRegistrationPolicy {

message MsgUpdateTopLevelDomainRegistrationPolicyResponse {}

message MsgSubmitTopLevelDomainProposal {
string creator = 1;
string name = 2;
uint64 registrationPeriodInYear = 3;
}

message MsgSubmitTopLevelDomainProposalResponse {
TopLevelDomain topLevelDomain = 1;
TopLevelDomainFee fee = 2;
}

1 change: 1 addition & 0 deletions x/registry/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(CmdExtendTopLevelDomainExpirationDate())
cmd.AddCommand(CmdUpdateTextRecord())
cmd.AddCommand(CmdUpdateTopLevelDomainRegistrationPolicy())
cmd.AddCommand(CmdSubmitTopLevelDomainProposal())
// this line is used by starport scaffolding # 1

return cmd
Expand Down
69 changes: 69 additions & 0 deletions x/registry/client/cli/tx_submit_top_level_domain_proposal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package cli

import (
"fmt"
"strconv"

Check failure on line 6 in x/registry/client/cli/tx_submit_top_level_domain_proposal.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos) -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cosmos/gaia) -s prefix(github.com/mycel-domain/mycel) --custom-order (gci)
errorsmod "cosmossdk.io/errors"

Check failure on line 7 in x/registry/client/cli/tx_submit_top_level_domain_proposal.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos) -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cosmos/gaia) -s prefix(github.com/mycel-domain/mycel) --custom-order (gci)
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"

Check failure on line 13 in x/registry/client/cli/tx_submit_top_level_domain_proposal.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos) -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cosmos/gaia) -s prefix(github.com/mycel-domain/mycel) --custom-order (gci)
"github.com/mycel-domain/mycel/x/registry/types"
"github.com/spf13/cast"
"github.com/spf13/cobra"
)

var _ = strconv.Itoa(0)

func CmdSubmitTopLevelDomainProposal() *cobra.Command {
cmd := &cobra.Command{
Use: "submit-top-level-domain-proposal [name] [registration-period-in-year] [flags]",
Short: "Broadcast message submit-top-level-domain-proposal",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argName := args[0]
argRegistrationPeriodInYear, err := cast.ToUint64E(args[1])
if err != nil {
return err
}
if argRegistrationPeriodInYear < 1 || argRegistrationPeriodInYear > 4 {
return errorsmod.Wrapf(types.ErrTopLevelDomainInvalidRegistrationPeriod, "%d year(s)", argRegistrationPeriodInYear)
}

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

proposal, err := cli.ReadGovPropFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}

msg := types.NewMsgSubmitTopLevelDomainProposal(
sdk.AccAddress(address.Module("gov")).String(),
argName,
argRegistrationPeriodInYear,
)
if err := msg.ValidateBasic(); err != nil {
return err
}

if err := proposal.SetMsgs([]sdk.Msg{msg}); err != nil {
return fmt.Errorf("failed to create submit top-level-domain proposal message: %w", err)
}

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

// add common proposal flags
flags.AddTxFlagsToCmd(cmd)
cli.AddGovPropFlagsToCmd(cmd)
cmd.MarkFlagRequired(cli.FlagTitle)

Check failure on line 66 in x/registry/client/cli/tx_submit_top_level_domain_proposal.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `cmd.MarkFlagRequired` is not checked (errcheck)

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

import (
"context"

errorsmod "cosmossdk.io/errors"

Check failure on line 6 in x/registry/keeper/msg_server_submit_top_level_domain_proposal.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos) -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cosmos/gaia) -s prefix(github.com/mycel-domain/mycel) --custom-order (gci)
sdk "github.com/cosmos/cosmos-sdk/types"

Check failure on line 7 in x/registry/keeper/msg_server_submit_top_level_domain_proposal.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos) -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cosmos/gaia) -s prefix(github.com/mycel-domain/mycel) --custom-order (gci)
"github.com/mycel-domain/mycel/x/registry/types"
)

func (k msgServer) SubmitTopLevelDomainProposal(goCtx context.Context, msg *types.MsgSubmitTopLevelDomainProposal) (*types.MsgSubmitTopLevelDomainProposalResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// NOTE: Same as x/registry/keeper/msg_server_register_top_level_domain.go
if msg.RegistrationPeriodInYear < 1 || msg.RegistrationPeriodInYear > 4 {
return nil, errorsmod.Wrapf(types.ErrTopLevelDomainInvalidRegistrationPeriod, "%d year(s)", msg.RegistrationPeriodInYear)
}

topLevelDomain, fee, err := k.Keeper.RegisterTopLevelDomain(ctx, msg.Creator, msg.Name, msg.RegistrationPeriodInYear)
if err != nil {
return nil, err
}

return &types.MsgSubmitTopLevelDomainProposalResponse{
TopLevelDomain: &topLevelDomain,
Fee: &fee,
}, nil
}
15 changes: 15 additions & 0 deletions x/registry/module_simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ const (
// TODO: Determine the simulation weight value
defaultWeightMsgUpdateTopLevelDomainRegistrationPolicy int = 100

opWeightMsgSubmitTopLevelDomainProposal = "op_weight_msg_submit_top_level_domain_proposal"
// TODO: Determine the simulation weight value
defaultWeightMsgSubmitTopLevelDomainProposal int = 100

// this line is used by starport scaffolding # simapp/module/const
)

Expand Down Expand Up @@ -157,6 +161,17 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
registrysimulation.SimulateMsgUpdateTopLevelDomainRegistrationPolicy(am.accountKeeper, am.bankKeeper, am.keeper),
))

var weightMsgSubmitTopLevelDomainProposal int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgSubmitTopLevelDomainProposal, &weightMsgSubmitTopLevelDomainProposal, nil,
func(_ *rand.Rand) {
weightMsgSubmitTopLevelDomainProposal = defaultWeightMsgSubmitTopLevelDomainProposal
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgSubmitTopLevelDomainProposal,
registrysimulation.SimulateMsgSubmitTopLevelDomainProposal(am.accountKeeper, am.bankKeeper, am.keeper),
))

// this line is used by starport scaffolding # simapp/module/operation

return operations
Expand Down
29 changes: 29 additions & 0 deletions x/registry/simulation/submit_top_level_domain_proposal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package simulation

import (
"math/rand"

"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"

Check failure on line 8 in x/registry/simulation/submit_top_level_domain_proposal.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos) -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cosmos/gaia) -s prefix(github.com/mycel-domain/mycel) --custom-order (gci)
"github.com/mycel-domain/mycel/x/registry/keeper"
"github.com/mycel-domain/mycel/x/registry/types"
)

func SimulateMsgSubmitTopLevelDomainProposal(
ak types.AccountKeeper,
bk types.BankKeeper,
k keeper.Keeper,
) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
simAccount, _ := simtypes.RandomAcc(r, accs)
msg := &types.MsgSubmitTopLevelDomainProposal{
Creator: simAccount.Address.String(),
}

// TODO: Handling the SubmitTopLevelDomainProposal simulation

return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "SubmitTopLevelDomainProposal simulation not implemented"), nil, nil
}
}
4 changes: 4 additions & 0 deletions x/registry/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func RegisterCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgExtendTopLevelDomainExpirationDate{}, "registry/ExtendTopLevelDomainExpirationDate", nil)
cdc.RegisterConcrete(&MsgUpdateTextRecord{}, "registry/UpdateTextRecord", nil)
cdc.RegisterConcrete(&MsgUpdateTopLevelDomainRegistrationPolicy{}, "registry/UpdateTopLevelDomainRegistrationPolicy", nil)
cdc.RegisterConcrete(&MsgSubmitTopLevelDomainProposal{}, "registry/SubmitTopLevelDomainProposal", nil)
// this line is used by starport scaffolding # 2
}

Expand All @@ -40,6 +41,9 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgUpdateTopLevelDomainRegistrationPolicy{},
)
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgSubmitTopLevelDomainProposal{},
)
// this line is used by starport scaffolding # 3

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
Expand Down
47 changes: 47 additions & 0 deletions x/registry/types/message_submit_top_level_domain_proposal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package types

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

const TypeMsgSubmitTopLevelDomainProposal = "submit_top_level_domain_proposal"

var _ sdk.Msg = &MsgSubmitTopLevelDomainProposal{}

func NewMsgSubmitTopLevelDomainProposal(creator string, name string, registrationPeriodInYear uint64) *MsgSubmitTopLevelDomainProposal {
return &MsgSubmitTopLevelDomainProposal{
Creator: creator,
Name: name,
RegistrationPeriodInYear: registrationPeriodInYear,
}
}

func (msg *MsgSubmitTopLevelDomainProposal) Route() string {
return RouterKey
}

func (msg *MsgSubmitTopLevelDomainProposal) Type() string {
return TypeMsgSubmitTopLevelDomainProposal
}

func (msg *MsgSubmitTopLevelDomainProposal) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{creator}
}

func (msg *MsgSubmitTopLevelDomainProposal) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}

func (msg *MsgSubmitTopLevelDomainProposal) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
return nil
}
40 changes: 40 additions & 0 deletions x/registry/types/message_submit_top_level_domain_proposal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package types

import (
"testing"

Check failure on line 5 in x/registry/types/message_submit_top_level_domain_proposal_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos) -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cosmos/gaia) -s prefix(github.com/mycel-domain/mycel) --custom-order (gci)
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

Check failure on line 6 in x/registry/types/message_submit_top_level_domain_proposal_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos) -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cosmos/gaia) -s prefix(github.com/mycel-domain/mycel) --custom-order (gci)
"github.com/mycel-domain/mycel/testutil/sample"
"github.com/stretchr/testify/require"

Check failure on line 8 in x/registry/types/message_submit_top_level_domain_proposal_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos) -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cosmos/gaia) -s prefix(github.com/mycel-domain/mycel) --custom-order (gci)
)

func TestMsgSubmitTopLevelDomainProposal_ValidateBasic(t *testing.T) {
tests := []struct {
name string
msg MsgSubmitTopLevelDomainProposal
err error
}{
{
name: "invalid address",
msg: MsgSubmitTopLevelDomainProposal{
Creator: "invalid_address",
},
err: sdkerrors.ErrInvalidAddress,
}, {
name: "valid address",
msg: MsgSubmitTopLevelDomainProposal{
Creator: sample.AccAddress(),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.msg.ValidateBasic()
if tt.err != nil {
require.ErrorIs(t, err, tt.err)
return
}
require.NoError(t, err)
})
}
}
Loading
Loading