]> git.codecow.com Git - nano-pow.git/commitdiff
Refactor caching without utils import. Add duplicate block hash to test cache storage...
authorChris Duncan <chris@codecow.com>
Thu, 9 Apr 2026 21:31:27 +0000 (14:31 -0700)
committerChris Duncan <chris@codecow.com>
Thu, 9 Apr 2026 21:31:27 +0000 (14:31 -0700)
src/lib/index.ts
src/utils/cache.ts
test/blockhashes.txt

index 13fffa1737f5a3cfc39dedf800d9a1ab007c416d..938f8ad110b03940476d1d1881b446fee625cedc 100644 (file)
@@ -15,7 +15,8 @@ export async function generate (hash: unknown, options?: unknown): Promise<WorkG
                try {
                        const { api, debug, difficulty, effort } = await NanoPowConfig(options)
                        LOG: logger.isEnabled = debug
-                       const cached = Cache.search(hash, difficulty)
+                       const bigintHash = bigintFrom(hash, 'hex')
+                       const cached = Cache.search(bigintHash, difficulty)
                        if (cached) {
                                LOG: logger.log('found work in cache')
                                return cached
index b56e7b7f9cdcdc32a257c42d74572b279b5fe137..03d0fd8b9db179075fcc2f06112cc27f50172b86 100644 (file)
@@ -2,7 +2,6 @@
 //! SPDX-License-Identifier: GPL-3.0-or-later
 
 import { WorkGenerateResponse } from "nano-pow"
-import { bigintFrom } from "#utils"
 
 export class Cache {
 
@@ -10,13 +9,12 @@ export class Cache {
                this.#removeItem('NanoPowCache')
        }
 
-       static search (hash: unknown, difficulty: bigint): WorkGenerateResponse | null {
-               const bigintHash = bigintFrom(hash, 'hex')
+       static search (hash: bigint, difficulty: bigint): WorkGenerateResponse | null {
                const item = this.#getItem('NanoPowCache')
                if (item) {
                        const cache = JSON.parse(item) as WorkGenerateResponse[]
                        for (const c of cache) {
-                               if (bigintFrom(c.hash, 'hex') === bigintHash && bigintFrom(c.difficulty, 'hex') >= difficulty) {
+                               if (BigInt(`0x${c.hash}`) === hash && BigInt(`0x${c.difficulty}`) >= difficulty) {
                                        return c
                                }
                        }
index ba54aafe65299b1834b4ee0c0e344930d0d1d2ea..d41c84bcaca54094fd22f9e7d01cd3f87a90b2c3 100644 (file)
@@ -1,4 +1,5 @@
 92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D
+92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D
 0000000000000000000000000000000000000000000000000000000000000000
 badhash
 8797585D56B8AEA3A62899C31FC088F9BE849BA8298A88E94F6E3112D4E55D01