Skip to content

Commit 046101e

Browse files
committed
add logic to check if msgURL is empty
1 parent bf8c0da commit 046101e

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

x/circuit/keeper/msg_server.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7+
"slices"
78
"strings"
89

910
"cosmossdk.io/collections"
@@ -137,6 +138,7 @@ func (srv msgServer) TripCircuitBreaker(ctx context.Context, msg *types.MsgTripC
137138
// have been paused using TripCircuitBreaker.
138139
func (srv msgServer) ResetCircuitBreaker(ctx context.Context, msg *types.MsgResetCircuitBreaker) (*types.MsgResetCircuitBreakerResponse, error) {
139140
keeper := srv.Keeper
141+
msgTypeUrls := msg.MsgTypeUrls
140142
address, err := srv.addressCodec.StringToBytes(msg.Authority)
141143
if err != nil {
142144
return nil, err
@@ -148,7 +150,29 @@ func (srv msgServer) ResetCircuitBreaker(ctx context.Context, msg *types.MsgRese
148150
return nil, err
149151
}
150152

151-
for _, msgTypeURL := range msg.MsgTypeUrls {
153+
// check if msgURL is empty
154+
if len(msgTypeUrls) == 0 {
155+
switch {
156+
case perms.Level == types.Permissions_LEVEL_SUPER_ADMIN || perms.Level == types.Permissions_LEVEL_ALL_MSGS || bytes.Equal(address, srv.GetAuthority()):
157+
// if the sender is a super admin or the module authority, will remove all disabled msgs
158+
srv.DisableList.Walk(ctx, nil, func(msgUrl string) (stop bool, err error) {
159+
msgTypeUrls = append(msgTypeUrls, msgUrl)
160+
return false, nil
161+
})
162+
163+
case perms.Level == types.Permissions_LEVEL_SOME_MSGS:
164+
// if the sender has permission for some messages, will remove all disabled msgs that in the perms.LimitTypeUrls
165+
srv.DisableList.Walk(ctx, nil, func(msgUrl string) (stop bool, err error) {
166+
if slices.Contains(perms.LimitTypeUrls, msgUrl) {
167+
msgTypeUrls = append(msgTypeUrls, msgUrl)
168+
}
169+
return false, nil
170+
})
171+
default:
172+
}
173+
}
174+
175+
for _, msgTypeURL := range msgTypeUrls {
152176
// check if the message is in the list of allowed messages
153177
isAllowed, err := srv.IsAllowed(ctx, msgTypeURL)
154178
if err != nil {
@@ -176,7 +200,7 @@ func (srv msgServer) ResetCircuitBreaker(ctx context.Context, msg *types.MsgRese
176200
}
177201
}
178202

179-
urls := strings.Join(msg.GetMsgTypeUrls(), ",")
203+
urls := strings.Join(msgTypeUrls, ",")
180204

181205
if err = srv.Keeper.EventService.EventManager(ctx).EmitKV(
182206
"reset_circuit_breaker",

0 commit comments

Comments
 (0)