forked from JackalLabs/canine-chain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg_server_block_senders.go
52 lines (37 loc) · 1.24 KB
/
msg_server_block_senders.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
package keeper
import (
"context"
"encoding/json"
"github.com/MonikaCat/canine-chain/v2/x/notifications/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func (k msgServer) BlockSenders(goCtx context.Context, msg *types.MsgBlockSenders) (*types.MsgBlockSendersResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
notiCounter, found := k.GetNotiCounter(ctx, msg.Creator)
if !found {
return nil, types.ErrNotiCounterNotFound
}
if !(notiCounter.Address == msg.Creator) {
return nil, types.ErrOnlyOwnerCanBlock
}
BlockedSenders := notiCounter.BlockedSenders
placeholderMap := make([]string, 0, 1000)
err := json.Unmarshal([]byte(BlockedSenders), &placeholderMap)
if err != nil {
return nil, types.ErrCantUnmarshall
}
temporaryMap := make([]string, 0, 1000)
err = json.Unmarshal([]byte(msg.SenderIds), &temporaryMap)
if err != nil {
return nil, types.ErrCantUnmarshall
}
placeholderMap = append(placeholderMap, temporaryMap...)
marshalledSenders, err := json.Marshal(placeholderMap)
if err != nil {
return nil, types.ErrCantUnmarshall
}
updatedBlockedSenders := string(marshalledSenders)
notiCounter.BlockedSenders = updatedBlockedSenders
k.SetNotiCounter(ctx, notiCounter)
return &types.MsgBlockSendersResponse{}, nil
}