feat: add command domain invariants
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package domain
|
||||
|
||||
import "crypto/sha256"
|
||||
|
||||
type RequestHash [sha256.Size]byte
|
||||
|
||||
func HashImmutableRequest(canonical []byte) RequestHash { return sha256.Sum256(canonical) }
|
||||
|
||||
type ReplayDecision uint8
|
||||
|
||||
const (
|
||||
ReplayNew ReplayDecision = iota
|
||||
ReplayExact
|
||||
ReplayConflict
|
||||
)
|
||||
|
||||
// ClassifyReplay compares a canonical immutable request against durable state.
|
||||
// A nil stored hash means no mutation with this request UUID exists.
|
||||
func ClassifyReplay(stored *RequestHash, incoming RequestHash) ReplayDecision {
|
||||
if stored == nil {
|
||||
return ReplayNew
|
||||
}
|
||||
if *stored == incoming {
|
||||
return ReplayExact
|
||||
}
|
||||
return ReplayConflict
|
||||
}
|
||||
Reference in New Issue
Block a user