Skip to content

Commit

Permalink
fix triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
gusin13 committed Dec 2, 2024
1 parent a94996d commit c6c14a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
24 changes: 12 additions & 12 deletions internal/services/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,17 @@ func (s *Service) processCovenantQuorumReachedEvent(
)
}
newState := types.DelegationState(covenantQuorumReachedEvent.NewState)
// Emit consumer event if the new state is active
if newState == types.StateActive {
// Emit consumer event if the new state is active
err = s.emitConsumerEvent(ctx, newState, delegation)
if err != nil {
return err
}

// Register spend notification
if err := s.registerStakingSpendNotification(ctx, delegation); err != nil {
return err
}
}

if dbErr := s.db.UpdateBTCDelegationState(
Expand Down Expand Up @@ -203,12 +208,17 @@ func (s *Service) processBTCDelegationInclusionProofReceivedEvent(
}

newState := types.DelegationState(inclusionProofEvent.NewState)
// Emit consumer event if the new state is active
if newState == types.StateActive {
// Emit consumer event if the new state is active
err = s.emitConsumerEvent(ctx, newState, delegation)
if err != nil {
return err
}

// Register spend notification
if err := s.registerStakingSpendNotification(ctx, delegation); err != nil {
return err
}
}

if dbErr := s.db.UpdateBTCDelegationDetails(
Expand Down Expand Up @@ -310,11 +320,6 @@ func (s *Service) processBTCDelegationUnbondedEarlyEvent(
)
}

// Register unbonding spend notification
if err := s.registerUnbondingSpendNotification(ctx, delegation); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -383,11 +388,6 @@ func (s *Service) processBTCDelegationExpiredEvent(
)
}

// Register spend notification
if err := s.registerStakingSpendNotification(ctx, delegation); err != nil {
return err
}

return nil
}

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 @@ -175,8 +175,9 @@ func (s *Service) handleSpendingStakingTransaction(
Str("staking_tx", delegation.StakingTxHashHex).
Str("unbonding_tx", spendingTx.TxHash().String()).
Msg("staking tx has been spent through unbonding path")
// It's a valid unbonding tx, no further action needed at this stage
return nil

// Register unbonding spend notification
return s.registerUnbondingSpendNotification(ctx, delegation)
}

// Try to validate as withdrawal transaction
Expand Down

0 comments on commit c6c14a3

Please sign in to comment.