From 48501f3c5f732399048f6720a43d866602b45c0e Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 29 Mar 2023 23:34:34 -0500 Subject: [PATCH] Improve stupid code --- src/policies/pubkey-ban-policy.ts | 17 +++++------------ src/policies/whitelist-policy.ts | 17 +++++------------ 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/policies/pubkey-ban-policy.ts b/src/policies/pubkey-ban-policy.ts index c8bba10..0f60e44 100644 --- a/src/policies/pubkey-ban-policy.ts +++ b/src/policies/pubkey-ban-policy.ts @@ -5,23 +5,16 @@ import { Policy } from '../types.ts'; * Pass an array of pubkeys or an iterable, making it efficient to load pubkeys from a large file. */ const pubkeyBanPolicy: Policy> = ({ event: { id, pubkey } }, pubkeys = []) => { - let isMatch = false; - for (const p of pubkeys) { if (p === pubkey) { - isMatch = true; - break; + return { + id, + action: 'reject', + msg: 'blocked: pubkey is banned.', + }; } } - if (isMatch) { - return { - id, - action: 'reject', - msg: 'blocked: pubkey is banned.', - }; - } - return { id, action: 'accept', diff --git a/src/policies/whitelist-policy.ts b/src/policies/whitelist-policy.ts index f7bbaa8..c08dc71 100644 --- a/src/policies/whitelist-policy.ts +++ b/src/policies/whitelist-policy.ts @@ -5,23 +5,16 @@ import type { Policy } from '../types.ts'; * Pass an array of pubkeys or an iterable, making it efficient to load pubkeys from a large file. */ const whitelistPolicy: Policy> = ({ event: { id, pubkey } }, pubkeys = []) => { - let isMatch = false; - for (const p of pubkeys) { if (p === pubkey) { - isMatch = true; - break; + return { + id, + action: 'accept', + msg: '', + }; } } - if (isMatch) { - return { - id, - action: 'accept', - msg: '', - }; - } - return { id, action: 'reject',