From 2de72c83d067a8f15165eab65fa6c1b9fa51667c 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 | 80 ++++++++++++++++++------------------- x/fbridge/keeper/genesis.go | 2 +- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/x/fbridge/keeper/auth.go b/x/fbridge/keeper/auth.go index 47080a89d7..68af400212 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: @@ -176,7 +214,7 @@ func (k Keeper) GetProposalVotes(ctx sdk.Context, proposalID uint64) []types.Vot return votes } -func (k Keeper) SetRole(ctx sdk.Context, role types.Role, addr sdk.AccAddress) { +func (k Keeper) setRole(ctx sdk.Context, role types.Role, addr sdk.AccAddress) { store := ctx.KVStore(k.storeKey) bz := make([]byte, 4) binary.BigEndian.PutUint32(bz, uint32(role)) @@ -207,7 +245,7 @@ func (k Keeper) GetRolePairs(ctx sdk.Context) []types.RolePair { return pairs } -func (k Keeper) DeleteRole(ctx sdk.Context, addr sdk.AccAddress) { +func (k Keeper) deleteRole(ctx sdk.Context, addr sdk.AccAddress) { store := ctx.KVStore(k.storeKey) store.Delete(types.RoleKey(addr)) } @@ -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) diff --git a/x/fbridge/keeper/genesis.go b/x/fbridge/keeper/genesis.go index e3ed8445b2..8d6e76dc01 100644 --- a/x/fbridge/keeper/genesis.go +++ b/x/fbridge/keeper/genesis.go @@ -20,7 +20,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, gs *types.GenesisState) error { } for _, pair := range gs.Roles { - k.SetRole(ctx, pair.Role, sdk.MustAccAddressFromBech32(pair.Address)) + k.setRole(ctx, pair.Role, sdk.MustAccAddressFromBech32(pair.Address)) } k.SetRoleMetadata(ctx, gs.RoleMetadata)