Skip to main content
Version: v0.50.x

Save Storage Structure

You now need to set the data structure in the keeper to store the wallet to name pair. Keeper's are where the data is stored for future use.

x/nameservice/keeper/keeper.go

type Keeper struct {
...
NameMapping collections.Map[string, string]
}

...

func NewKeeper() Keeper {
...

k := Keeper{
...
NameMapping: collections.NewMap(sb, collections.NewPrefix(1), "name_mapping", collections.StringKey, collections.StringValue),
}

}

keeper NewKeeper NameMapping


Application Logic

Update the msg_server logic to set the name upon request from a user.

x/nameservice/keeper/msg_server.go
func (ms msgServer) SetServiceName(ctx context.Context, msg *types.MsgSetServiceName) (*types.MsgSetServiceNameResponse, error) {
if err := ms.k.NameMapping.Set(ctx, msg.Sender, msg.Name); err != nil {
return nil, err
}

return &types.MsgSetServiceNameResponse{}, nil
}

and also for the query_server to retrieve the name.

x/nameservice/keeper/query_server.go
func (k Querier) ResolveName(goCtx context.Context, req *types.QueryResolveNameRequest) (*types.QueryResolveNameResponse, error) {
v, err := k.Keeper.NameMapping.Get(goCtx, req.Wallet)
if err != nil {
return nil, err
}

return &types.QueryResolveNameResponse{
Name: v,
}, nil
}