From 81ad56e85cdb98f6de590ae0f2d93c1d988eacc2 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 12 May 2024 20:54:53 -0300 Subject: [PATCH] simplify RestrictToSpecifiedKinds() --- policies/events.go | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/policies/events.go b/policies/events.go index f76febc..aa2811a 100644 --- a/policies/events.go +++ b/policies/events.go @@ -67,31 +67,10 @@ func PreventLargeTags(maxTagValueLen int) func(context.Context, *nostr.Event) (b // RestrictToSpecifiedKinds returns a function that can be used as a RejectFilter that will reject // any events with kinds different than the specified ones. func RestrictToSpecifiedKinds(kinds ...uint16) func(context.Context, *nostr.Event) (bool, string) { - max := 0 - min := 0 - for _, kind := range kinds { - if int(kind) > max { - max = int(kind) - } - if int(kind) < min { - min = int(kind) - } - } - // sort the kinds in increasing order slices.Sort(kinds) return func(ctx context.Context, event *nostr.Event) (reject bool, msg string) { - // these are cheap and very questionable optimizations, but they exist for a reason: - // we would have to ensure that the kind number is within the bounds of a uint16 anyway - if event.Kind > max { - return true, fmt.Sprintf("event kind not allowed (it should be lower than %d)", max) - } - if event.Kind < min { - return true, fmt.Sprintf("event kind not allowed (it should be higher than %d)", min) - } - - // hopefully this map of uint16s is very fast if _, allowed := slices.BinarySearch(kinds, uint16(event.Kind)); allowed { return false, "" }