This repository has been archived by the owner on Oct 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
689 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ const ( | |
|
||
Bech32PrefixAccAddr = "mycel" | ||
|
||
OneYearInDays = 365 | ||
OneYearInDays = 365 | ||
) | ||
|
||
var ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
x/registry/client/cli/tx_extend_top_level_domain_expiration.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
x/registry/keeper/msg_server_extend_top_level_domain_expiration.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
x/registry/simulation/extend_top_level_domain_expiration.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
x/registry/types/message_extend_top_level_domain_expiration.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} | ||
|
||
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 | ||
} |
40 changes: 40 additions & 0 deletions
40
x/registry/types/message_extend_top_level_domain_expiration_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.