/
msg_server_list.go
57 lines (41 loc) · 1.28 KB
/
msg_server_list.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
package keeper
import (
"context"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/jackalLabs/canine-chain/v3/x/rns/types"
)
func (k msgServer) List(goCtx context.Context, msg *types.MsgList) (*types.MsgListResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
mname := strings.ToLower(msg.Name)
_, found := k.GetForsale(ctx, mname)
if found {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Name already listed.")
}
n, tld, err := GetNameAndTLD(mname)
if err != nil {
return nil, err
}
name, nfound := k.GetNames(ctx, n, tld)
if !nfound {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Name does not exist or has expired.")
}
if name.Value != msg.Creator {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "You do not own this name.")
}
blockHeight := ctx.BlockHeight()
if name.Locked > blockHeight {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "cannot transfer free name")
}
if blockHeight > name.Expires {
return nil, sdkerrors.Wrap(sdkerrors.ErrNotFound, "Name does not exist or has expired.")
}
newsale := types.Forsale{
Name: mname,
Price: msg.Price,
Owner: msg.Creator,
}
k.SetForsale(ctx, newsale)
return &types.MsgListResponse{}, nil
}