From 5292013dff16d12ba0bf4567c4179c0ad257964e Mon Sep 17 00:00:00 2001 From: Rayden Ge Date: Thu, 12 Dec 2024 19:17:12 +0100 Subject: [PATCH] fix(events): align event processing with smart contract changes (#400) align event processing with smart contract changes issue: closes #393 --- .../x/evmstaking/keeper/delegator_address.go | 9 ++++----- client/x/evmstaking/keeper/keeper.go | 20 +++++++++---------- client/x/evmstaking/types/events.go | 4 ++-- client/x/evmstaking/types/staking_contract.go | 4 ++-- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/client/x/evmstaking/keeper/delegator_address.go b/client/x/evmstaking/keeper/delegator_address.go index bd2174db..b7e5b34b 100644 --- a/client/x/evmstaking/keeper/delegator_address.go +++ b/client/x/evmstaking/keeper/delegator_address.go @@ -102,7 +102,7 @@ func (k Keeper) ProcessSetRewardAddress(ctx context.Context, ev *bindings.IPToke return nil } -func (k Keeper) ProcessAddOperator(ctx context.Context, ev *bindings.IPTokenStakingAddOperator) (err error) { +func (k Keeper) ProcessSetOperator(ctx context.Context, ev *bindings.IPTokenStakingSetOperator) (err error) { sdkCtx := sdk.UnwrapSDKContext(ctx) cachedCtx, writeCache := sdkCtx.CacheContext() @@ -116,7 +116,7 @@ func (k Keeper) ProcessAddOperator(ctx context.Context, ev *bindings.IPTokenStak } sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( - types.EventTypeAddOperatorFailure, + types.EventTypeSetOperatorFailure, sdk.NewAttribute(types.AttributeKeyBlockHeight, strconv.FormatInt(sdkCtx.BlockHeight(), 10)), sdk.NewAttribute(types.AttributeKeyDelegatorUncmpPubKey, hex.EncodeToString(ev.UncmpPubkey)), sdk.NewAttribute(types.AttributeKeyOperatorAddress, ev.Operator.Hex()), @@ -144,7 +144,7 @@ func (k Keeper) ProcessAddOperator(ctx context.Context, ev *bindings.IPTokenStak return nil } -func (k Keeper) ProcessRemoveOperator(ctx context.Context, ev *bindings.IPTokenStakingRemoveOperator) (err error) { +func (k Keeper) ProcessUnsetOperator(ctx context.Context, ev *bindings.IPTokenStakingUnsetOperator) (err error) { sdkCtx := sdk.UnwrapSDKContext(ctx) cachedCtx, writeCache := sdkCtx.CacheContext() @@ -158,10 +158,9 @@ func (k Keeper) ProcessRemoveOperator(ctx context.Context, ev *bindings.IPTokenS } sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( - types.EventTypeRemoveOperatorFailure, + types.EventTypeUnsetOperatorFailure, sdk.NewAttribute(types.AttributeKeyBlockHeight, strconv.FormatInt(sdkCtx.BlockHeight(), 10)), sdk.NewAttribute(types.AttributeKeyDelegatorUncmpPubKey, hex.EncodeToString(ev.UncmpPubkey)), - sdk.NewAttribute(types.AttributeKeyOperatorAddress, ev.Operator.Hex()), sdk.NewAttribute(types.AttributeKeyStatusCode, errors.UnwrapErrCode(err).String()), sdk.NewAttribute(types.AttributeKeyTxHash, hex.EncodeToString(ev.Raw.TxHash.Bytes())), ), diff --git a/client/x/evmstaking/keeper/keeper.go b/client/x/evmstaking/keeper/keeper.go index 696304dd..9dbe9f34 100644 --- a/client/x/evmstaking/keeper/keeper.go +++ b/client/x/evmstaking/keeper/keeper.go @@ -154,24 +154,24 @@ func (k Keeper) ProcessStakingEvents(ctx context.Context, height uint64, logs [] clog.Error(ctx, "Failed to process set reward address", err) continue } - case types.AddOperator.ID: - ev, err := k.ipTokenStakingContract.ParseAddOperator(ethlog) + case types.SetOperator.ID: + ev, err := k.ipTokenStakingContract.ParseSetOperator(ethlog) if err != nil { - clog.Error(ctx, "Failed to parse SetRewardAddress log", err) + clog.Error(ctx, "Failed to parse SetOperator log", err) continue } - if err = k.ProcessAddOperator(ctx, ev); err != nil { - clog.Error(ctx, "Failed to process add operator", err) + if err = k.ProcessSetOperator(ctx, ev); err != nil { + clog.Error(ctx, "Failed to process set operator", err) continue } - case types.RemoveOperator.ID: - ev, err := k.ipTokenStakingContract.ParseRemoveOperator(ethlog) + case types.UnsetOperator.ID: + ev, err := k.ipTokenStakingContract.ParseUnsetOperator(ethlog) if err != nil { - clog.Error(ctx, "Failed to parse SetRewardAddress log", err) + clog.Error(ctx, "Failed to parse UnsetOperator log", err) continue } - if err = k.ProcessRemoveOperator(ctx, ev); err != nil { - clog.Error(ctx, "Failed to process add operator", err) + if err = k.ProcessUnsetOperator(ctx, ev); err != nil { + clog.Error(ctx, "Failed to process unset operator", err) continue } case types.CreateValidatorEvent.ID: diff --git a/client/x/evmstaking/types/events.go b/client/x/evmstaking/types/events.go index 7a973db7..c05e09cb 100644 --- a/client/x/evmstaking/types/events.go +++ b/client/x/evmstaking/types/events.go @@ -5,8 +5,8 @@ const ( EventTypeUpdateValidatorCommissionFailure = "update_validator_commission_failure" EventTypeSetWithdrawalAddressFailure = "set_withdrawal_address_failure" EventTypeSetRewardAddressFailure = "set_reward_address_failure" - EventTypeAddOperatorFailure = "add_operator_failure" - EventTypeRemoveOperatorFailure = "remove_operator_failure" + EventTypeSetOperatorFailure = "set_operator_failure" + EventTypeUnsetOperatorFailure = "unset_operator_failure" EventTypeCreateValidatorFailure = "create_validator_failure" EventTypeDelegateFailure = "delegate_failure" EventTypeRedelegateFailure = "redelegate_failure" diff --git a/client/x/evmstaking/types/staking_contract.go b/client/x/evmstaking/types/staking_contract.go index 64fbe4d8..2dd6cc54 100644 --- a/client/x/evmstaking/types/staking_contract.go +++ b/client/x/evmstaking/types/staking_contract.go @@ -12,8 +12,8 @@ var ( UpdateValidatorCommission = mustGetEvent(ipTokenStakingABI, "UpdateValidatorCommssion") SetWithdrawalAddress = mustGetEvent(ipTokenStakingABI, "SetWithdrawalAddress") SetRewardAddress = mustGetEvent(ipTokenStakingABI, "SetRewardAddress") - AddOperator = mustGetEvent(ipTokenStakingABI, "AddOperator") - RemoveOperator = mustGetEvent(ipTokenStakingABI, "RemoveOperator") + SetOperator = mustGetEvent(ipTokenStakingABI, "SetOperator") + UnsetOperator = mustGetEvent(ipTokenStakingABI, "UnsetOperator") CreateValidatorEvent = mustGetEvent(ipTokenStakingABI, "CreateValidator") DepositEvent = mustGetEvent(ipTokenStakingABI, "Deposit") RedelegateEvent = mustGetEvent(ipTokenStakingABI, "Redelegate")