From b8e8e4302e43f53f3678912f22b4afcdae2cccb2 Mon Sep 17 00:00:00 2001
From: Kirill <paltsev.kir@gmail.com>
Date: Thu, 16 Jan 2025 00:45:28 +0400
Subject: [PATCH 1/2] Remove redundant String() call for %s placeholder

---
 internal/utils/utils.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/internal/utils/utils.go b/internal/utils/utils.go
index 8eecdc4..69f9560 100644
--- a/internal/utils/utils.go
+++ b/internal/utils/utils.go
@@ -42,7 +42,7 @@ func GetBTCParams(net string) (*chaincfg.Params, error) {
 		return &chaincfg.SigNetParams, nil
 	}
 	return nil, fmt.Errorf("BTC network with name %s does not exist. should be one of {%s, %s, %s, %s, %s}",
-		net, BtcMainnet.String(), BtcTestnet.String(), BtcSimnet.String(), BtcRegtest.String(), BtcSignet.String())
+		net, BtcMainnet, BtcTestnet, BtcSimnet, BtcRegtest, BtcSignet)
 }
 
 func GetValidNetParams() map[string]bool {

From f5b4ddc051191fc297346a17fbe6684304b111cd Mon Sep 17 00:00:00 2001
From: Kirill <paltsev.kir@gmail.com>
Date: Thu, 16 Jan 2025 00:49:11 +0400
Subject: [PATCH 2/2] Use .Stringer() instead of .Str() for types that
 implement fmt.Stringer

---
 internal/services/delegation.go         | 10 ++++-----
 internal/services/delegation_helpers.go |  2 +-
 internal/services/events.go             | 14 ++++++------
 internal/services/expiry_checker.go     |  4 ++--
 internal/services/subscription.go       |  2 +-
 internal/services/watch_btc_events.go   | 30 ++++++++++++-------------
 6 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/internal/services/delegation.go b/internal/services/delegation.go
index 7671c64..70d4cdf 100644
--- a/internal/services/delegation.go
+++ b/internal/services/delegation.go
@@ -155,7 +155,7 @@ func (s *Service) processCovenantQuorumReachedEvent(
 		log.Debug().
 			Str("staking_tx", covenantQuorumReachedEvent.StakingTxHash).
 			Str("staking_start_height", strconv.FormatUint(uint64(delegation.StartHeight), 10)).
-			Str("event_type", EventCovenantQuorumReached.String()).
+			Stringer("event_type", EventCovenantQuorumReached).
 			Msg("handling active state")
 
 		err = s.emitActiveDelegationEvent(
@@ -233,7 +233,7 @@ func (s *Service) processBTCDelegationInclusionProofReceivedEvent(
 		log.Debug().
 			Str("staking_tx", inclusionProofEvent.StakingTxHash).
 			Str("staking_start_height", inclusionProofEvent.StartHeight).
-			Str("event_type", EventBTCDelegationInclusionProofReceived.String()).
+			Stringer("event_type", EventBTCDelegationInclusionProofReceived).
 			Msg("handling active state")
 
 		err = s.emitActiveDelegationEvent(
@@ -336,12 +336,12 @@ func (s *Service) processBTCDelegationUnbondedEarlyEvent(
 
 	log.Debug().
 		Str("staking_tx", unbondedEarlyEvent.StakingTxHash).
-		Str("new_state", types.StateUnbonding.String()).
+		Stringer("new_state", types.StateUnbonding).
 		Str("early_unbonding_start_height", unbondedEarlyEvent.StartHeight).
 		Str("unbonding_time", strconv.FormatUint(uint64(delegation.UnbondingTime), 10)).
 		Str("unbonding_expire_height", strconv.FormatUint(uint64(unbondingExpireHeight), 10)).
-		Str("sub_state", subState.String()).
-		Str("event_type", EventBTCDelgationUnbondedEarly.String()).
+		Stringer("sub_state", subState).
+		Stringer("event_type", EventBTCDelgationUnbondedEarly).
 		Msg("updating delegation state")
 
 	// Update delegation state
diff --git a/internal/services/delegation_helpers.go b/internal/services/delegation_helpers.go
index 3325863..3f46be2 100644
--- a/internal/services/delegation_helpers.go
+++ b/internal/services/delegation_helpers.go
@@ -39,7 +39,7 @@ func (s *Service) registerUnbondingSpendNotification(
 
 	log.Debug().
 		Str("staking_tx", delegation.StakingTxHashHex).
-		Str("unbonding_tx", unbondingTx.TxHash().String()).
+		Stringer("unbonding_tx", unbondingTx.TxHash()).
 		Msg("registering early unbonding spend notification")
 
 	unbondingOutpoint := wire.OutPoint{
diff --git a/internal/services/events.go b/internal/services/events.go
index 494159a..bdb9f1f 100644
--- a/internal/services/events.go
+++ b/internal/services/events.go
@@ -210,7 +210,7 @@ func (s *Service) validateCovenantQuorumReachedEvent(ctx context.Context, event
 	if !utils.Contains(qualifiedStates, delegation.State) {
 		log.Debug().
 			Str("stakingTxHashHex", event.StakingTxHash).
-			Str("currentState", delegation.State.String()).
+			Stringer("currentState", delegation.State).
 			Str("newState", event.NewState).
 			Msg("Ignoring EventCovenantQuorumReached because current state is not qualified for transition")
 		return false, nil // Ignore the event silently
@@ -224,7 +224,7 @@ func (s *Service) validateCovenantQuorumReachedEvent(ctx context.Context, event
 		if delegation.HasInclusionProof() {
 			log.Debug().
 				Str("stakingTxHashHex", event.StakingTxHash).
-				Str("currentState", delegation.State.String()).
+				Stringer("currentState", delegation.State).
 				Str("newState", event.NewState).
 				Msg("Ignoring EventCovenantQuorumReached because inclusion proof already received")
 			return false, nil
@@ -236,7 +236,7 @@ func (s *Service) validateCovenantQuorumReachedEvent(ctx context.Context, event
 		if !delegation.HasInclusionProof() {
 			log.Debug().
 				Str("stakingTxHashHex", event.StakingTxHash).
-				Str("currentState", delegation.State.String()).
+				Stringer("currentState", delegation.State).
 				Str("newState", event.NewState).
 				Msg("Ignoring EventCovenantQuorumReached because inclusion proof not received")
 			return false, nil
@@ -278,7 +278,7 @@ func (s *Service) validateBTCDelegationInclusionProofReceivedEvent(ctx context.C
 	if !utils.Contains(qualifiedStates, delegation.State) {
 		log.Debug().
 			Str("stakingTxHashHex", event.StakingTxHash).
-			Str("currentState", delegation.State.String()).
+			Stringer("currentState", delegation.State).
 			Str("newState", event.NewState).
 			Msg("Ignoring EventBTCDelegationInclusionProofReceived because current state is not qualified for transition")
 		return false, nil
@@ -289,7 +289,7 @@ func (s *Service) validateBTCDelegationInclusionProofReceivedEvent(ctx context.C
 	if delegation.HasInclusionProof() {
 		log.Debug().
 			Str("stakingTxHashHex", event.StakingTxHash).
-			Str("currentState", delegation.State.String()).
+			Stringer("currentState", delegation.State).
 			Str("newState", event.NewState).
 			Msg("Ignoring EventBTCDelegationInclusionProofReceived because inclusion proof already received")
 		return false, nil
@@ -329,7 +329,7 @@ func (s *Service) validateBTCDelegationUnbondedEarlyEvent(ctx context.Context, e
 	if !utils.Contains(types.QualifiedStatesForUnbondedEarly(), delegation.State) {
 		log.Debug().
 			Str("stakingTxHashHex", event.StakingTxHash).
-			Str("currentState", delegation.State.String()).
+			Stringer("currentState", delegation.State).
 			Msg("Ignoring EventBTCDelgationUnbondedEarly because current state is not qualified for transition")
 		return false, nil
 	}
@@ -368,7 +368,7 @@ func (s *Service) validateBTCDelegationExpiredEvent(ctx context.Context, event *
 	if !utils.Contains(types.QualifiedStatesForExpired(), delegation.State) {
 		log.Debug().
 			Str("stakingTxHashHex", event.StakingTxHash).
-			Str("currentState", delegation.State.String()).
+			Stringer("currentState", delegation.State).
 			Msg("Ignoring EventBTCDelegationExpired because current state is not qualified for transition")
 		return false, nil
 	}
diff --git a/internal/services/expiry_checker.go b/internal/services/expiry_checker.go
index 62d6f33..cac371b 100644
--- a/internal/services/expiry_checker.go
+++ b/internal/services/expiry_checker.go
@@ -47,8 +47,8 @@ func (s *Service) checkExpiry(ctx context.Context) *types.Error {
 
 		log.Debug().
 			Str("staking_tx", delegation.StakingTxHashHex).
-			Str("current_state", delegation.State.String()).
-			Str("new_sub_state", tlDoc.DelegationSubState.String()).
+			Stringer("current_state", delegation.State).
+			Stringer("new_sub_state", tlDoc.DelegationSubState).
 			Str("expire_height", strconv.FormatUint(uint64(tlDoc.ExpireHeight), 10)).
 			Msg("checking if delegation is expired")
 
diff --git a/internal/services/subscription.go b/internal/services/subscription.go
index 4f1af91..902b324 100644
--- a/internal/services/subscription.go
+++ b/internal/services/subscription.go
@@ -78,7 +78,7 @@ func (s *Service) ResubscribeToMissedBtcNotifications(ctx context.Context) {
 
 			log.Debug().
 				Str("staking_tx", delegation.StakingTxHashHex).
-				Str("current_state", delegation.State.String()).
+				Stringer("current_state", delegation.State).
 				Msg("resubscribing to missed BTC notification")
 
 			// Register spend notification
diff --git a/internal/services/watch_btc_events.go b/internal/services/watch_btc_events.go
index 33b8474..4cf6bab 100644
--- a/internal/services/watch_btc_events.go
+++ b/internal/services/watch_btc_events.go
@@ -33,7 +33,7 @@ func (s *Service) watchForSpendStakingTx(
 	case spendDetail := <-spendEvent.Spend:
 		log.Debug().
 			Str("staking_tx", stakingTxHashHex).
-			Str("spending_tx", spendDetail.SpendingTx.TxHash().String()).
+			Stringer("spending_tx", spendDetail.SpendingTx.TxHash()).
 			Msg("staking tx has been spent")
 		if err := s.handleSpendingStakingTransaction(
 			quitCtx,
@@ -45,7 +45,7 @@ func (s *Service) watchForSpendStakingTx(
 			log.Error().
 				Err(err).
 				Str("staking_tx", stakingTxHashHex).
-				Str("spending_tx", spendDetail.SpendingTx.TxHash().String()).
+				Stringer("spending_tx", spendDetail.SpendingTx.TxHash()).
 				Msg("failed to handle spending staking transaction")
 			return
 		}
@@ -71,7 +71,7 @@ func (s *Service) watchForSpendUnbondingTx(
 	case spendDetail := <-spendEvent.Spend:
 		log.Debug().
 			Str("staking_tx", delegation.StakingTxHashHex).
-			Str("unbonding_tx", spendDetail.SpendingTx.TxHash().String()).
+			Stringer("unbonding_tx", spendDetail.SpendingTx.TxHash()).
 			Msg("unbonding tx has been spent")
 		if err := s.handleSpendingUnbondingTransaction(
 			quitCtx,
@@ -83,7 +83,7 @@ func (s *Service) watchForSpendUnbondingTx(
 			log.Error().
 				Err(err).
 				Str("staking_tx", delegation.StakingTxHashHex).
-				Str("unbonding_tx", spendDetail.SpendingTx.TxHash().String()).
+				Stringer("unbonding_tx", spendDetail.SpendingTx.TxHash()).
 				Msg("failed to handle spending unbonding transaction")
 			return
 		}
@@ -108,7 +108,7 @@ func (s *Service) watchForSpendSlashingChange(
 	case spendDetail := <-spendEvent.Spend:
 		log.Debug().
 			Str("staking_tx", delegation.StakingTxHashHex).
-			Str("spending_tx", spendDetail.SpendingTx.TxHash().String()).
+			Stringer("spending_tx", spendDetail.SpendingTx.TxHash()).
 			Msg("slashing change output has been spent")
 		delegationState, err := s.db.GetBTCDelegationState(quitCtx, delegation.StakingTxHashHex)
 		if err != nil {
@@ -123,7 +123,7 @@ func (s *Service) watchForSpendSlashingChange(
 		if qualifiedStates == nil || !utils.Contains(qualifiedStates, *delegationState) {
 			log.Error().
 				Str("staking_tx", delegation.StakingTxHashHex).
-				Str("state", delegationState.String()).
+				Stringer("state", delegationState).
 				Msg("current state is not qualified for slashed withdrawn")
 			return
 		}
@@ -141,8 +141,8 @@ func (s *Service) watchForSpendSlashingChange(
 			log.Error().
 				Err(err).
 				Str("staking_tx", delegation.StakingTxHashHex).
-				Str("state", types.StateWithdrawn.String()).
-				Str("sub_state", delegationSubState.String()).
+				Stringer("state", types.StateWithdrawn).
+				Stringer("sub_state", delegationSubState).
 				Msg("failed to update delegation state to withdrawn")
 			return
 		}
@@ -179,7 +179,7 @@ func (s *Service) handleSpendingStakingTransaction(
 	if isUnbonding {
 		log.Debug().
 			Str("staking_tx", delegation.StakingTxHashHex).
-			Str("unbonding_tx", spendingTx.TxHash().String()).
+			Stringer("unbonding_tx", spendingTx.TxHash()).
 			Msg("staking tx has been spent through unbonding path")
 
 		// Register unbonding spend notification
@@ -192,7 +192,7 @@ func (s *Service) handleSpendingStakingTransaction(
 		// It's a valid withdrawal, process it
 		log.Debug().
 			Str("staking_tx", delegation.StakingTxHashHex).
-			Str("withdrawal_tx", spendingTx.TxHash().String()).
+			Stringer("withdrawal_tx", spendingTx.TxHash()).
 			Msg("staking tx has been spent through withdrawal path")
 		return s.handleWithdrawal(ctx, delegation, types.SubStateTimelock, spendingHeight)
 	}
@@ -254,7 +254,7 @@ func (s *Service) handleSpendingUnbondingTransaction(
 		// It's a valid withdrawal, process it
 		log.Debug().
 			Str("staking_tx", delegation.StakingTxHashHex).
-			Str("unbonding_tx", spendingTx.TxHash().String()).
+			Stringer("unbonding_tx", spendingTx.TxHash()).
 			Msg("unbonding tx has been spent through withdrawal path")
 		return s.handleWithdrawal(ctx, delegation, types.SubStateEarlyUnbonding, spendingHeight)
 	}
@@ -312,7 +312,7 @@ func (s *Service) handleWithdrawal(
 	if qualifiedStates == nil || !utils.Contains(qualifiedStates, *delegationState) {
 		log.Error().
 			Str("staking_tx", delegation.StakingTxHashHex).
-			Str("current_state", delegationState.String()).
+			Stringer("current_state", delegationState).
 			Msg("current state is not qualified for withdrawal")
 		return fmt.Errorf("current state %s is not qualified for withdrawal", *delegationState)
 	}
@@ -320,8 +320,8 @@ func (s *Service) handleWithdrawal(
 	// Update to withdrawn state
 	log.Debug().
 		Str("staking_tx", delegation.StakingTxHashHex).
-		Str("state", types.StateWithdrawn.String()).
-		Str("sub_state", subState.String()).
+		Stringer("state", types.StateWithdrawn).
+		Stringer("sub_state", subState).
 		Msg("updating delegation state to withdrawn")
 
 	return s.db.UpdateBTCDelegationState(
@@ -343,7 +343,7 @@ func (s *Service) startWatchingSlashingChange(
 ) error {
 	log.Debug().
 		Str("staking_tx", delegation.StakingTxHashHex).
-		Str("slashing_tx", slashingTx.TxHash().String()).
+		Stringer("slashing_tx", slashingTx.TxHash()).
 		Msg("watching for slashing change output")
 
 	// Create outpoint for the change output (index 1)