commit inicial do projeto
This commit is contained in:
33
internal/transactions/replay.go
Normal file
33
internal/transactions/replay.go
Normal file
@ -0,0 +1,33 @@
|
||||
package transactions
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// SeenTracker registra hashes de transações já vistas (para evitar replay).
|
||||
type SeenTracker struct {
|
||||
mu sync.RWMutex
|
||||
hashes map[string]struct{}
|
||||
}
|
||||
|
||||
// NewSeenTracker cria um novo tracker de transações vistas
|
||||
func NewSeenTracker() *SeenTracker {
|
||||
return &SeenTracker{
|
||||
hashes: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Seen verifica se uma transação já foi vista
|
||||
func (s *SeenTracker) Seen(hash string) bool {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
_, exists := s.hashes[hash]
|
||||
return exists
|
||||
}
|
||||
|
||||
// Mark marca uma transação como vista
|
||||
func (s *SeenTracker) Mark(hash string) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.hashes[hash] = struct{}{}
|
||||
}
|
||||
Reference in New Issue
Block a user