Skip to content

Commit

Permalink
chore
Browse files Browse the repository at this point in the history
  • Loading branch information
tkxkd0159 committed May 3, 2024
1 parent 25f2722 commit 2202c51
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions x/fbridge/keeper/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,44 @@ func (k Keeper) addVote(ctx sdk.Context, proposalID uint64, voter sdk.AccAddress
return nil
}

func (k Keeper) UpdateRole(ctx sdk.Context, role types.Role, addr sdk.AccAddress) error {
previousRole := k.GetRole(ctx, addr)
if previousRole == role {
return sdkerrors.ErrUnauthorized.Wrap("target already has same role")
}

metadata := k.GetRoleMetadata(ctx)

switch previousRole {
case types.RoleGuardian:
metadata.Guardian--
case types.RoleOperator:
metadata.Operator--
case types.RoleJudge:
metadata.Judge--
}

if role == types.RoleEmpty {
k.DeleteRole(ctx, addr)
return nil
} else {
k.SetRole(ctx, role, addr)
}

switch role {
case types.RoleGuardian:
metadata.Guardian++
case types.RoleOperator:
metadata.Operator++
case types.RoleJudge:
metadata.Judge++
}

k.SetRoleMetadata(ctx, metadata)

return nil
}

func (k Keeper) IsValidRole(role types.Role) error {
switch role {
case types.RoleGuardian, types.RoleOperator, types.RoleJudge:
Expand Down Expand Up @@ -218,44 +256,6 @@ func (k Keeper) SetRoleMetadata(ctx sdk.Context, data types.RoleMetadata) {
store.Set(types.KeyRoleMetadata, bz)
}

func (k Keeper) UpdateRole(ctx sdk.Context, role types.Role, addr sdk.AccAddress) error {
previousRole := k.GetRole(ctx, addr)
if previousRole == role {
return sdkerrors.ErrUnauthorized.Wrap("target already has same role")
}

metadata := k.GetRoleMetadata(ctx)

switch previousRole {
case types.RoleGuardian:
metadata.Guardian--
case types.RoleOperator:
metadata.Operator--
case types.RoleJudge:
metadata.Judge--
}

if role == types.RoleEmpty {
k.DeleteRole(ctx, addr)
return nil
} else {
k.SetRole(ctx, role, addr)
}

switch role {
case types.RoleGuardian:
metadata.Guardian++
case types.RoleOperator:
metadata.Operator++
case types.RoleJudge:
metadata.Judge++
}

k.SetRoleMetadata(ctx, metadata)

return nil
}

func (k Keeper) GetRoleMetadata(ctx sdk.Context) types.RoleMetadata {
store := ctx.KVStore(k.storeKey)

Expand Down

0 comments on commit 2202c51

Please sign in to comment.