]> git.codecow.com Git - nano-pow.git/commitdiff
Define single execution sequence in separate function.
authorChris Duncan <chris@codecow.com>
Sat, 25 Jul 2026 07:18:34 +0000 (00:18 -0700)
committerChris Duncan <chris@codecow.com>
Sat, 25 Jul 2026 07:18:34 +0000 (00:18 -0700)
index.html

index 297339432daf1073cc2b435a32bc2a41fff79389..d88bfc649e8e6e5351ef8eb51c1a1ae1b2574dbf 100644 (file)
@@ -45,7 +45,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
                function random (length = 32) {
                        const bytes = crypto.getRandomValues(new Uint8Array(length))
                        return [...bytes].map(b => b.toString(16).padStart(2, '0')).join('')
-                       }
+               }
 
                        function average(times, type, effort) {
                                const averages = stats(times)
@@ -59,6 +59,24 @@ SPDX-License-Identifier: GPL-3.0-or-later
                                }
                        }
 
+                       async function sequenceGenerateValidate (hash, api, debug, difficulty, effort) {
+                               logger.isEnabled = debug
+                               let start = 0, end = 0, work = null, valid = false
+
+                               start = performance.now()
+                               work = (await NanoPow.work_generate(hash, {api, debug, difficulty, effort})).work
+                               valid = (await NanoPow.work_validate(work, hash, {api, debug, difficulty, effort})).valid
+                               end = performance.now()
+
+                               if (!valid) {
+                                       throw new Error(`invalid result\nblock hash: ${hash}\nwork: ${work}`)
+                               }
+                               if (!start || !end || start > end) {
+                                       throw new Error(`invalid timing\nstart: ${start}\nend: ${end}`)
+                               }
+                               return end - start
+                       }
+
                        async function run(size, difficulty, effort, api, isOutputShown, isDebug, isSelfCheck) {
                                logger.isEnabled = isDebug
                                // Generate once on load to compile shaders and initialize buffers