Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace utils.Contains with slices.Contains #128

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions internal/services/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"time"

"github.com/babylonlabs-io/babylon-staking-indexer/internal/types"
"github.com/babylonlabs-io/babylon-staking-indexer/internal/utils"
bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types"
ftypes "github.com/babylonlabs-io/babylon/x/finality/types"
abcitypes "github.com/cometbft/cometbft/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
proto "github.com/cosmos/gogoproto/proto"
"github.com/rs/zerolog/log"
"slices"
)

type EventTypes string
Expand Down Expand Up @@ -174,7 +174,7 @@ func (s *Service) validateCovenantQuorumReachedEvent(ctx context.Context, event
}

// Check if the current state is qualified for the transition
if !utils.Contains(qualifiedStates, delegation.State) {
if !slices.Contains(qualifiedStates, delegation.State) {
log.Debug().
Str("stakingTxHashHex", event.StakingTxHash).
Stringer("currentState", delegation.State).
Expand Down Expand Up @@ -232,7 +232,7 @@ func (s *Service) validateBTCDelegationInclusionProofReceivedEvent(ctx context.C
}

// Check if the current state is qualified for the transition
if !utils.Contains(qualifiedStates, delegation.State) {
if !slices.Contains(qualifiedStates, delegation.State) {
log.Debug().
Str("stakingTxHashHex", event.StakingTxHash).
Stringer("currentState", delegation.State).
Expand Down Expand Up @@ -273,7 +273,7 @@ func (s *Service) validateBTCDelegationUnbondedEarlyEvent(ctx context.Context, e
}

// Check if the current state is qualified for the transition
if !utils.Contains(types.QualifiedStatesForUnbondedEarly(), delegation.State) {
if !slices.Contains(types.QualifiedStatesForUnbondedEarly(), delegation.State) {
log.Debug().
Str("stakingTxHashHex", event.StakingTxHash).
Stringer("currentState", delegation.State).
Expand Down Expand Up @@ -302,7 +302,7 @@ func (s *Service) validateBTCDelegationExpiredEvent(ctx context.Context, event *
}

// Check if the current state is qualified for the transition
if !utils.Contains(types.QualifiedStatesForExpired(), delegation.State) {
if !slices.Contains(types.QualifiedStatesForExpired(), delegation.State) {
log.Debug().
Str("stakingTxHashHex", event.StakingTxHash).
Stringer("currentState", delegation.State).
Expand Down
5 changes: 3 additions & 2 deletions internal/services/watch_btc_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/btcsuite/btcd/wire"
notifier "github.com/lightningnetwork/lnd/chainntnfs"
"github.com/rs/zerolog/log"
"slices"
)

func (s *Service) watchForSpendStakingTx(
Expand Down Expand Up @@ -120,7 +121,7 @@ func (s *Service) watchForSpendSlashingChange(
}

qualifiedStates := types.QualifiedStatesForWithdrawn()
if qualifiedStates == nil || !utils.Contains(qualifiedStates, *delegationState) {
if qualifiedStates == nil || !slices.Contains(qualifiedStates, *delegationState) {
log.Error().
Str("staking_tx", delegation.StakingTxHashHex).
Stringer("state", delegationState).
Expand Down Expand Up @@ -379,7 +380,7 @@ func (s *Service) handleWithdrawal(
}

qualifiedStates := types.QualifiedStatesForWithdrawn()
if qualifiedStates == nil || !utils.Contains(qualifiedStates, *delegationState) {
if qualifiedStates == nil || !slices.Contains(qualifiedStates, *delegationState) {
log.Error().
Str("staking_tx", delegation.StakingTxHashHex).
Stringer("current_state", delegationState).
Expand Down
10 changes: 0 additions & 10 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,6 @@ func SafeUnescape(s string) string {
return unquoted
}

// Contains checks if a slice contains a specific element
func Contains[T comparable](slice []T, item T) bool {
for _, elem := range slice {
if elem == item {
return true
}
}
return false
}

func GetTxHash(txBytes []byte) (chainhash.Hash, error) {
var msgTx wire.MsgTx
if err := msgTx.Deserialize(bytes.NewReader(txBytes)); err != nil {
Expand Down
Loading