* @returns {Promise<Account>} The lowest-indexed unopened account belonging to the wallet\r
*/\r
async unopened (rpc: Rpc, batchSize: number = ADDRESS_GAP, from: number = 0): Promise<Account> {\r
- return await _unopened(this, rpc, batchSize, from + batchSize)\r
+ return await _unopened(this, rpc, batchSize, from)\r
}\r
\r
/**\r
if (typeof from !== 'number' || !Number.isSafeInteger(batchSize) || batchSize < 0) {
throw new TypeError('Invalid starting account index', { cause: from })
}
- const accounts = await wallet.accounts(from, from + batchSize - 1)
+ const to = from + batchSize
+ const accounts = await wallet.accounts(from, to - 1)
const addresses = []
- for (const a in accounts) {
- addresses.push(accounts[a].address)
+ for (const account of accounts) {
+ addresses.push(account.address)
}
const data = {
"accounts": addresses
}
const { errors } = await rpc.call('accounts_frontiers', data)
- for (const key of Object.keys(errors ?? {})) {
- const value = errors[key]
- if (value === 'Account not found') {
- return Account.load(key)
+ if (errors != null) {
+ for (let i = from; i < to; i++) {
+ const account = accounts[i]
+ const value = errors[account.address]
+ if (value === 'Account not found') {
+ return account
+ }
}
}
return await _unopened(wallet, rpc, batchSize, from + batchSize)