From 2202c5168d2b15e14ad103355bbb2f4a25f9e0f0 Mon Sep 17 00:00:00 2001 From: Jayden Lee <41176085+tkxkd0159@users.noreply.github.com> Date: Fri, 3 May 2024 11:09:53 +0900 Subject: [PATCH] chore --- x/fbridge/keeper/auth.go | 76 ++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/x/fbridge/keeper/auth.go b/x/fbridge/keeper/auth.go index 47080a89d7..2a1e6dc6cc 100644 --- a/x/fbridge/keeper/auth.go +++ b/x/fbridge/keeper/auth.go @@ -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: @@ -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)