33 lines
690 B
Go
33 lines
690 B
Go
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{}{}
|
|
} |