]> git.codecow.com Git - libnemo.git/commitdiff
Fix range of unopened account search and cap batch at 100.
authorChris Duncan <chris@codecow.com>
Mon, 3 Aug 2026 20:05:01 +0000 (13:05 -0700)
committerChris Duncan <chris@codecow.com>
Mon, 3 Aug 2026 20:05:01 +0000 (13:05 -0700)
src/lib/wallet/unopened.ts

index fc5ef3724f9efb43451c2e650fc380de11049473..ebdc59ac66bde6172bd265d461b850ba0628975d 100644 (file)
@@ -10,14 +10,14 @@ export async function _unopened (wallet: Wallet, rpc: unknown, batchSize: unknow
        if (!(rpc instanceof Rpc)) {
                throw new TypeError('Invalid RPC endpoint', { cause: rpc })
        }
-       if (typeof batchSize !== 'number' || !Number.isSafeInteger(batchSize) || batchSize < 1) {
-               throw new TypeError('Invalid batch size', { cause: batchSize })
+       if (typeof batchSize !== 'number' || batchSize < 1 || 100 < batchSize) {
+               throw new TypeError('Batch size must be 1-100', { cause: batchSize })
        }
-       if (typeof from !== 'number' || !Number.isSafeInteger(batchSize) || batchSize < 0) {
+       if (typeof from !== 'number' || from < 0 || 0xffffffff < from) {
                throw new TypeError('Invalid starting account index', { cause: from })
        }
-       const to = from + batchSize
-       const accounts = await wallet.accounts(from, to - 1)
+       const to = (from + batchSize > 0xffffffff) ? 0xffffffff : from + batchSize
+       const accounts = await wallet.accounts(from, to)
        const addresses = []
        for (const account of accounts.values()) {
                addresses.push(account.address)
@@ -39,5 +39,5 @@ export async function _unopened (wallet: Wallet, rpc: unknown, batchSize: unknow
                        }
                }
        }
-       return await _unopened(wallet, rpc, batchSize, from + batchSize)
+       return await _unopened(wallet, rpc, batchSize, to)
 }