-
Notifications
You must be signed in to change notification settings - Fork 17
/
msg_server_init.go
66 lines (49 loc) · 1.42 KB
/
msg_server_init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package keeper
import (
"context"
"strings"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/jackalLabs/canine-chain/x/rns/types"
)
func (k msgServer) Init(goCtx context.Context, msg *types.MsgInit) (*types.MsgInitResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
_, found := k.GetInit(ctx, msg.Creator)
if found {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "cannot initialize more than once")
}
i := types.Init{
Address: msg.Creator,
Complete: true,
}
k.SetInit(ctx, i)
bh := ctx.BlockHeight()
name := types.MakeName(int(bh), bh)
if strings.Contains(name, ".") {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "name cannot contain '.'")
}
if len(name) < 6 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "name cannot be less than 6 characters")
}
whois, isFound := k.GetNames(ctx, name, "jkl")
if isFound {
if bh < whois.Expires {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Name already registered")
}
}
time := 5733818 + bh
emptySubdomains := []*types.Names{}
// Create an updated whois record
newWhois := types.Names{
Name: name,
Expires: time,
Value: msg.Creator,
Data: "{}",
Subdomains: emptySubdomains,
Tld: "jkl",
Locked: time,
}
// Write whois information to the store
k.SetNames(ctx, newWhois)
return &types.MsgInitResponse{}, nil
}