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

Commit

Permalink
scaffold extend message
Browse files Browse the repository at this point in the history
  • Loading branch information
taryune committed Nov 2, 2023
1 parent 71d6c1c commit 6415c14
Show file tree
Hide file tree
Showing 21 changed files with 689 additions and 64 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ type App struct {
RegistryKeeper registrymodulekeeper.Keeper
EpochsKeeper epochsmodulekeeper.Keeper
ResolverKeeper resolvermodulekeeper.Keeper
FurnaceKeeper furnacemodulekeeper.Keeper
FurnaceKeeper furnacemodulekeeper.Keeper
// this line is used by starport scaffolding # stargate/app/keeperDeclaration

// mm is the module manager
Expand Down
2 changes: 1 addition & 1 deletion app/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (

Bech32PrefixAccAddr = "mycel"

OneYearInDays = 365
OneYearInDays = 365
)

var (
Expand Down
2 changes: 2 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81185,6 +81185,8 @@ definitions:

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
mycel.registry.MsgExtendTopLevelDomainExpirationResponse:
type: object
mycel.registry.MsgRegisterSecondLevelDomainResponse:
type: object
mycel.registry.MsgRegisterTopLevelDomainResponse:
Expand Down
24 changes: 15 additions & 9 deletions proto/mycel/registry/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ option go_package = "github.com/mycel-domain/mycel/x/registry/types";

// Msg defines the Msg service.
service Msg {
rpc UpdateWalletRecord (MsgUpdateWalletRecord ) returns (MsgUpdateWalletRecordResponse );
rpc UpdateDnsRecord (MsgUpdateDnsRecord ) returns (MsgUpdateDnsRecordResponse );
rpc RegisterSecondLevelDomain (MsgRegisterSecondLevelDomain ) returns (MsgRegisterSecondLevelDomainResponse );
rpc RegisterTopLevelDomain (MsgRegisterTopLevelDomain ) returns (MsgRegisterTopLevelDomainResponse );
rpc WithdrawRegistrationFee (MsgWithdrawRegistrationFee) returns (MsgWithdrawRegistrationFeeResponse);
rpc UpdateWalletRecord (MsgUpdateWalletRecord ) returns (MsgUpdateWalletRecordResponse );
rpc UpdateDnsRecord (MsgUpdateDnsRecord ) returns (MsgUpdateDnsRecordResponse );
rpc RegisterSecondLevelDomain (MsgRegisterSecondLevelDomain ) returns (MsgRegisterSecondLevelDomainResponse );
rpc RegisterTopLevelDomain (MsgRegisterTopLevelDomain ) returns (MsgRegisterTopLevelDomainResponse );
rpc WithdrawRegistrationFee (MsgWithdrawRegistrationFee ) returns (MsgWithdrawRegistrationFeeResponse );
rpc ExtendTopLevelDomainExpiration (MsgExtendTopLevelDomainExpiration) returns (MsgExtendTopLevelDomainExpirationResponse);
}
message MsgUpdateWalletRecord {
string creator = 1;
Expand Down Expand Up @@ -58,9 +59,14 @@ message MsgWithdrawRegistrationFee {
}

message MsgWithdrawRegistrationFeeResponse {
repeated cosmos.base.v1beta1.Coin registrationFee = 7 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
repeated cosmos.base.v1beta1.Coin registrationFee = 7 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
}

message MsgExtendTopLevelDomainExpiration {
string creator = 1;
string name = 2;
int64 registrationPeriodInYear = 3;
}

message MsgExtendTopLevelDomainExpirationResponse {}

4 changes: 2 additions & 2 deletions x/furnace/keeper/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type ExpCreateBurnAmountEvent struct {
var (
now = time.Now()
oneDayDuration = time.Hour*24 + time.Second
defaultConfig = types.GetDefaultEpochBurnConfig()
defaultConfig = types.GetDefaultEpochBurnConfig()
)

func (suite *KeeperTestSuite) TestAfterEpochEndCreateBurnAmount() {
Expand All @@ -45,7 +45,7 @@ func (suite *KeeperTestSuite) TestAfterEpochEndCreateBurnAmount() {
},
},
{
epochsCount: int64(defaultConfig.DefaultTotalEpochs+1),
epochsCount: int64(defaultConfig.DefaultTotalEpochs + 1),
expectedEvents: []ExpCreateBurnAmountEvent{
{
BurnAmountIndex: "1",
Expand Down
2 changes: 1 addition & 1 deletion x/furnace/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import (

// x/furnace module sentinel errors
var (
ErrSample = sdkerrors.Register(ModuleName, 1100, "sample error")
ErrSample = sdkerrors.Register(ModuleName, 1100, "sample error")
ErrInvalidRegistrationPeriod = sdkerrors.Register(ModuleName, 1101, "invalid registration period")
)
1 change: 1 addition & 0 deletions x/registry/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(CmdRegisterDomain())
cmd.AddCommand(CmdRegisterTopLevelDomain())
cmd.AddCommand(CmdWithdrawRegistrationFee())
cmd.AddCommand(CmdExtendTopLevelDomainExpiration())
// this line is used by starport scaffolding # 1

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

import (
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/mycel-domain/mycel/x/registry/types"
"github.com/spf13/cast"
"github.com/spf13/cobra"
)

var _ = strconv.Itoa(0)

func CmdExtendTopLevelDomainExpiration() *cobra.Command {
cmd := &cobra.Command{
Use: "extend-top-level-domain-expiration [name] [registration-period-in-year]",
Short: "Broadcast message extendTopLevelDomainExpiration",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argName := args[0]
argRegistrationPeriodInYear, err := cast.ToInt32E(args[1])
if err != nil {
return err
}

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

msg := types.NewMsgExtendTopLevelDomainExpiration(
clientCtx.GetFromAddress().String(),
argName,
argRegistrationPeriodInYear,
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
6 changes: 3 additions & 3 deletions x/registry/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ func NewKeeper(
memKey: memKey,
paramstore: ps,

bankKeeper: bankKeeper,
bankKeeper: bankKeeper,
distributionKeeper: distributionKeeper,
mintKeeper: mintKeeper,
furnaceKeeper: furnaceKeeper,
mintKeeper: mintKeeper,
furnaceKeeper: furnaceKeeper,
}
}

Expand Down
17 changes: 17 additions & 0 deletions x/registry/keeper/msg_server_extend_top_level_domain_expiration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/mycel-domain/mycel/x/registry/types"
)

func (k msgServer) ExtendTopLevelDomainExpiration(goCtx context.Context, msg *types.MsgExtendTopLevelDomainExpiration) (*types.MsgExtendTopLevelDomainExpirationResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// TODO: Handling the message
_ = ctx

return &types.MsgExtendTopLevelDomainExpirationResponse{}, nil
}
10 changes: 5 additions & 5 deletions x/registry/keeper/msg_server_register_top_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ func (k msgServer) RegisterTopLevelDomain(goCtx context.Context, msg *types.MsgR

defaultRegistrationConfig := types.GetDefaultSubdomainConfig(3030)
domain := types.TopLevelDomain{
Name: msg.Name,
ExpirationDate: expirationDate.UnixNano(),
Metadata: nil,
SubdomainConfig: &defaultRegistrationConfig,
AccessControl: accessControl,
Name: msg.Name,
ExpirationDate: expirationDate.UnixNano(),
Metadata: nil,
SubdomainConfig: &defaultRegistrationConfig,
AccessControl: accessControl,
TotalWithdrawalAmount: sdk.NewCoins(),
}

Expand Down
1 change: 0 additions & 1 deletion x/registry/keeper/msg_server_update_dns_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ func (k msgServer) UpdateDnsRecord(goCtx context.Context, msg *types.MsgUpdateDn
// Emit event
EmitUpdateDnsRecordEvent(ctx, *msg)


return &types.MsgUpdateDnsRecordResponse{}, nil
}
1 change: 0 additions & 1 deletion x/registry/keeper/msg_server_update_wallet_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ func (k msgServer) UpdateWalletRecord(goCtx context.Context, msg *types.MsgUpdat
// Emit event
EmitUpdateWalletRecordEvent(ctx, *msg)


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

opWeightMsgExtendTopLevelDomainExpiration = "op_weight_msg_extend_top_level_domain_expiration"
// TODO: Determine the simulation weight value
defaultWeightMsgExtendTopLevelDomainExpiration int = 100

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

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

var weightMsgExtendTopLevelDomainExpiration int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgExtendTopLevelDomainExpiration, &weightMsgExtendTopLevelDomainExpiration, nil,
func(_ *rand.Rand) {
weightMsgExtendTopLevelDomainExpiration = defaultWeightMsgExtendTopLevelDomainExpiration
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgExtendTopLevelDomainExpiration,
registrysimulation.SimulateMsgExtendTopLevelDomainExpiration(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/extend_top_level_domain_expiration.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"
"github.com/mycel-domain/mycel/x/registry/keeper"
"github.com/mycel-domain/mycel/x/registry/types"
)

func SimulateMsgExtendTopLevelDomainExpiration(
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.MsgExtendTopLevelDomainExpiration{
Creator: simAccount.Address.String(),
}

// TODO: Handling the ExtendTopLevelDomainExpiration simulation

return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "ExtendTopLevelDomainExpiration 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 @@ -12,6 +12,7 @@ func RegisterCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgRegisterSecondLevelDomain{}, "registry/RegisterSecondLevelDomain", nil)
cdc.RegisterConcrete(&MsgRegisterTopLevelDomain{}, "registry/RegisterTopLevelDomain", nil)
cdc.RegisterConcrete(&MsgWithdrawRegistrationFee{}, "registry/WithdrawRegistrationFee", nil)
cdc.RegisterConcrete(&MsgExtendTopLevelDomainExpiration{}, "registry/ExtendTopLevelDomainExpiration", nil)
// this line is used by starport scaffolding # 2
}

Expand All @@ -28,6 +29,9 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgWithdrawRegistrationFee{},
)
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgExtendTopLevelDomainExpiration{},
)
// 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_extend_top_level_domain_expiration.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 TypeMsgExtendTopLevelDomainExpiration = "extend_top_level_domain_expiration"

var _ sdk.Msg = &MsgExtendTopLevelDomainExpiration{}

func NewMsgExtendTopLevelDomainExpiration(creator string, name string, registrationPeriodInYear int32) *MsgExtendTopLevelDomainExpiration {
return &MsgExtendTopLevelDomainExpiration{
Creator: creator,
Name: name,
RegistrationPeriodInYear: registrationPeriodInYear,

Check failure on line 16 in x/registry/types/message_extend_top_level_domain_expiration.go

View workflow job for this annotation

GitHub Actions / go

cannot use registrationPeriodInYear (variable of type int32) as int64 value in struct literal
}
}

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

func (msg *MsgExtendTopLevelDomainExpiration) Type() string {
return TypeMsgExtendTopLevelDomainExpiration
}

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

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

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

import (
"testing"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/mycel-domain/mycel/testutil/sample"
"github.com/stretchr/testify/require"
)

func TestMsgExtendTopLevelDomainExpiration_ValidateBasic(t *testing.T) {
tests := []struct {
name string
msg MsgExtendTopLevelDomainExpiration
err error
}{
{
name: "invalid address",
msg: MsgExtendTopLevelDomainExpiration{
Creator: "invalid_address",
},
err: sdkerrors.ErrInvalidAddress,
}, {
name: "valid address",
msg: MsgExtendTopLevelDomainExpiration{
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)
})
}
}
2 changes: 1 addition & 1 deletion x/registry/types/message_withdraw_registration_fee.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package types

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

const TypeMsgWithdrawRegistrationFee = "withdraw_registration_fee"
Expand Down
2 changes: 1 addition & 1 deletion x/registry/types/top_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

type TopLevelDomainRegistrationFee struct {
TotalRegistrationFee sdk.Coins
BurnWeight math.LegacyDec
BurnWeight math.LegacyDec
RegistrationFeeToBurn sdk.Coin
RegistrationFeeToTreasury sdk.Coin
}
Expand Down
Loading

0 comments on commit 6415c14

Please sign in to comment.