Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mn13 committed Sep 11, 2024
1 parent cc6b20b commit 4e5b686
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
41 changes: 23 additions & 18 deletions warden/x/act/keeper/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package keeper
import (
"context"
"fmt"
"log"
"reflect"
"runtime/debug"

"cosmossdk.io/errors"
Expand Down Expand Up @@ -103,7 +103,6 @@ func (k Keeper) TryRejectVotedAction(ctx context.Context, act *types.Action) err
// result in the database.
func (k Keeper) TryExecuteAction(ctx context.Context, act *types.Action) error {
ready, err := k.checkActionReady(ctx, *act)
log.Printf("\nready %v\n", ready)
if err != nil {
return err
}
Expand Down Expand Up @@ -215,11 +214,11 @@ func (k Keeper) AddAction(ctx context.Context, creator string, msg sdk.Msg, time
return nil, errors.Wrapf(types.ErrNoRuleRegistryHandler, "%v", err)
}

if approveRule.Expression.String() != expectedApproveExpression.String() {
if !reflect.DeepEqual(approveRule.Expression, expectedApproveExpression) {
return nil, types.ErrApproveExpressionNotMatched
}

if rejectRule.Expression.String() != expectedRejectExpression.String() {
if !reflect.DeepEqual(rejectRule.Expression, expectedRejectExpression) {
return nil, types.ErrRejectExpressionNotMatched
}

Expand All @@ -239,20 +238,7 @@ func (k Keeper) AddAction(ctx context.Context, creator string, msg sdk.Msg, time
return nil, err
}

mentions := approveMentions

approveMentionsSet := make(map[string]struct{})

for _, approveMention := range approveMentions {
approveMentionsSet[approveMention] = struct{}{}
}

for _, rejectMention := range rejectMentions {
_, exists := approveMentionsSet[rejectMention]
if !exists {
mentions = append(mentions, rejectMention)
}
}
mentions := mergeMentions(approveMentions, rejectMentions)

// update the rule of this Action with the preprocessed expression
// todo: should be removed with removing Rule field in Action
Expand Down Expand Up @@ -314,3 +300,22 @@ func (k Keeper) validateActionMsgSigners(msg sdk.Msg) error {

return nil
}

func mergeMentions(approveMentions []string, rejectMentions []string) []string {
mentions := approveMentions

approveMentionsSet := make(map[string]struct{})

for _, approveMention := range approveMentions {
approveMentionsSet[approveMention] = struct{}{}
}

for _, rejectMention := range rejectMentions {
_, exists := approveMentionsSet[rejectMention]
if !exists {
mentions = append(mentions, rejectMention)
}
}

return mentions
}
8 changes: 6 additions & 2 deletions warden/x/warden/keeper/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,19 @@ func (k Keeper) getRejectNewKeyRequestRule(ctx context.Context, space v1beta3.Sp
}

func (k Keeper) getApproveUpdateKeyRule(ctx context.Context, space v1beta3.Space, key v1beta3.Key) (acttypes.Rule, error) {
if space.ApproveSignRuleId > 0 {
if key.ApproveRuleId > 0 {
return k.actKeeper.GetRule(ctx, key.ApproveRuleId)
} else if space.ApproveSignRuleId > 0 {
return k.actKeeper.GetRule(ctx, space.ApproveSignRuleId)
} else {
return space.RuleApproveUpdateKey(), nil
}
}

func (k Keeper) getRejectUpdateKeyRule(ctx context.Context, space v1beta3.Space, key v1beta3.Key) (acttypes.Rule, error) {
if space.RejectSignRuleId > 0 {
if key.ApproveRuleId > 0 {
return k.actKeeper.GetRule(ctx, key.RejectRuleId)
} else if space.RejectSignRuleId > 0 {
return k.actKeeper.GetRule(ctx, space.RejectSignRuleId)
} else {
return space.RuleRejectUpdateKey(), nil
Expand Down

0 comments on commit 4e5b686

Please sign in to comment.