forked from JackalLabs/canine-chain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg_server_set_counter.go
47 lines (37 loc) · 1.08 KB
/
msg_server_set_counter.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
package keeper
import (
"context"
"encoding/json"
"github.com/MonikaCat/canine-chain/v2/x/notifications/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// This needs to be inside of filetree init
func (k msgServer) SetCounter(goCtx context.Context, msg *types.MsgSetCounter) (*types.MsgSetCounterResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
// Check if the value already exists
_, isFound := k.GetNotiCounter(
ctx,
msg.Creator,
)
if isFound {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "counter already set")
}
// Place holder map for blocked senders
placeholderMap := make([]string, 0, 1000)
marshalledBlockedSenders, err := json.Marshal(placeholderMap)
if err != nil {
return nil, types.ErrCantUnmarshall
}
BlockedSenders := string(marshalledBlockedSenders)
counter := types.NotiCounter{
Address: msg.Creator,
Counter: 0,
BlockedSenders: BlockedSenders,
}
k.SetNotiCounter(
ctx,
counter,
)
return &types.MsgSetCounterResponse{NotiCounter: counter.Counter}, nil
}