]> git.codecow.com Git - nano-pow.git/commitdiff
Use generic strict equality hash comparison on cache functions to allow string or...
authorChris Duncan <chris@codecow.com>
Mon, 22 Jun 2026 22:18:49 +0000 (15:18 -0700)
committerChris Duncan <chris@codecow.com>
Mon, 22 Jun 2026 22:18:49 +0000 (15:18 -0700)
src/utils/cache.ts

index 0d3b643e6d34b0edbbf69ef91a60226dd672b00b..0490a6a496484d9fa1e17fb52639a505a8132be7 100644 (file)
@@ -28,22 +28,22 @@ export const Cache = {
        clear (): void {
                storage.removeItem(STORAGE_KEY)
        },
-       delete (hash: bigint): void {
+       delete (hash: unknown): void {
                const item = storage.getItem(STORAGE_KEY)
                if (item == null) return
                const cache = JSON.parse(item) as WorkGenerateResponse[]
                for (let i = 0; i < cache.length; i++) {
-                       if (eq(cache[i].hash, hash)) {
+                       if (cache[i].hash === hash) {
                                cache.splice(i, 1)
                        }
                }
                storage.setItem(STORAGE_KEY, JSON.stringify(cache))
        },
-       search (hash: bigint, difficulty: bigint): WorkGenerateResponse | null {
+       search (hash: unknown, difficulty: bigint): WorkGenerateResponse | null {
                const item = storage.getItem(STORAGE_KEY)
                if (item == null) return null
                const cache: WorkGenerateResponse[] = JSON.parse(item)
-               const match = cache.find(c => eq(c.hash, hash) && eq(c.difficulty, difficulty))
+               const match = cache.find(c => c.hash === hash && eq(c.difficulty, difficulty))
                return match ?? null
        },
        store (result: WorkGenerateResponse): WorkGenerateResponse {