]> git.codecow.com Git - libnemo.git/commitdiff
Call other subtype Block methods explicitly.
authorChris Duncan <chris@codecow.com>
Sun, 9 Aug 2026 16:40:48 +0000 (09:40 -0700)
committerChris Duncan <chris@codecow.com>
Sun, 9 Aug 2026 16:40:48 +0000 (09:40 -0700)
src/lib/account/refresh.ts
src/lib/wallet/refresh.ts

index 9172309562cbe8637e75cf65ff516aec535ed907..10c14ce0286889065513c3de251b4cee4b821c9c 100644 (file)
@@ -40,8 +40,6 @@ export async function _refresh (account: Account, rpc: unknown): Promise<void> {
                throw new Error('Confirmed frontier block info subtype not found')
        }
        const confirmedFrontierSubtype = resConfirmedFrontierBlockInfo.subtype
-       if (!['change', 'epoch', 'open', 'receive', 'send'].includes(confirmedFrontierSubtype)) {
-               throw new RangeError('Invalid subtype for confirmed frontier block', { cause: confirmedFrontierSubtype })
        }
        if (!('contents' in resConfirmedFrontierBlockInfo) || resConfirmedFrontierBlockInfo.contents == null || typeof resConfirmedFrontierBlockInfo.contents !== 'object') {
                throw new Error('Confirmed frontier block info contents not found')
@@ -51,15 +49,14 @@ export async function _refresh (account: Account, rpc: unknown): Promise<void> {
                confirmedFrontierContents[k] = v
        }
        const confirmedFrontierBlock = new Block(confirmedFrontierContents.account, confirmedFrontierContents.balance, confirmedFrontierContents.previous, confirmedFrontierContents.representative)
-       if (typeof confirmedFrontierBlock[confirmedFrontierSubtype] !== 'function') {
-               throw new TypeError('Unknown subtype of confirmed frontier block', { cause: confirmedFrontierSubtype })
-       }
        if (confirmedFrontierSubtype === 'epoch') {
                confirmedFrontierBlock.epoch(accountInfo.account_version)
        } else if (confirmedFrontierSubtype === 'change') {
                confirmedFrontierBlock.change(confirmedFrontierContents.representative)
-       } else {
+       } else if (confirmedFrontierSubtype === 'open' || confirmedFrontierSubtype === 'receive' || confirmedFrontierSubtype === 'send'{
                confirmedFrontierBlock[confirmedFrontierSubtype](confirmedFrontierContents.link, 0)
+       } else {
+               throw new TypeError('Invalid confirmed frontier block subtype', { cause: confirmedFrontierSubtype })
        }
        confirmedFrontierBlock.signature = confirmedFrontierContents.signature
        account.confirmed_frontier_block = confirmedFrontierBlock
@@ -88,15 +85,14 @@ export async function _refresh (account: Account, rpc: unknown): Promise<void> {
                frontierContents[k] = v
        }
        const frontierBlock = new Block(frontierContents.account, frontierContents.balance, frontierContents.previous, frontierContents.representative)
-       if (typeof frontierBlock[frontierSubtype] !== 'function') {
-               throw new TypeError('Unknown subtype of frontier block', { cause: frontierSubtype })
-       }
        if (frontierSubtype === 'epoch') {
                frontierBlock.epoch(accountInfo.account_version)
        } else if (frontierSubtype === 'change') {
                frontierBlock.change(frontierContents.representative)
-       } else {
+       } else if (frontierSubtype === 'open' || frontierSubtype === 'receive' || frontierSubtype === 'send') {
                frontierBlock[frontierSubtype](frontierContents.link, 0)
+       } else {
+               throw new TypeError('Invalid frontier block subtype', { cause: frontierSubtype })
        }
        frontierBlock.signature = frontierContents.signature
        account.frontier_block = frontierBlock
index 89b8ae740dff87f0825ec1084e2c278972270edd..43a6667372bf47efdafccf200fd79d891522fb35 100644 (file)
@@ -67,9 +67,11 @@ export async function _refresh (wallet: Wallet, rpc: unknown, from: unknown, to:
                                        frontierBlock.epoch(account_version)
                                } else if (subtype === 'change') {
                                        frontierBlock.change(representative)
-                               } else {
+                               } else if (subtype === 'open' || subtype === 'receive' || subtype === 'send') {
                                        frontierBlock[subtype](link, 0)
-                               }
+                               } else {
+                                       throw new TypeError('Invalid frontier block subtype', { cause: subtype })
+                               }       
                                frontierBlock.signature = signature
                                account.frontier_block = frontierBlock
                        }