Skip to content

Commit

Permalink
fix(events): align event processing with smart contract changes (#400)
Browse files Browse the repository at this point in the history
align event processing with smart contract changes

issue: closes #393
  • Loading branch information
ezreal1997 authored and Ramarti committed Dec 12, 2024
1 parent 830b91a commit 5292013
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
9 changes: 4 additions & 5 deletions client/x/evmstaking/keeper/delegator_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()),
Expand Down Expand Up @@ -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()

Expand All @@ -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())),
),
Expand Down
20 changes: 10 additions & 10 deletions client/x/evmstaking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions client/x/evmstaking/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions client/x/evmstaking/types/staking_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 5292013

Please sign in to comment.